/** * Fork-exec-wait /etc/cerberusrc * * @param hook The ID of the hook to run * @param argc The number of command line arguments * @param argv The command line arguments * @return The exit value of the hook */ int fork_exec_wait_hook(int hook, int argc, char** argv) { pid_t pid, reaped; int status; pid = fork(); if (pid == -1) return -1; if (pid == 0) { close(STDIN_FILENO); exec_hook(hook, argc, argv); _exit(138); } for (;;) { reaped = wait(&status); if (reaped == -1) { perror("wait"); return -1; } if (reaped == pid) return status == 138 ? -1 : status; } }
/** * Mane method * * @param argc The number of command line arguments * @param argv The command line arguments * @return Return code */ int main(int argc, char** argv) { char* tty_device = ttyname(STDIN_FILENO); do_login(argc, argv); /* Ignore signals */ signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); /* Wait for the login shell and all grandchildren to exit */ while ((wait(NULL) == -1) && (errno == EINTR)) ; /* Regain access to the terminal */ if (tty_device) { int fd = open(tty_device, O_RDWR | O_NONBLOCK); if (fd != 0) dup2(fd, 0); if (fd != 1) dup2(fd, 1); if (fd != 2) dup2(fd, 2); } /* Reset terminal ownership and mode */ chown_tty(0, tty_group, 0); /* Close login session */ close_login_session(); /* Run logout hook */ exec_hook(HOOK_LOGOUT, argc, argv); return 0; }
enum IP_STATUS ip_accept_preparsed(const struct ppam_rx_hash *ctxt, struct annotations_t *notes, struct iphdr *ip_hdr, enum state source) { return exec_hook(ctxt, IP_HOOK_PREROUTING, notes, ip_hdr, &ip_accept_finish, source); }
static int toilet_flush(const char *path, struct fuse_file_info *fi) { int writing; FIX_PATH(path); pthread_mutex_lock(&lock); if (strcmp(path, opened_filename) == 0) writing = 1; pthread_mutex_unlock(&lock); if (writing) exec_hook(path); return 0; }