summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-06-05 19:08:22 +0000
committerjilles <jilles@FreeBSD.org>2013-06-05 19:08:22 +0000
commitdbbdb077d82c797a0eda74194fcf16f3264030ab (patch)
tree2692ea400c79babd9dc476ddcc0fe8acc344ccae
parent018a784d3f43677b1c8a81718f963490127f4b99 (diff)
downloadFreeBSD-src-dbbdb077d82c797a0eda74194fcf16f3264030ab.zip
FreeBSD-src-dbbdb077d82c797a0eda74194fcf16f3264030ab.tar.gz
sh: Allow multiple operands in wait builtin.
This is only part of the PR; the behaviour for unknown/invalid pids/jobs remains unchanged (aborts the builtin with status 2). PR: 176916 Submitted by: Vadim Goncharov
-rw-r--r--bin/sh/jobs.c24
-rw-r--r--tools/regression/bin/sh/builtins/wait8.07
2 files changed, 25 insertions, 6 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index 163b7e7..aa8d988 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -95,6 +95,7 @@ static int ttyfd = -1;
static void restartjob(struct job *);
#endif
static void freejob(struct job *);
+static int waitcmdloop(struct job *);
static struct job *getjob(char *);
pid_t getjobpgrp(char *);
static pid_t dowait(int, struct job *);
@@ -459,15 +460,26 @@ int
waitcmd(int argc __unused, char **argv __unused)
{
struct job *job;
- int status, retval;
- struct job *jp;
+ int retval;
nextopt("");
- if (*argptr != NULL) {
+ if (*argptr == NULL)
+ return (waitcmdloop(NULL));
+
+ do {
job = getjob(*argptr);
- } else {
- job = NULL;
- }
+ retval = waitcmdloop(job);
+ argptr++;
+ } while (*argptr != NULL);
+
+ return (retval);
+}
+
+static int
+waitcmdloop(struct job *job)
+{
+ int status, retval;
+ struct job *jp;
/*
* Loop until a process is terminated or stopped, or a SIGINT is
diff --git a/tools/regression/bin/sh/builtins/wait8.0 b/tools/regression/bin/sh/builtins/wait8.0
new file mode 100644
index 0000000..b59ff59
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/wait8.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+exit 44 & p44=$!
+exit 45 & p45=$!
+exit 7 & p7=$!
+wait "$p44" "$p7" "$p45"
+[ "$?" = 45 ]
OpenPOWER on IntegriCloud