in scripts/inotify/inotify.c [24:64]
void run_callback_internal(char** callback) {
fflush(stdout); // avoid mixing with callback output.
pid_t pid = fork();
if (pid == -1) {
perror("fork");
return; // let it retry at the next event or timeout.
}
if (pid == 0) {
execve(callback[0], callback, environ);
perror("execve");
exit(EXIT_FAILURE);
}
int status;
do {
int w = waitpid(pid, &status, 0);
if (w == -1) {
if (errno == EINTR) {
continue;
}
perror("waitpid");
exit(EXIT_FAILURE); // shouldn't happen; don't risk leaking zombies.
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
if (WIFEXITED(status)) {
printf("inotify: %s exited with status %d (exit: %d)\n",
callback[0], status, WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("inotify: %s exited with status %d (signal: %d)\n",
callback[0], status, WTERMSIG(status));
} else {
printf("inotify: %s exited with status %d\n", callback[0], status);
}
if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) {
exit(EXIT_SUCCESS);
}
}