summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2015-10-16 23:09:54 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2015-10-16 23:09:54 +0000
commitf57bdc1233c877fced52c883076f325dd392b4ea (patch)
tree740b756ca5271ae52cd73997d29cc9e941943c4d /usr.sbin
parent896d70f8206763f02a3161513f52fbaea14059ca (diff)
use daemon(), jca had the same diff in his tree
Diffstat (limited to 'usr.sbin')
-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);