aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/pkill
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2005-08-24 19:38:28 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2005-08-24 19:38:28 +0000
commit712bf6af1640d84212b3b34f65e7ebcab0cd206d (patch)
tree6ec533e7943ef38b34c0e8818d3ba4805bfad7fb /usr.bin/pkill
parent0ea90af02ed1f3d76a26ab4b8866a3530be9e353 (diff)
downloadsrc-712bf6af1640d84212b3b34f65e7ebcab0cd206d.tar.gz
src-712bf6af1640d84212b3b34f65e7ebcab0cd206d.zip
Modify '-F' option to work nicely with pidfile(3) - a pidfile given as
an argument has to be locked.
Notes
Notes: svn path=/head/; revision=149435
Diffstat (limited to 'usr.bin/pkill')
-rw-r--r--usr.bin/pkill/pkill.18
-rw-r--r--usr.bin/pkill/pkill.c14
2 files changed, 22 insertions, 0 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1
index 143bbc47b3d8..badeb5906f6d 100644
--- a/usr.bin/pkill/pkill.1
+++ b/usr.bin/pkill/pkill.1
@@ -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
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index 68798f129475..1048d3ae23bc 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -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);