int remove_allum(int *pos_r, int nb_row, int *map, t_point *margin) { int buff; t_point pos; int to_rm; if ((to_rm = get_user_entry(pos_r, nb_row, map, margin)) < 1) return (-1); buff = -1; pos.x = margin->x - 4; pos.y = nb_row + 2 + margin->y; cur_goto(&pos); tputs(tgetstr("ce", NULL), 0, &tput_putc); while (++buff < to_rm) rm_an_allum(pos_r, nb_row, map, margin); tputs(tgetstr("vi", NULL), 0, &tput_putc); return (select_next_line(pos_r, nb_row, map, margin)); }
/* * runas is the pseudo-user identity we assume * jail is the directory we chdir() to before doing chroot(".") * pidfile is written outside the jail. * flags is a bitflag option specifier */ int daemonize(const char *runas, const char *jail, const char *pidfile, int flags) { struct passwd *pw; int pid = already_running(pidfile); daemon_pidfile = strdup(pidfile); if (pid > 0) { fprintf(stderr, "Another Merlin instance is already running with pid %d\n", pid); exit(EXIT_FAILURE); } /* don't drop privs or chdir if we're debugging */ if (flags & DMNZ_NOFORK) return write_pid(pidfile, getpid()); if (jail && chdir(jail) < 0) { fprintf(stderr, "Failed to chdir() to '%s': %s\n", jail, strerror(errno)); return -1; } pid = fork(); if (pid < 0) { fprintf(stderr, "fork() failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (!pid) { /* baby daemon goes here */ /* start a new process group */ setsid(); if (jail && flags & DMNZ_CHROOT && chroot(".") < 0) { fprintf(stderr, "chroot(%s) failed: %s", jail, strerror(errno)); exit(EXIT_FAILURE); } pw = get_user_entry(runas); if (pw && drop_privs(pw) != pw->pw_uid) { fprintf(stderr, "Failed to drop privileges to user %s", pw->pw_name); exit(EXIT_FAILURE); } free(pw); return 0; } if (write_pid(pidfile, pid) != pid) { fprintf(stderr, "Failed to write pidfile '%s': %s\n", pidfile, strerror(errno)); kill(pid, SIGTERM); kill(pid, SIGKILL); exit(EXIT_FAILURE); } if (flags & DMNZ_NOFORK) return pid; _exit(EXIT_SUCCESS); return 0; }