summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1999-04-06 04:31:23 +0000
committerpeter <peter@FreeBSD.org>1999-04-06 04:31:23 +0000
commit9f884254c7708e5c45656623b738c91b71cc946a (patch)
tree101ae2f8ee767fd4b51ff37977650da834486ea5 /usr.sbin
parent26451e6e7df2c83d23588f4b100e03020391a885 (diff)
downloadFreeBSD-src-9f884254c7708e5c45656623b738c91b71cc946a.zip
FreeBSD-src-9f884254c7708e5c45656623b738c91b71cc946a.tar.gz
This is a hack. Cron runs with stdin/out/err pointing to /dev/console,
which init thoughtfully revoke()'s when starting a getty on ttyv0. This Cron's popen() was passing these fd's through to cron children (ie: sendmail, *not* normal cron jobs). The side effects were usually not noticed, but it tripped up postfix which did a sanity check to see that stdin/out/err were open, and got EBADF even thought the fd's were in use. I seem to recall sendmail itself has hacks to work around this problem, it had a checkfd012() function, possibly for this same problem. (Postfix has a workaround too now though..) This is a hack, not a fix. It's probably best to check and perhaps close/reopen() /dev/console if needed each time around the event loop. It would probably be useful to actually see any error messages from cron.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/cron/cron/popen.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/usr.sbin/cron/cron/popen.c b/usr.sbin/cron/cron/popen.c
index 34b2f02..7613f54 100644
--- a/usr.sbin/cron/cron/popen.c
+++ b/usr.sbin/cron/cron/popen.c
@@ -28,11 +28,12 @@
static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89";
#endif
static const char rcsid[] =
- "$Id$";
+ "$Id: popen.c,v 1.5 1997/09/15 06:39:07 charnier Exp $";
#endif /* not lint */
#include "cron.h"
#include <sys/signal.h>
+#include <fcntl.h>
#define MAX_ARGS 100
@@ -105,6 +106,9 @@ cron_popen(program, type)
/* NOTREACHED */
case 0: /* child */
if (*type == 'r') {
+ /* Do not share our parent's stdin */
+ (void)close(0);
+ (void)open("/dev/null", O_RDWR);
if (pdes[1] != 1) {
dup2(pdes[1], 1);
dup2(pdes[1], 2); /* stderr, too! */
@@ -116,6 +120,11 @@ cron_popen(program, type)
dup2(pdes[0], 0);
(void)close(pdes[0]);
}
+ /* Hack: stdout gets revoked */
+ (void)close(1);
+ (void)open("/dev/null", O_RDWR);
+ (void)close(2);
+ (void)open("/dev/null", O_RDWR);
(void)close(pdes[1]);
}
#if WANT_GLOBBING
OpenPOWER on IntegriCloud