diff options
| author | 2001-10-24 17:28:16 +0000 | |
|---|---|---|
| committer | 2001-10-24 17:28:16 +0000 | |
| commit | 14852038eded5e16ae6dfd1e43d39de403fd0497 (patch) | |
| tree | 32df7c8c549de0542e25efc8c18c808250d39a49 /usr.sbin/cron/do_command.c | |
| parent | cleanup, such as spaces and dangling return;s (diff) | |
| download | wireguard-openbsd-14852038eded5e16ae6dfd1e43d39de403fd0497.tar.xz wireguard-openbsd-14852038eded5e16ae6dfd1e43d39de403fd0497.zip | |
When becoming a daemon, dup stdin, stdout, and stderr to /dev/null
Change an unsafe vfork() to fork()
Fix dup2() usage--must check for oldd == newd case and no need to close oldd
Fixes annoying messages from sendmail about stdout being closed.
Diffstat (limited to 'usr.sbin/cron/do_command.c')
| -rw-r--r-- | usr.sbin/cron/do_command.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/usr.sbin/cron/do_command.c b/usr.sbin/cron/do_command.c index 120aaacd905..c3c70bcf4a4 100644 --- a/usr.sbin/cron/do_command.c +++ b/usr.sbin/cron/do_command.c @@ -1,4 +1,4 @@ -/* $OpenBSD: do_command.c,v 1.10 2001/02/18 19:48:33 millert Exp $ */ +/* $OpenBSD: do_command.c,v 1.11 2001/10/24 17:28:16 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved */ @@ -21,7 +21,7 @@ */ #if !defined(lint) && !defined(LINT) -static char rcsid[] = "$OpenBSD: do_command.c,v 1.10 2001/02/18 19:48:33 millert Exp $"; +static char rcsid[] = "$OpenBSD: do_command.c,v 1.11 2001/10/24 17:28:16 millert Exp $"; #endif #include "cron.h" @@ -139,7 +139,7 @@ child_process(entry *e, user *u) { /* fork again, this time so we can exec the user's command. */ - switch (vfork()) { + switch (fork()) { case -1: log_it("CRON", getpid(), "error", "can't vfork"); exit(ERROR_EXIT); @@ -182,14 +182,15 @@ child_process(entry *e, user *u) { /* grandchild process. make std{in,out} be the ends of * pipes opened by our daddy; make stderr go to stdout. */ - close(STDIN); dup2(stdin_pipe[READ_PIPE], STDIN); - close(STDOUT); dup2(stdout_pipe[WRITE_PIPE], STDOUT); - close(STDERR); dup2(STDOUT, STDERR); - - /* close the pipes we just dup'ed. The resources will remain. - */ - close(stdin_pipe[READ_PIPE]); - close(stdout_pipe[WRITE_PIPE]); + if (stdin_pipe[READ_PIPE] != STDIN) { + dup2(stdin_pipe[READ_PIPE], STDIN); + close(stdin_pipe[READ_PIPE]); + } + if (stdout_pipe[WRITE_PIPE] != STDOUT) { + close(STDOUT); + dup2(stdout_pipe[WRITE_PIPE], STDOUT); + } + dup2(STDOUT, STDERR); /* set our directory, uid and gid. Set gid first, since once * we set uid, we've lost root privledges. @@ -483,6 +484,8 @@ child_process(entry *e, user *u) { (long)getpid(), children)) pid = wait(&waiter); if (pid < OK) { + if (errno == EINTR) + continue; Debug(DPROC, ("[%ld] no more grandchildren--mail written?\n", (long)getpid())) |
