NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/41302: cron dies at startup
The following reply was made to PR bin/41302; it has been noted by GNATS.
From: Martin Husemann <martin%duskware.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/41302: cron dies at startup
Date: Sun, 3 May 2009 12:14:28 +0200
--GvXjxJ+pjyke8COw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
This is a patch similar to what FreeBSD did to fix this problem (only
difference is restoring the signal handler when fork() fails.
OK to commit?
Martin
--GvXjxJ+pjyke8COw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch
Index: daemon.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/daemon.c,v
retrieving revision 1.9
diff -u -r1.9 daemon.c
--- daemon.c 7 Aug 2003 16:42:46 -0000 1.9
+++ daemon.c 3 May 2009 10:11:17 -0000
@@ -39,9 +39,11 @@
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
+#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <stdlib.h>
+#include <signal.h>
#include <unistd.h>
#ifdef __weak_alias
@@ -52,10 +54,25 @@
daemon(nochdir, noclose)
int nochdir, noclose;
{
+ struct sigaction osa, sa;
int fd;
+ pid_t newgrp;
+ int oerrno;
+ int osa_ok;
+
+ /* A SIGHUP may be thrown when the parent exits below. */
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_IGN;
+ sa.sa_flags = 0;
+ osa_ok = sigaction(SIGHUP, &sa, &osa);
switch (fork()) {
case -1:
+ if (osa_ok != -1) {
+ oerrno = errno;
+ sigaction(SIGHUP, &osa, NULL);
+ errno = oerrno;
+ }
return (-1);
case 0:
break;
@@ -63,8 +80,14 @@
_exit(0);
}
- if (setsid() == -1)
+ newgrp = setsid();
+ oerrno = errno;
+ if (osa_ok != -1)
+ sigaction(SIGHUP, &osa, NULL);
+ if (newgrp == -1) {
+ errno = oerrno;
return (-1);
+ }
if (!nochdir)
(void)chdir("/");
--GvXjxJ+pjyke8COw--
Home |
Main Index |
Thread Index |
Old Index