sigemptyset(®istered);
sigemptyset(&pending);
- if (pipe(p)!=0) {
- fatal_perror("start_signal_handling: pipe");
- }
+ pipe_cloexec(p);
spw=p[1];
spr=p[0];
if (fcntl(spw, F_SETFL, fcntl(spw, F_GETFL)|O_NONBLOCK)==-1) {
}
if (secnet_is_daemon) {
/* stderr etc are redirected to the system/log facility */
- if (pipe(errfds)!=0) {
- fatal_perror("can't create pipe for stderr");
- }
+ pipe_cloexec(errfds);
if (dup2(errfds[1],0) < 0
|| dup2(errfds[1],1) < 0
|| dup2(errfds[1],2) < 0)
extern void *safe_malloc_ary(size_t size, size_t count, const char *message);
void setcloexec(int fd); /* cannot fail */
+void pipe_cloexec(int fd[2]); /* pipe(), setcloexec() twice; cannot fail */
extern int sys_cmd(const char *file, const char *argc, ...);
dup2(st->in,0);
dup2(st->out,1);
- /* XXX close all other fds */
setsid();
/* XXX We really should strdup() all of argv[] but because we'll just
exit anyway if execvp() fails it doesn't seem worth bothering. */
st->slip.pending_esc=False;
/* Invoke userv */
- if (pipe(c_stdin)!=0) {
- fatal_perror("userv_invoke_userv: pipe(c_stdin)");
- }
- if (pipe(c_stdout)!=0) {
- fatal_perror("userv_invoke_userv: pipe(c_stdout)");
- }
+ pipe_cloexec(c_stdin);
+ pipe_cloexec(c_stdout);
st->txfd=c_stdin[1];
st->rxfd=c_stdout[0];
if (r<0) fatal_perror("fcntl(,F_SETFD,|FD_CLOEXEC) failed");
}
+void pipe_cloexec(int fd[2]) {
+ int r=pipe(fd);
+ if (r) fatal_perror("pipe");
+ setcloexec(fd[0]);
+ setcloexec(fd[1]);
+}
+
static const char *phases[NR_PHASES]={
"PHASE_INIT",
"PHASE_GETOPTS",