diff options
| author | Dan McDonald <danmcd@joyent.com> | 2022-04-13 11:52:04 -0400 |
|---|---|---|
| committer | Dan McDonald <danmcd@joyent.com> | 2022-04-13 11:52:04 -0400 |
| commit | 76941d49ab437e7d72062113cc1ea9818232e737 (patch) | |
| tree | 36f57ce01df0275509bb6cc74ee723204d822c85 | |
| parent | b45d4bf2c2c3235719fb50a3cb9fbcf1699d3f1d (diff) | |
| parent | b1bc843f030b066c3da149508c52f7306b25b8ff (diff) | |
| download | illumos-joyent-76941d49ab437e7d72062113cc1ea9818232e737.tar.gz | |
[illumos-gate merge]
commit b1bc843f030b066c3da149508c52f7306b25b8ff
14592 pwait(1) should never wait on its own PID
Conflicts:
usr/src/cmd/ptools/pwait/pwait.c
| -rw-r--r-- | usr/src/cmd/ptools/pwait/pwait.c | 15 |
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( |
