summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorStephen Kitt <steve@sk2.org>2016-06-06 22:45:27 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2016-09-02 22:10:56 +0800
commit203e8395faa9135956e3b2a2b749b6dd96a7e988 (patch)
tree9daef748990b61965d99ff9fad443a2f667b80b6 /src
parenttrap: Implement POSIX.1-2008 trap reset behaviour (diff)
downloaddash-203e8395faa9135956e3b2a2b749b6dd96a7e988.tar.gz
dash-203e8395faa9135956e3b2a2b749b6dd96a7e988.zip
jobs: Handle string-based job descriptors
When looking for a job using a string descriptor, e.g.

	fg %man

the relevant loop in src/jobs.c only ever exits to the err label. With
this patch, when the end condition is reached, we check whether a job
was found, and if so, set things up to exit correctly via gotit.
Multiple matches are already caught using the test in the match block.

Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'src')
-rw-r--r--src/jobs.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/jobs.c b/src/jobs.c
index 3997863..4f02e38 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -714,9 +714,7 @@ check:
 	}
 
 	found = 0;
-	while (1) {
-		if (!jp)
-			goto err;
+	while (jp) {
 		if (match(jp->ps[0].cmd, p)) {
 			if (found)
 				goto err;
@@ -726,6 +724,10 @@ check:
 		jp = jp->prev_job;
 	}
 
+	if (!found)
+		goto err;
+	jp = found;
+
 gotit:
 #if JOBS
 	err_msg = "job %s not created under job control";