summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2015-10-16 23:09:53 +0000
committerderaadt <deraadt@openbsd.org>2015-10-16 23:09:53 +0000
commitd9d98c6defca8868fea30d99b51d75f64edd0721 (patch)
tree20e4c61619c19bdd0b0cdd8c4e7ca7a0a6c1e43e
parentAlso allow 6 as a miblen for NET_RT_DUMP, not all users specify a rtable. (diff)
downloadwireguard-openbsd-d9d98c6defca8868fea30d99b51d75f64edd0721.tar.xz
wireguard-openbsd-d9d98c6defca8868fea30d99b51d75f64edd0721.zip
use daemon(), jca had the same diff in his tree
-rw-r--r--usr.sbin/rarpd/rarpd.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c
index df981e85498..724aaa25a20 100644
--- a/usr.sbin/rarpd/rarpd.c
+++ b/usr.sbin/rarpd/rarpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rarpd.c,v 1.61 2015/08/20 22:39:29 deraadt Exp $ */
+/* $OpenBSD: rarpd.c,v 1.62 2015/10/16 23:09:53 deraadt Exp $ */
/* $NetBSD: rarpd.c,v 1.25 1998/04/23 02:48:33 mrg Exp $ */
/*
@@ -149,38 +149,9 @@ main(int argc, char *argv[])
}
if ((!fflag) && (!dflag)) {
- pid = fork();
- if (pid > 0)
- /* Parent exits, leaving child in background. */
- exit(0);
- else
- if (pid == -1) {
- error(FATAL, "cannot fork");
- /* NOTREACHED */
- }
-
- /* write pid file */
+ if (daemon(0, 0) == -1)
+ error(FATAL, "failed to daemonize: %s", strerror(errno));
pidfile(NULL);
-
- /* Fade into the background */
- f = open(_PATH_TTY, O_RDWR);
- if (f >= 0) {
- if (ioctl(f, TIOCNOTTY, 0) < 0) {
- error(FATAL, "TIOCNOTTY: %s", strerror(errno));
- /* NOTREACHED */
- }
- (void) close(f);
- }
- (void) chdir("/");
- (void) setpgid(0, 0);
- devnull = open(_PATH_DEVNULL, O_RDWR);
- if (devnull >= 0) {
- (void) dup2(devnull, STDIN_FILENO);
- (void) dup2(devnull, STDOUT_FILENO);
- (void) dup2(devnull, STDERR_FILENO);
- if (devnull > 2)
- (void) close(devnull);
- }
}
rarp_loop();
exit(0);