From b8f8720c5e068a9332a63a0c49701fd5b6bd7acb Mon Sep 17 00:00:00 2001 From: Spencer Evans-Cole Date: Sun, 27 Mar 2022 17:33:54 -0400 Subject: 14592 pwait(1) should never wait on its own PID Reviewed by: Dan McDonald Reviewed by: Matt Barden Reviewed by: Toomas Soome Approved by: Richard Lowe --- usr/src/cmd/ptools/pwait/pwait.c | 15 ++++++++++++--- 1 file 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 @@ -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( -- cgit v1.2.3