udhcpc: stop deleting our own pidfile if we daemonize.
udhcp[cd]: stop using atexit magic fir pidfile removal.
This commit is contained in:
parent
f71d916b60
commit
6e6d331d97
@ -24,16 +24,6 @@ long uptime(void)
|
|||||||
return info.uptime;
|
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)
|
static void create_pidfile(const char *pidfile)
|
||||||
{
|
{
|
||||||
if (!pidfile)
|
if (!pidfile)
|
||||||
@ -43,12 +33,6 @@ static void create_pidfile(const char *pidfile)
|
|||||||
bb_perror_msg("cannot create pidfile %s", pidfile);
|
bb_perror_msg("cannot create pidfile %s", pidfile);
|
||||||
return;
|
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)
|
void udhcp_make_pidfile(const char *pidfile)
|
||||||
|
@ -116,6 +116,9 @@ static void client_background(void)
|
|||||||
#else
|
#else
|
||||||
// chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh?
|
// chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh?
|
||||||
bb_daemonize(DAEMON_CHDIR_ROOT);
|
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;
|
logmode &= ~LOGMODE_STDIO;
|
||||||
#endif
|
#endif
|
||||||
client_config.foreground = 1; /* Do not fork again. */
|
client_config.foreground = 1; /* Do not fork again. */
|
||||||
@ -327,7 +330,8 @@ int udhcpc_main(int argc, char **argv)
|
|||||||
client_background();
|
client_background();
|
||||||
} else if (client_config.abort_if_no_lease) {
|
} else if (client_config.abort_if_no_lease) {
|
||||||
bb_info_msg("No lease, failing");
|
bb_info_msg("No lease, failing");
|
||||||
return 1;
|
retval = 1;
|
||||||
|
goto ret;
|
||||||
}
|
}
|
||||||
/* wait to try again */
|
/* wait to try again */
|
||||||
packet_num = 0;
|
packet_num = 0;
|
||||||
@ -483,7 +487,7 @@ int udhcpc_main(int argc, char **argv)
|
|||||||
if (client_config.quit_after_lease) {
|
if (client_config.quit_after_lease) {
|
||||||
if (client_config.release_on_quit)
|
if (client_config.release_on_quit)
|
||||||
perform_release();
|
perform_release();
|
||||||
return 0;
|
goto ret0;
|
||||||
}
|
}
|
||||||
if (!client_config.foreground)
|
if (!client_config.foreground)
|
||||||
client_background();
|
client_background();
|
||||||
@ -516,7 +520,7 @@ int udhcpc_main(int argc, char **argv)
|
|||||||
bb_info_msg("Received SIGTERM");
|
bb_info_msg("Received SIGTERM");
|
||||||
if (client_config.release_on_quit)
|
if (client_config.release_on_quit)
|
||||||
perform_release();
|
perform_release();
|
||||||
return 0;
|
goto ret0;
|
||||||
}
|
}
|
||||||
} else if (retval == -1 && errno == EINTR) {
|
} else if (retval == -1 && errno == EINTR) {
|
||||||
/* a signal was caught */
|
/* a signal was caught */
|
||||||
@ -524,7 +528,11 @@ int udhcpc_main(int argc, char **argv)
|
|||||||
/* An error occured */
|
/* An error occured */
|
||||||
bb_perror_msg("select");
|
bb_perror_msg("select");
|
||||||
}
|
}
|
||||||
|
} /* for (;;) */
|
||||||
}
|
ret0:
|
||||||
return 0;
|
retval = 0;
|
||||||
|
ret:
|
||||||
|
if (client_config.pidfile)
|
||||||
|
remove_pidfile(client_config.pidfile);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,11 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
udhcp_make_pidfile(server_config.pidfile);
|
udhcp_make_pidfile(server_config.pidfile);
|
||||||
|
|
||||||
option = find_option(server_config.options, DHCP_LEASE_TIME);
|
option = find_option(server_config.options, DHCP_LEASE_TIME);
|
||||||
|
server_config.lease = LEASE_TIME;
|
||||||
if (option) {
|
if (option) {
|
||||||
memcpy(&server_config.lease, option->data + 2, 4);
|
memcpy(&server_config.lease, option->data + 2, 4);
|
||||||
server_config.lease = ntohl(server_config.lease);
|
server_config.lease = ntohl(server_config.lease);
|
||||||
} else
|
}
|
||||||
server_config.lease = LEASE_TIME;
|
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
|
num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
|
||||||
@ -72,8 +72,10 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
read_leases(server_config.lease_file);
|
read_leases(server_config.lease_file);
|
||||||
|
|
||||||
if (read_interface(server_config.interface, &server_config.ifindex,
|
if (read_interface(server_config.interface, &server_config.ifindex,
|
||||||
&server_config.server, server_config.arp) < 0)
|
&server_config.server, server_config.arp) < 0) {
|
||||||
return 1;
|
retval = 1;
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* Setup the signal pipe */
|
/* Setup the signal pipe */
|
||||||
udhcp_sp_setup();
|
udhcp_sp_setup();
|
||||||
@ -82,7 +84,8 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
while (1) { /* loop until universe collapses */
|
while (1) { /* loop until universe collapses */
|
||||||
|
|
||||||
if (server_socket < 0) {
|
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);
|
max_sock = udhcp_sp_fd_set(&rfds, server_socket);
|
||||||
@ -90,16 +93,17 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
tv.tv_sec = timeout_end - time(0);
|
tv.tv_sec = timeout_end - time(0);
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
}
|
}
|
||||||
|
retval = 0;
|
||||||
if (!server_config.auto_time || tv.tv_sec > 0) {
|
if (!server_config.auto_time || tv.tv_sec > 0) {
|
||||||
retval = select(max_sock + 1, &rfds, NULL, NULL,
|
retval = select(max_sock + 1, &rfds, NULL, NULL,
|
||||||
server_config.auto_time ? &tv : NULL);
|
server_config.auto_time ? &tv : NULL);
|
||||||
} else retval = 0; /* If we already timed out, fall through */
|
}
|
||||||
|
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
write_leases();
|
write_leases();
|
||||||
timeout_end = time(0) + server_config.auto_time;
|
timeout_end = time(0) + server_config.auto_time;
|
||||||
continue;
|
continue;
|
||||||
} else if (retval < 0 && errno != EINTR) {
|
}
|
||||||
|
if (retval < 0 && errno != EINTR) {
|
||||||
DEBUG("error on select");
|
DEBUG("error on select");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -113,7 +117,7 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
bb_info_msg("Received a SIGTERM");
|
bb_info_msg("Received a SIGTERM");
|
||||||
return 0;
|
goto ret0;
|
||||||
case 0: break; /* no signal */
|
case 0: break; /* no signal */
|
||||||
default: continue; /* signal or error (probably EINTR) */
|
default: continue; /* signal or error (probably EINTR) */
|
||||||
}
|
}
|
||||||
@ -222,7 +226,8 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case DHCPRELEASE:
|
case DHCPRELEASE:
|
||||||
DEBUG("Received RELEASE");
|
DEBUG("Received RELEASE");
|
||||||
if (lease) lease->expires = time(0);
|
if (lease)
|
||||||
|
lease->expires = time(0);
|
||||||
break;
|
break;
|
||||||
case DHCPINFORM:
|
case DHCPINFORM:
|
||||||
DEBUG("Received INFORM");
|
DEBUG("Received INFORM");
|
||||||
@ -232,6 +237,10 @@ int udhcpd_main(int argc, char **argv)
|
|||||||
bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
|
bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ret0:
|
||||||
return 0;
|
retval = 0;
|
||||||
|
ret:
|
||||||
|
if (server_config.pidfile)
|
||||||
|
remove_pidfile(server_config.pidfile);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user