about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2018-09-17 13:01:11 +0200
committerLeah Neukirchen <leah@vuxu.org>2018-09-17 13:01:11 +0200
commitb92fba5ca891fa6a1f4f3a6f12789b87ccc1b484 (patch)
treeaa0a30772828dd144744ae6df37aa7950f164547
parent86e7c446c64441e3d6831bd4d400c99525b9c9f6 (diff)
downloadextrace-b92fba5ca891fa6a1f4f3a6f12789b87ccc1b484.tar.gz
extrace-b92fba5ca891fa6a1f4f3a6f12789b87ccc1b484.tar.xz
extrace-b92fba5ca891fa6a1f4f3a6f12789b87ccc1b484.zip
pwait: verify pids exist at parse time
kill(pid, 0) will return ESRCH for nonexisting pids.
(The other possible error, EPERM would indicate the pid exists.)
-rw-r--r--NEWS.md2
-rw-r--r--pwait.14
-rw-r--r--pwait.c7
3 files changed, 12 insertions, 1 deletions
diff --git a/NEWS.md b/NEWS.md
index 6bcfc4e..5d67ad4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
 ## HEAD
 
+* pwait: detect and warn for non-existing PID.
+
 ## 0.6 (2018-06-19)
 
 * Add `-u` to print owner of process.
diff --git a/pwait.1 b/pwait.1
index 6621b4f..9973747 100644
--- a/pwait.1
+++ b/pwait.1
@@ -1,4 +1,4 @@
-.Dd June 13, 2016
+.Dd September 17, 2018
 .Dt PWAIT 1
 .Os
 .Sh NAME
@@ -22,6 +22,8 @@ Return 111 if any process exited non-successfully.
 .El
 .Sh EXIT STATUS
 .Ex -std
+.Pp
+Invalid pids elicit a warning message but are otherwise ignored.
 .Sh ERRORS
 Check these prerequisites if you see this error:
 .Bd -literal -offset Ds
diff --git a/pwait.c b/pwait.c
index e5f6fde..d32589d 100644
--- a/pwait.c
+++ b/pwait.c
@@ -184,6 +184,13 @@ usage:
 			fprintf(stderr, "%s: invalid process id\n", argv[n]);
 			continue;
 		}
+		errno = 0;
+		kill(pid, 0);
+		if (errno == ESRCH) {
+			fprintf(stderr, "%s: no such process\n", argv[n]);
+			continue;
+		}
+
 		pids[m++] = pid;
 	}