Denys Vlasenko <[email protected]> writes:

+static void run_scanner_prog(int fd, struct stat *statbuf, char **prog)
+{
+    /* fstat(fd, &statbuf) was just done by caller */
+
+    off_t cur_pos = lseek(fd, 0, SEEK_CUR);
+    if (statbuf->st_size <= cur_pos)
+    {
+        /* If file was truncated, treat it as a new file.
+         * (changing inode# causes caller to think that file was closed or 
renamed)
+         */
+        if (statbuf->st_size < cur_pos)
+            statbuf->st_ino++;
+        return; /* we are at EOF, nothing to do */
+    }
+
+    VERB3 log("File grew by %llu bytes, from %llu to %llu",
+        (long long)(statbuf->st_size - cur_pos),
+        (long long)(cur_pos),
+        (long long)(statbuf->st_size));
+
+    pid_t pid = vfork();
+    if (pid < 0)
+        perror_msg_and_die("vfork");
+    if (pid == 0)
+    {
+        xmove_fd(fd, STDIN_FILENO);
+        execvp(prog[0], prog);
+        perror_msg_and_die("Can't execute '%s'", prog[0]);
+    }
+
+    safe_waitpid(pid, NULL, 0);

I think, we should here check returned value from execvp
program. Program which SIGSEGV or fails from whatever reason is
pointless to run.

I can't help myself, but I think I'm reading very stupid cron, which is
activated by inotify :)

Apart of this, its looks good

-- 
Nikola

Reply via email to