void proc_shutdown(struct privsep_proc *p) { struct privsep *ps = p->p_ps; if (p->p_id == PROC_CONTROL && ps) control_cleanup(&ps->ps_csock); if (p->p_shutdown != NULL) (*p->p_shutdown)(); proc_close(ps); log_info("%s exiting, pid %d", p->p_title, getpid()); exit(0); }
static int proc_vscanf (pctx_t ctx, const char *path, const char *fmt, va_list ap) { int n = -1; assert (ctx->pctx_magic == PCTX_MAGIC); assert (path || ctx->pctx_fp); assert (!ctx->pctx_dp); if (path) { if (proc_open (ctx, path) < 0) return -1; } n = vfscanf (ctx->pctx_fp, fmt, ap); if (path) proc_close (ctx); return n; }
void proc_kill(struct privsep *ps) { pid_t pid; u_int i; if (privsep_process != PROC_PARENT) return; for (i = 0; i < PROC_MAX; i++) { if (ps->ps_pid[i] == 0) continue; killpg(ps->ps_pid[i], SIGTERM); } do { pid = waitpid(WAIT_ANY, NULL, 0); } while (pid != -1 || (pid == -1 && errno == EINTR)); proc_close(ps); }
/* Returns -1 with errno == 0 for EOF * Trailing newlines are trimmed in the result. */ int proc_gets (pctx_t ctx, const char *path, char *buf, int len) { int i, ret = 0; assert (ctx->pctx_magic == PCTX_MAGIC); assert (path || ctx->pctx_fp); assert (!ctx->pctx_dp); if (path) { if (proc_open (ctx, path) < 0) return -1; } errno = 0; if (!fgets (buf, len, ctx->pctx_fp)) ret = -1; if (path) proc_close (ctx); if (ret == 0 && (i = strlen (buf)) > 0 && buf[i - 1] == '\n') buf[i - 1] = '\0'; return ret; }
void proc_kill(struct privsep *ps) { char *cause; pid_t pid; int len, status; if (privsep_process != PROC_PARENT) return; proc_close(ps); do { pid = waitpid(WAIT_ANY, &status, 0); if (pid <= 0) continue; if (WIFSIGNALED(status)) { len = asprintf(&cause, "terminated; signal %d", WTERMSIG(status)); } else if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) len = asprintf(&cause, "exited abnormally"); else len = 0; } else len = -1; if (len == 0) { /* child exited OK, don't print a warning message */ } else if (len != -1) { log_warnx("lost child: pid %u %s", pid, cause); free(cause); } else log_warnx("lost child: pid %u", pid); } while (pid != -1 || (pid == -1 && errno == EINTR)); }