summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-03-02 15:58:42 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-03-02 15:58:42 +0000
commite6328e696c69672422ca207c2f51ac8be93403eb (patch)
tree5b3043fb78b1a5b9bad9b2eab3d8a3685d32f7d7
parent8fd70f65c238597d6e0e1219c09e901a862e21d0 (diff)
use daemon(3) instead of homebrown gunk
-rw-r--r--sbin/dhclient/dhclient.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 3d8020ccb0a..1026cb8a04e 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.28 2004/03/02 15:52:40 henning Exp $ */
+/* $OpenBSD: dhclient.c,v 1.29 2004/03/02 15:58:41 henning Exp $ */
/* DHCP Client. */
@@ -2008,33 +2008,17 @@ void
go_daemon(void)
{
static int state = 0;
- int pid;
- /* Don't become a daemon if the user requested otherwise. */
- if (no_daemon)
+ if (no_daemon || state)
return;
- /* Only do it once. */
- if (state)
- return;
state = 1;
/* Stop logging to stderr... */
log_perror = 0;
- /* Become a daemon... */
- if ((pid = fork()) < 0)
- error("Can't fork daemon: %m");
- else if (pid)
- exit(0);
- /* Become session leader and get pid... */
- pid = setsid();
-
- /* Close standard I/O descriptors. */
- close(0);
- close(1);
- close(2);
-
+ if (daemon(1, 0) == -1)
+ error("daemon");
}
int