diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2014-10-20 00:43:25 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2014-10-20 00:43:25 +0200 |
commit | cdbcca237081ae582dc40252fb1ec87106eb0075 (patch) | |
tree | 028fb1d7242daa7bd84809cb999e08e7169cb9ae | |
parent | c0c7dd9ea8e6740ecaf45f0d8c05dac99204067d (diff) | |
download | extrace-cdbcca237081ae582dc40252fb1ec87106eb0075.tar.gz extrace-cdbcca237081ae582dc40252fb1ec87106eb0075.tar.xz extrace-cdbcca237081ae582dc40252fb1ec87106eb0075.zip |
pwait: add -c
-rw-r--r-- | pwait.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/pwait.c b/pwait.c index 21e4077..b635fd0 100644 --- a/pwait.c +++ b/pwait.c @@ -3,8 +3,9 @@ * Requires CONFIG_CONNECTOR=y and CONFIG_PROC_EVENTS=y. * Requires root or "setcap cap_net_admin+ep pwait". * - * Usage: pwait [-v] PID... + * Usage: pwait [-v] [-c] PID... * -v Print the exit status when each process terminates. + * -c Check for PIDs to exit successfully, else return 111. * * Copyright (C) 2014 Christian Neukirchen <chneukirchen@gmail.com> * @@ -149,11 +150,13 @@ main(int argc, char *argv[]) pid_t pid; char *end; int verbose = 0; + int check = 0; int seen = 0; int rc = -1; - while ((opt = getopt(argc, argv, "+v")) != -1) + while ((opt = getopt(argc, argv, "+cv")) != -1) switch (opt) { + case 'c': check = 1; break; case 'v': verbose = 1; break; default: goto usage; } @@ -163,7 +166,7 @@ main(int argc, char *argv[]) if (argc == 0) { usage: - fprintf(stderr, "Usage: pwait [-v] PID...\n"); + fprintf(stderr, "Usage: pwait [-v] [-c] PID...\n"); exit(1); } @@ -263,6 +266,10 @@ usage: display(pid, status); pids[n] = 0; seen = 1; + if (check && rc == 0 && + (!WIFEXITED(status) || + WEXITSTATUS(status) != 0)) + rc = 111; } } |