diff --git a/src/task_filter_magic.bpf.c b/src/task_filter_magic.bpf.c index 28a329bea42075b02af360cf3bffa3fa566e9b7d..17635a39d3ea60b8dddb9ce46a0aae84824192f6 100644 --- a/src/task_filter_magic.bpf.c +++ b/src/task_filter_magic.bpf.c @@ -52,15 +52,6 @@ int entry(void *ctx) goto unmap; } - /* err = fstat(fd, u_statbuf); */ - /* if (err != 0) { */ - /* goto unmap; */ - /* } */ - /* if (statbuf.st_size < offset + magic_size-1) { */ - /* err = -1; */ - /* goto unmap; */ - /* } */ - if (offset) { off_t o = lseek(fd, offset, SEEK_SET); if (o == -1) { diff --git a/src/task_filter_magic.c b/src/task_filter_magic.c index 944b31604144ec685d6de6a485699a83b3767adb..c17dc521a432fe8b6d9c580a61be35ea9cf94dd2 100644 --- a/src/task_filter_magic.c +++ b/src/task_filter_magic.c @@ -179,23 +179,6 @@ static int filter_magic_user_fp(size_t offset, const char *magic) { return EXIT_FAILURE; } - struct stat statbuf; - err = fstat(fileno(fp), &statbuf); - if (err != 0) { - log_debug("Skipping %s: Error fstat()ing file.", pathbuf); - goto fclose; - } - - // handling only regular files and FIFOs - if (!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) { - log_debug("Skipping %s: Mode %u is not a file.", pathbuf, statbuf.st_mode); - goto fclose; - } - - if (statbuf.st_size < offset + magic_size-1) { - goto fclose; - } - if (offset) { err = fseek(fp, offset, SEEK_SET); if (err) { @@ -206,8 +189,7 @@ static int filter_magic_user_fp(size_t offset, const char *magic) { size_t nread = fread(buf, sizeof(char), magic_size-1, fp); if (nread < magic_size-1) { - log_err("fread(%s) returned short item count", pathbuf); - return EXIT_FAILURE; + goto fclose; } if (strcmp(magic, buf) == 0) { @@ -258,23 +240,6 @@ static int filter_magic_user(size_t offset, const char *magic) { return EXIT_FAILURE; } - struct stat statbuf; - err = fstat(fd, &statbuf); - if (err != 0) { - log_debug("Skipping %s: Error fstat()ing file.", pathbuf); - goto close; - } - - // handling only regular files and FIFOs - if (!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) { - log_debug("Skipping %s: Mode %u is not a file.", pathbuf, statbuf.st_mode); - goto close; - } - - if (statbuf.st_size < offset + magic_size-1) { - goto close; - } - if (offset) { off_t o = lseek(fd, offset, SEEK_SET); if (o == -1) { @@ -289,8 +254,7 @@ static int filter_magic_user(size_t offset, const char *magic) { return EXIT_FAILURE; } if (nread < magic_size-1) { - log_warn("read(%s) returned short item count", pathbuf); - return EXIT_FAILURE; + goto close; } if (strcmp(magic, buf) == 0) { @@ -353,23 +317,6 @@ static int filter_magic_user_burst(size_t offset, const char *magic, size_t max_ return EXIT_FAILURE; } - struct stat statbuf; - err = fstat(fd, &statbuf); - if (err != 0) { - log_debug("Skipping %s: Error fstat()ing file.", pathbuf); - goto close; - } - - // handling only regular files and FIFOs - if (!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) { - log_debug("Skipping %s: Mode %u is not a file.", pathbuf, statbuf.st_mode); - goto close; - } - - if (statbuf.st_size < offset + magic_size-1) { - goto close; - } - if (offset) { off_t o = lseek(fd, offset, SEEK_SET); if (o == -1) { @@ -384,20 +331,16 @@ static int filter_magic_user_burst(size_t offset, const char *magic, size_t max_ return EXIT_FAILURE; } if (nread < magic_size-1) { - log_warn("read(%s) returned short item count", pathbuf); - return EXIT_FAILURE; + goto close; } if (strcmp(magic, buf) == 0) { - printf("%s\n", pathbuf); + write(STDOUT_FILENO, pathbuf, strlen(pathbuf)); + write(STDOUT_FILENO, "\n", 1); } close: - err = close(fd); - if (err) { - perror("close"); - return EXIT_FAILURE; - } + close(fd); } } }