diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-03 23:39:35 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-03 23:39:35 +0000 |
commit | 6e6d331d97aa230625c9b50c73f5df9251b8df4b (patch) | |
tree | f5ad77208e9a8da163cb347b5e3ceea648a8b7e7 | |
parent | f71d916b60079f2009a714e49cb3e83efedbfb77 (diff) | |
download | busybox-w32-6e6d331d97aa230625c9b50c73f5df9251b8df4b.tar.gz busybox-w32-6e6d331d97aa230625c9b50c73f5df9251b8df4b.tar.bz2 busybox-w32-6e6d331d97aa230625c9b50c73f5df9251b8df4b.zip |
udhcpc: stop deleting our own pidfile if we daemonize.
udhcp[cd]: stop using atexit magic fir pidfile removal.
-rw-r--r-- | networking/udhcp/common.c | 16 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 20 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 33 |
3 files changed, 35 insertions, 34 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 721888f6d..76f8bf703 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -24,16 +24,6 @@ long uptime(void) | |||
24 | return info.uptime; | 24 | return info.uptime; |
25 | } | 25 | } |
26 | 26 | ||
27 | #if ENABLE_FEATURE_PIDFILE | ||
28 | static const char *saved_pidfile; | ||
29 | |||
30 | static void pidfile_delete(void) | ||
31 | { | ||
32 | if (saved_pidfile) | ||
33 | remove_pidfile(saved_pidfile); | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | static void create_pidfile(const char *pidfile) | 27 | static void create_pidfile(const char *pidfile) |
38 | { | 28 | { |
39 | if (!pidfile) | 29 | if (!pidfile) |
@@ -43,12 +33,6 @@ static void create_pidfile(const char *pidfile) | |||
43 | bb_perror_msg("cannot create pidfile %s", pidfile); | 33 | bb_perror_msg("cannot create pidfile %s", pidfile); |
44 | return; | 34 | return; |
45 | } | 35 | } |
46 | #if ENABLE_FEATURE_PIDFILE | ||
47 | /* lockf(pid_fd, F_LOCK, 0); */ | ||
48 | if (!saved_pidfile) | ||
49 | atexit(pidfile_delete); | ||
50 | saved_pidfile = pidfile; | ||
51 | #endif | ||
52 | } | 36 | } |
53 | 37 | ||
54 | void udhcp_make_pidfile(const char *pidfile) | 38 | void udhcp_make_pidfile(const char *pidfile) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 362e70169..06806ec66 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -116,6 +116,9 @@ static void client_background(void) | |||
116 | #else | 116 | #else |
117 | // chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh? | 117 | // chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh? |
118 | bb_daemonize(DAEMON_CHDIR_ROOT); | 118 | bb_daemonize(DAEMON_CHDIR_ROOT); |
119 | /* rewrite pidfile, as our pid is different now */ | ||
120 | if (client_config.pidfile) | ||
121 | write_pidfile(client_config.pidfile); | ||
119 | logmode &= ~LOGMODE_STDIO; | 122 | logmode &= ~LOGMODE_STDIO; |
120 | #endif | 123 | #endif |
121 | client_config.foreground = 1; /* Do not fork again. */ | 124 | client_config.foreground = 1; /* Do not fork again. */ |
@@ -327,7 +330,8 @@ int udhcpc_main(int argc, char **argv) | |||
327 | client_background(); | 330 | client_background(); |
328 | } else if (client_config.abort_if_no_lease) { | 331 | } else if (client_config.abort_if_no_lease) { |
329 | bb_info_msg("No lease, failing"); | 332 | bb_info_msg("No lease, failing"); |
330 | return 1; | 333 | retval = 1; |
334 | goto ret; | ||
331 | } | 335 | } |
332 | /* wait to try again */ | 336 | /* wait to try again */ |
333 | packet_num = 0; | 337 | packet_num = 0; |
@@ -483,7 +487,7 @@ int udhcpc_main(int argc, char **argv) | |||
483 | if (client_config.quit_after_lease) { | 487 | if (client_config.quit_after_lease) { |
484 | if (client_config.release_on_quit) | 488 | if (client_config.release_on_quit) |
485 | perform_release(); | 489 | perform_release(); |
486 | return 0; | 490 | goto ret0; |
487 | } | 491 | } |
488 | if (!client_config.foreground) | 492 | if (!client_config.foreground) |
489 | client_background(); | 493 | client_background(); |
@@ -516,7 +520,7 @@ int udhcpc_main(int argc, char **argv) | |||
516 | bb_info_msg("Received SIGTERM"); | 520 | bb_info_msg("Received SIGTERM"); |
517 | if (client_config.release_on_quit) | 521 | if (client_config.release_on_quit) |
518 | perform_release(); | 522 | perform_release(); |
519 | return 0; | 523 | goto ret0; |
520 | } | 524 | } |
521 | } else if (retval == -1 && errno == EINTR) { | 525 | } else if (retval == -1 && errno == EINTR) { |
522 | /* a signal was caught */ | 526 | /* a signal was caught */ |
@@ -524,7 +528,11 @@ int udhcpc_main(int argc, char **argv) | |||
524 | /* An error occured */ | 528 | /* An error occured */ |
525 | bb_perror_msg("select"); | 529 | bb_perror_msg("select"); |
526 | } | 530 | } |
527 | 531 | } /* for (;;) */ | |
528 | } | 532 | ret0: |
529 | return 0; | 533 | retval = 0; |
534 | ret: | ||
535 | if (client_config.pidfile) | ||
536 | remove_pidfile(client_config.pidfile); | ||
537 | return retval; | ||
530 | } | 538 | } |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index d85615349..9f96e8bd1 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -53,11 +53,11 @@ int udhcpd_main(int argc, char **argv) | |||
53 | udhcp_make_pidfile(server_config.pidfile); | 53 | udhcp_make_pidfile(server_config.pidfile); |
54 | 54 | ||
55 | option = find_option(server_config.options, DHCP_LEASE_TIME); | 55 | option = find_option(server_config.options, DHCP_LEASE_TIME); |
56 | server_config.lease = LEASE_TIME; | ||
56 | if (option) { | 57 | if (option) { |
57 | memcpy(&server_config.lease, option->data + 2, 4); | 58 | memcpy(&server_config.lease, option->data + 2, 4); |
58 | server_config.lease = ntohl(server_config.lease); | 59 | server_config.lease = ntohl(server_config.lease); |
59 | } else | 60 | } |
60 | server_config.lease = LEASE_TIME; | ||
61 | 61 | ||
62 | /* Sanity check */ | 62 | /* Sanity check */ |
63 | num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1; | 63 | num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1; |
@@ -72,8 +72,10 @@ int udhcpd_main(int argc, char **argv) | |||
72 | read_leases(server_config.lease_file); | 72 | read_leases(server_config.lease_file); |
73 | 73 | ||
74 | if (read_interface(server_config.interface, &server_config.ifindex, | 74 | if (read_interface(server_config.interface, &server_config.ifindex, |
75 | &server_config.server, server_config.arp) < 0) | 75 | &server_config.server, server_config.arp) < 0) { |
76 | return 1; | 76 | retval = 1; |
77 | goto ret; | ||
78 | } | ||
77 | 79 | ||
78 | /* Setup the signal pipe */ | 80 | /* Setup the signal pipe */ |
79 | udhcp_sp_setup(); | 81 | udhcp_sp_setup(); |
@@ -82,7 +84,8 @@ int udhcpd_main(int argc, char **argv) | |||
82 | while (1) { /* loop until universe collapses */ | 84 | while (1) { /* loop until universe collapses */ |
83 | 85 | ||
84 | if (server_socket < 0) { | 86 | if (server_socket < 0) { |
85 | server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface); | 87 | server_socket = listen_socket(INADDR_ANY, SERVER_PORT, |
88 | server_config.interface); | ||
86 | } | 89 | } |
87 | 90 | ||
88 | max_sock = udhcp_sp_fd_set(&rfds, server_socket); | 91 | max_sock = udhcp_sp_fd_set(&rfds, server_socket); |
@@ -90,16 +93,17 @@ int udhcpd_main(int argc, char **argv) | |||
90 | tv.tv_sec = timeout_end - time(0); | 93 | tv.tv_sec = timeout_end - time(0); |
91 | tv.tv_usec = 0; | 94 | tv.tv_usec = 0; |
92 | } | 95 | } |
96 | retval = 0; | ||
93 | if (!server_config.auto_time || tv.tv_sec > 0) { | 97 | if (!server_config.auto_time || tv.tv_sec > 0) { |
94 | retval = select(max_sock + 1, &rfds, NULL, NULL, | 98 | retval = select(max_sock + 1, &rfds, NULL, NULL, |
95 | server_config.auto_time ? &tv : NULL); | 99 | server_config.auto_time ? &tv : NULL); |
96 | } else retval = 0; /* If we already timed out, fall through */ | 100 | } |
97 | |||
98 | if (retval == 0) { | 101 | if (retval == 0) { |
99 | write_leases(); | 102 | write_leases(); |
100 | timeout_end = time(0) + server_config.auto_time; | 103 | timeout_end = time(0) + server_config.auto_time; |
101 | continue; | 104 | continue; |
102 | } else if (retval < 0 && errno != EINTR) { | 105 | } |
106 | if (retval < 0 && errno != EINTR) { | ||
103 | DEBUG("error on select"); | 107 | DEBUG("error on select"); |
104 | continue; | 108 | continue; |
105 | } | 109 | } |
@@ -113,7 +117,7 @@ int udhcpd_main(int argc, char **argv) | |||
113 | continue; | 117 | continue; |
114 | case SIGTERM: | 118 | case SIGTERM: |
115 | bb_info_msg("Received a SIGTERM"); | 119 | bb_info_msg("Received a SIGTERM"); |
116 | return 0; | 120 | goto ret0; |
117 | case 0: break; /* no signal */ | 121 | case 0: break; /* no signal */ |
118 | default: continue; /* signal or error (probably EINTR) */ | 122 | default: continue; /* signal or error (probably EINTR) */ |
119 | } | 123 | } |
@@ -222,7 +226,8 @@ int udhcpd_main(int argc, char **argv) | |||
222 | break; | 226 | break; |
223 | case DHCPRELEASE: | 227 | case DHCPRELEASE: |
224 | DEBUG("Received RELEASE"); | 228 | DEBUG("Received RELEASE"); |
225 | if (lease) lease->expires = time(0); | 229 | if (lease) |
230 | lease->expires = time(0); | ||
226 | break; | 231 | break; |
227 | case DHCPINFORM: | 232 | case DHCPINFORM: |
228 | DEBUG("Received INFORM"); | 233 | DEBUG("Received INFORM"); |
@@ -232,6 +237,10 @@ int udhcpd_main(int argc, char **argv) | |||
232 | bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]); | 237 | bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]); |
233 | } | 238 | } |
234 | } | 239 | } |
235 | 240 | ret0: | |
236 | return 0; | 241 | retval = 0; |
242 | ret: | ||
243 | if (server_config.pidfile) | ||
244 | remove_pidfile(server_config.pidfile); | ||
245 | return retval; | ||
237 | } | 246 | } |