summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Evans-Cole <spencer.ec09@gmail.com>2022-03-27 17:33:54 -0400
committerDan McDonald <danmcd@joyent.com>2022-04-13 11:57:38 -0400
commitb8f8720c5e068a9332a63a0c49701fd5b6bd7acb (patch)
tree2100c569049567488a20ed2fde1dc0a3f423d6b9
parent81f5e485fc02f0eddc9a7354a01f42834ed521e9 (diff)
downloadillumos-joyent-b8f8720c5e068a9332a63a0c49701fd5b6bd7acb.tar.gz
14592 pwait(1) should never wait on its own PID
Reviewed by: Dan McDonald <danmcd@joyent.com> Reviewed by: Matt Barden <mbarden@tintri.com> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Richard Lowe <richlowe@richlowe.net>
-rw-r--r--usr/src/cmd/ptools/pwait/pwait.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr/src/cmd/ptools/pwait/pwait.c b/usr/src/cmd/ptools/pwait/pwait.c
index ec11573477..efb79c38f1 100644
--- a/usr/src/cmd/ptools/pwait/pwait.c
+++ b/usr/src/cmd/ptools/pwait/pwait.c
@@ -21,6 +21,7 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright 2022 Spencer Evans-Cole.
*/
#include <stdio.h>
@@ -57,6 +58,7 @@ main(int argc, char **argv)
char *arg;
unsigned i;
int verbose = 0;
+ pid_t mypid = getpid();
if ((command = strrchr(argv[0], '/')) != NULL)
command++;
@@ -108,6 +110,13 @@ main(int argc, char **argv)
char psinfofile[100];
arg = argv[i];
+ if (mypid == atol(arg)) {
+ if (verbose) {
+ (void) printf("%s: has the same"
+ " pid as this process\n", arg);
+ }
+ continue;
+ }
if (strchr(arg, '/') != NULL)
(void) strncpy(psinfofile, arg, sizeof (psinfofile));
else {
@@ -115,7 +124,7 @@ main(int argc, char **argv)
(void) strncat(psinfofile, arg, sizeof (psinfofile)-6);
}
(void) strncat(psinfofile, "/psinfo",
- sizeof (psinfofile)-strlen(psinfofile));
+ sizeof (psinfofile) - strlen(psinfofile));
pfd = &pollfd[i];
if ((pfd->fd = open(psinfofile, O_RDONLY)) >= 0) {
@@ -163,8 +172,8 @@ main(int argc, char **argv)
if (pread(pfd->fd, &psinfo,
sizeof (psinfo), (off_t)0)
== sizeof (psinfo)) {
- (void) printf("%s: terminated, "
- "wait status 0x%.4x\n",
+ (void) printf("%s: terminated,"
+ " wait status 0x%.4x\n",
arg, psinfo.pr_wstat);
} else {
(void) printf(