Jiri Moskovcak <[email protected]> writes: > On 03/15/2012 05:26 PM, Nikola Pajkovsky wrote: >> 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. >> > > - but you need to run it to find out that it doesn't work, so I don't > understand your proposal - you mean if we detect it failed once then > disable it and never try to run it again?
try to think what would happen if you have an app with auto start and it fails to start or do some operation (we have inotify). running it over and over doesn't bring you anything good. in worst case it could eat cpu, memory or i/o. so if execvp(prog[0], prog) return on pid exit != 0, we should stop watch-log and report to abrt; hey man, we have some hiccups please report to abrt <email> >> I can't help myself, but I think I'm reading very stupid cron, which is >> activated by inotify :) > > - yes, because we want it to be event driven not timer driver.. > >> >> Apart of this, its looks good >> -- Nikola
