mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-22 18:07:25 +00:00
[master] Move the check for another server to be earlier
[rt38078] Move the check for another server to be earlier Move the code that checks if there is already a server running to be executed earlier in the process. This puts it before the server touches the database which should avoid problems with rewriting a database from under a running server.
This commit is contained in:
parent
913d69f6c9
commit
992dc76542
7
RELNOTES
7
RELNOTES
@ -202,6 +202,13 @@ by Eric Young (eay@cryptsoft.com).
|
|||||||
leae expiration code.
|
leae expiration code.
|
||||||
[ISC-Bugs #38002]
|
[ISC-Bugs #38002]
|
||||||
|
|
||||||
|
- Move the check for a PID file and process to be before we rewrite the
|
||||||
|
lease file. This avoids the possibility of starting a second instance
|
||||||
|
of a server which changes the current lease file confusing the first
|
||||||
|
instance. This check is only included if the admin hasn't disabled PID
|
||||||
|
files.
|
||||||
|
[ISC-Bugs #38078]
|
||||||
|
|
||||||
Changes since 4.3.1b1
|
Changes since 4.3.1b1
|
||||||
|
|
||||||
- Modify the linux and openwrt dhclient scripts to process information
|
- Modify the linux and openwrt dhclient scripts to process information
|
||||||
|
@ -621,6 +621,34 @@ main(int argc, char **argv) {
|
|||||||
if (cftest && !lftest)
|
if (cftest && !lftest)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First part of dealing with pid files. Check to see if
|
||||||
|
* we should continue running or not. We run if:
|
||||||
|
* - we are testing the lease file out
|
||||||
|
* - we don't have a pid file to check
|
||||||
|
* - there is no other process running
|
||||||
|
*/
|
||||||
|
if ((lftest == 0) && (no_pid_file == ISC_FALSE)) {
|
||||||
|
/*Read previous pid file. */
|
||||||
|
if ((i = open(path_dhcpd_pid, O_RDONLY)) >= 0) {
|
||||||
|
status = read(i, pbuf, (sizeof pbuf) - 1);
|
||||||
|
close(i);
|
||||||
|
if (status > 0) {
|
||||||
|
pbuf[status] = 0;
|
||||||
|
pid = atoi(pbuf);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there was a previous server process and
|
||||||
|
* it is still running, abort
|
||||||
|
*/
|
||||||
|
if (!pid ||
|
||||||
|
(pid != getpid() && kill(pid, 0) == 0))
|
||||||
|
log_fatal("There's already a "
|
||||||
|
"DHCP server running.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
group_write_hook = group_writer;
|
group_write_hook = group_writer;
|
||||||
|
|
||||||
/* Start up the database... */
|
/* Start up the database... */
|
||||||
@ -696,30 +724,11 @@ main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with pid files. If the user told us
|
* Second part of dealing with pid files. Now
|
||||||
* not to write a file we don't read one either
|
* that we have forked we can write our pid if
|
||||||
|
* appropriate.
|
||||||
*/
|
*/
|
||||||
if (no_pid_file == ISC_FALSE) {
|
if (no_pid_file == ISC_FALSE) {
|
||||||
/*Read previous pid file. */
|
|
||||||
if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
|
|
||||||
status = read(i, pbuf, (sizeof pbuf) - 1);
|
|
||||||
close (i);
|
|
||||||
if (status > 0) {
|
|
||||||
pbuf[status] = 0;
|
|
||||||
pid = atoi(pbuf);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there was a previous server process and
|
|
||||||
* it is still running, abort
|
|
||||||
*/
|
|
||||||
if (!pid ||
|
|
||||||
(pid != getpid() && kill(pid, 0) == 0))
|
|
||||||
log_fatal("There's already a "
|
|
||||||
"DHCP server running.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write new pid file. */
|
|
||||||
i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
sprintf(pbuf, "%d\n", (int) getpid());
|
sprintf(pbuf, "%d\n", (int) getpid());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user