1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
diff -ur a b
--- a/src/dhcdbd.c 2007-07-08 17:31:50.000000000 +0100
+++ b/src/dhcdbd.c 2007-07-08 17:38:39.000000000 +0100
@@ -2778,9 +2778,6 @@
char path[1024];
int fd, l;
- if (dhcdbd_daemonize && (daemon (0, 0) == -1))
- return errno;
-
openlog ("dhcdbd", LOG_NDELAY | LOG_CONS, LOG_USER);
dbus = dbus_svc_init (bus, dhcdbd_destination, dhcdbd_log, 0L);
@@ -2821,6 +2818,17 @@
(dbus, dhcdbd_object_path, path, dhcdbd_if_subscribe, dhco))
return (1);
+ /* Daemonize and write the pidfile write away, to avoid races */
+ if (dhcdbd_daemonize && (daemon (0, 0) == -1))
+ return errno;
+ unlink (DHCDBD_PID_FILE);
+ if ((fd = open (DHCDBD_PID_FILE, O_WRONLY | O_CREAT)) == -1)
+ exit (errno);
+ l = sprintf (path, "%u", getpid ());
+ l = write (fd, path, l);
+ fsync (fd);
+ close (fd);
+
memset (&sa, '\0', sizeof (struct sigaction));
sa.sa_sigaction = dhc_reaper;
sa.sa_flags = SA_SIGINFO; /* NO RESTART, NO DEFER, CLDSTOP */
@@ -2828,13 +2836,7 @@
dhcdbd_log ("sigaction failed: %s\n", strerror (errno));
return (1);
}
- unlink (DHCDBD_PID_FILE);
- if ((fd = open (DHCDBD_PID_FILE, O_WRONLY | O_CREAT)) == -1)
- exit (errno);
- l = sprintf (path, "%u", getpid ());
- l = write (fd, path, l);
- fsync (fd);
- close (fd);
+
dhcdbd_log ("Started up.");
dbus_svc_main_loop (dbus, dhcdbd_work);
dhcdbd_debug ("Main Loop Exited.");
|