summaryrefslogtreecommitdiff
path: root/usr.sbin/cron/cron.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-10-24 17:28:17 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-10-24 17:28:17 +0000
commitb63d94eeb32cdb0f74aee4d49dd45475cb621be8 (patch)
tree11d5d97b952a624af67c4317d58d6f556f430da9 /usr.sbin/cron/cron.c
parent3304ae07e128acca74b601e043df6f543a59509f (diff)
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/cron.c')
-rw-r--r--usr.sbin/cron/cron.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/usr.sbin/cron/cron.c b/usr.sbin/cron/cron.c
index a2ce0eba63a..5cc8a5458f5 100644
--- a/usr.sbin/cron/cron.c
+++ b/usr.sbin/cron/cron.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cron.c,v 1.15 2001/08/11 20:47:14 millert Exp $ */
+/* $OpenBSD: cron.c,v 1.16 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: cron.c,v 1.15 2001/08/11 20:47:14 millert Exp $";
+static char rcsid[] = "$OpenBSD: cron.c,v 1.16 2001/10/24 17:28:16 millert Exp $";
#endif
#define MAIN_PROGRAM
@@ -57,6 +57,7 @@ int
main(int argc, char *argv[]) {
cron_db database;
struct sigaction sact;
+ int fd;
ProgramName = argv[0];
@@ -105,6 +106,13 @@ main(int argc, char *argv[]) {
/* child process */
log_it("CRON",getpid(),"STARTUP","fork ok");
(void) setsid();
+ if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+ (void) dup2(fd, STDIN);
+ (void) dup2(fd, STDOUT);
+ (void) dup2(fd, STDERR);
+ if (fd > STDERR)
+ (void) close(fd);
+ }
break;
default:
/* parent process should just die */