Modify '-F' option to work nicely with pidfile(3) - a pidfile given as
an argument has to be locked.
This commit is contained in:
parent
0ea90af02e
commit
712bf6af16
@ -91,6 +91,12 @@ The following options are available:
|
||||
Restrict matches to a process whose PID is stored in the
|
||||
.Ar pidfile
|
||||
file.
|
||||
The
|
||||
.Ar pidfile
|
||||
file must be locked with the
|
||||
.Xr flock 2
|
||||
syscall or created with
|
||||
.Xr pidfile 3 .
|
||||
.It Fl G Ar gid
|
||||
Restrict matches to processes with a real group ID in the comma-separated
|
||||
list
|
||||
@ -233,8 +239,10 @@ An internal error occurred.
|
||||
.Xr kill 1 ,
|
||||
.Xr killall 1 ,
|
||||
.Xr ps 1 ,
|
||||
.Xr flock 2 ,
|
||||
.Xr kill 2 ,
|
||||
.Xr sigaction 2 ,
|
||||
.Xr pidfile 3 ,
|
||||
.Xr re_format 7
|
||||
.\" Xr signal 7
|
||||
.Sh HISTORY
|
||||
|
@ -641,6 +641,20 @@ takepid(const char *pidfile)
|
||||
if (fh == NULL)
|
||||
err(STATUS_ERROR, "can't open pid file `%s'", pidfile);
|
||||
|
||||
/*
|
||||
* If we can lock pidfile, this means that daemon is not running,
|
||||
* so better don't kill the process from the pidfile.
|
||||
*/
|
||||
if (flock(fileno(fh), LOCK_EX | LOCK_NB) == 0) {
|
||||
(void)fclose(fh);
|
||||
errx(STATUS_ERROR, "file '%s' can be locked", pidfile);
|
||||
} else {
|
||||
if (errno != EWOULDBLOCK) {
|
||||
errx(STATUS_ERROR, "error while locking file '%s'",
|
||||
pidfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (fgets(line, sizeof(line), fh) == NULL) {
|
||||
if (feof(fh)) {
|
||||
(void)fclose(fh);
|
||||
|
Loading…
Reference in New Issue
Block a user