svn commit: trunk/busybox/networking/udhcp
vda at busybox.net
vda at busybox.net
Thu May 3 16:39:37 PDT 2007
Author: vda
Date: 2007-05-03 16:39:35 -0700 (Thu, 03 May 2007)
New Revision: 18554
Log:
udhcpc: stop deleting our own pidfile if we daemonize.
udhcp[cd]: stop using atexit magic fir pidfile removal.
Modified:
trunk/busybox/networking/udhcp/common.c
trunk/busybox/networking/udhcp/dhcpc.c
trunk/busybox/networking/udhcp/dhcpd.c
Changeset:
Modified: trunk/busybox/networking/udhcp/common.c
===================================================================
--- trunk/busybox/networking/udhcp/common.c 2007-05-03 23:13:04 UTC (rev 18553)
+++ trunk/busybox/networking/udhcp/common.c 2007-05-03 23:39:35 UTC (rev 18554)
@@ -24,16 +24,6 @@
return info.uptime;
}
-#if ENABLE_FEATURE_PIDFILE
-static const char *saved_pidfile;
-
-static void pidfile_delete(void)
-{
- if (saved_pidfile)
- remove_pidfile(saved_pidfile);
-}
-#endif
-
static void create_pidfile(const char *pidfile)
{
if (!pidfile)
@@ -43,12 +33,6 @@
bb_perror_msg("cannot create pidfile %s", pidfile);
return;
}
-#if ENABLE_FEATURE_PIDFILE
- /* lockf(pid_fd, F_LOCK, 0); */
- if (!saved_pidfile)
- atexit(pidfile_delete);
- saved_pidfile = pidfile;
-#endif
}
void udhcp_make_pidfile(const char *pidfile)
Modified: trunk/busybox/networking/udhcp/dhcpc.c
===================================================================
--- trunk/busybox/networking/udhcp/dhcpc.c 2007-05-03 23:13:04 UTC (rev 18553)
+++ trunk/busybox/networking/udhcp/dhcpc.c 2007-05-03 23:39:35 UTC (rev 18554)
@@ -116,6 +116,9 @@
#else
// chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh?
bb_daemonize(DAEMON_CHDIR_ROOT);
+ /* rewrite pidfile, as our pid is different now */
+ if (client_config.pidfile)
+ write_pidfile(client_config.pidfile);
logmode &= ~LOGMODE_STDIO;
#endif
client_config.foreground = 1; /* Do not fork again. */
@@ -327,7 +330,8 @@
client_background();
} else if (client_config.abort_if_no_lease) {
bb_info_msg("No lease, failing");
- return 1;
+ retval = 1;
+ goto ret;
}
/* wait to try again */
packet_num = 0;
@@ -483,7 +487,7 @@
if (client_config.quit_after_lease) {
if (client_config.release_on_quit)
perform_release();
- return 0;
+ goto ret0;
}
if (!client_config.foreground)
client_background();
@@ -516,7 +520,7 @@
bb_info_msg("Received SIGTERM");
if (client_config.release_on_quit)
perform_release();
- return 0;
+ goto ret0;
}
} else if (retval == -1 && errno == EINTR) {
/* a signal was caught */
@@ -524,7 +528,11 @@
/* An error occured */
bb_perror_msg("select");
}
-
- }
- return 0;
+ } /* for (;;) */
+ ret0:
+ retval = 0;
+ ret:
+ if (client_config.pidfile)
+ remove_pidfile(client_config.pidfile);
+ return retval;
}
Modified: trunk/busybox/networking/udhcp/dhcpd.c
===================================================================
--- trunk/busybox/networking/udhcp/dhcpd.c 2007-05-03 23:13:04 UTC (rev 18553)
+++ trunk/busybox/networking/udhcp/dhcpd.c 2007-05-03 23:39:35 UTC (rev 18554)
@@ -53,11 +53,11 @@
udhcp_make_pidfile(server_config.pidfile);
option = find_option(server_config.options, DHCP_LEASE_TIME);
+ server_config.lease = LEASE_TIME;
if (option) {
memcpy(&server_config.lease, option->data + 2, 4);
server_config.lease = ntohl(server_config.lease);
- } else
- server_config.lease = LEASE_TIME;
+ }
/* Sanity check */
num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
@@ -72,8 +72,10 @@
read_leases(server_config.lease_file);
if (read_interface(server_config.interface, &server_config.ifindex,
- &server_config.server, server_config.arp) < 0)
- return 1;
+ &server_config.server, server_config.arp) < 0) {
+ retval = 1;
+ goto ret;
+ }
/* Setup the signal pipe */
udhcp_sp_setup();
@@ -82,7 +84,8 @@
while (1) { /* loop until universe collapses */
if (server_socket < 0) {
- server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface);
+ server_socket = listen_socket(INADDR_ANY, SERVER_PORT,
+ server_config.interface);
}
max_sock = udhcp_sp_fd_set(&rfds, server_socket);
@@ -90,16 +93,17 @@
tv.tv_sec = timeout_end - time(0);
tv.tv_usec = 0;
}
+ retval = 0;
if (!server_config.auto_time || tv.tv_sec > 0) {
retval = select(max_sock + 1, &rfds, NULL, NULL,
server_config.auto_time ? &tv : NULL);
- } else retval = 0; /* If we already timed out, fall through */
-
+ }
if (retval == 0) {
write_leases();
timeout_end = time(0) + server_config.auto_time;
continue;
- } else if (retval < 0 && errno != EINTR) {
+ }
+ if (retval < 0 && errno != EINTR) {
DEBUG("error on select");
continue;
}
@@ -113,7 +117,7 @@
continue;
case SIGTERM:
bb_info_msg("Received a SIGTERM");
- return 0;
+ goto ret0;
case 0: break; /* no signal */
default: continue; /* signal or error (probably EINTR) */
}
@@ -222,7 +226,8 @@
break;
case DHCPRELEASE:
DEBUG("Received RELEASE");
- if (lease) lease->expires = time(0);
+ if (lease)
+ lease->expires = time(0);
break;
case DHCPINFORM:
DEBUG("Received INFORM");
@@ -232,6 +237,10 @@
bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
}
}
-
- return 0;
+ ret0:
+ retval = 0;
+ ret:
+ if (server_config.pidfile)
+ remove_pidfile(server_config.pidfile);
+ return retval;
}
More information about the busybox-cvs
mailing list