Teach dhclient(8) to exit gracefully if another instance is already
running instead of overwriten the PID file, removing IPv4 address from the network interface(s) and leaving the system in a broken state. This fixes PR bin/26504 by Jun-ichiro itojun Hagino. Patch supplied by Rivo Nurges during NetBSD's second Bugathon.
This commit is contained in:
parent
1fe5d73096
commit
66ac2330dc
33
dist/dhcp/client/dhclient.c
vendored
33
dist/dhcp/client/dhclient.c
vendored
@ -32,7 +32,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char ocopyright[] =
|
||||
"$Id: dhclient.c,v 1.17 2006/08/03 20:17:43 christos Exp $ Copyright (c) 2004-2005 Internet Systems Consortium. All rights reserved.\n";
|
||||
"$Id: dhclient.c,v 1.18 2006/10/07 14:14:06 tron Exp $ Copyright (c) 2004-2005 Internet Systems Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
@ -118,6 +118,9 @@ int main (argc, argv, envp)
|
||||
int no_dhclient_pid = 0;
|
||||
int no_dhclient_script = 0;
|
||||
char *s;
|
||||
FILE *pidfd;
|
||||
long pidfd_pid;
|
||||
int e;
|
||||
|
||||
/* Make sure we have stdin, stdout and stderr. */
|
||||
i = open ("/dev/null", O_RDWR);
|
||||
@ -260,25 +263,17 @@ int main (argc, argv, envp)
|
||||
path_dhclient_script = s;
|
||||
}
|
||||
|
||||
/* first kill of any currently running client */
|
||||
if (release_mode) {
|
||||
FILE *pidfd;
|
||||
pid_t oldpid;
|
||||
long temp;
|
||||
int e;
|
||||
if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
|
||||
e = fscanf(pidfd, "%ld\n", &pidfd_pid);
|
||||
fclose(pidfd);
|
||||
|
||||
oldpid = 0;
|
||||
if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
|
||||
e = fscanf(pidfd, "%ld\n", &temp);
|
||||
oldpid = (pid_t)temp;
|
||||
|
||||
if (e != 0 && e != EOF) {
|
||||
if (oldpid) {
|
||||
if (kill(oldpid, SIGTERM) == 0)
|
||||
unlink(path_dhclient_pid);
|
||||
}
|
||||
}
|
||||
fclose(pidfd);
|
||||
if (e != 0 && e != EOF && pidfd_pid) {
|
||||
if (release_mode) {
|
||||
if (kill((pid_t)pidfd_pid, SIGTERM) == 0)
|
||||
unlink(path_dhclient_pid);
|
||||
} else if (kill((pid_t)pidfd_pid, 0) == 0)
|
||||
log_fatal("dhclient[%li] is already running",
|
||||
pidfd_pid);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user