Skip to contentSkip to conversation

Handle string-based job descriptors

PATCH New Stephen Kitt 2 participants 3 messages Jun 3, 2016 – Jun 7, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 src/jobs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
src/jobs.c +8 -2
index c2c2332..37f3b41 100644
@@ -715,8 +715,14 @@ check:
 
 	found = 0;
 	while (1) {
-		if (!jp)
-			goto err;
+		if (!jp) {
+			if (found) {
+				jp = found;
+				goto gotit;
+			} else {
+				goto err;
+			}
+		}
 		if (match(jp->ps[0].cmd, p)) {
 			if (found)
 				goto err;
Signature · 1 line
2.8.1
#1 lore raw

PATCH v2 1/1 jobs: Handle string-based job descriptors

Quoted 10 lines · Stephen Kitt

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.

Thanks for the patch. I'd prefer to move that logic out of the loop, like this:

---8<---
From: Stephen Kitt <[email protected]>

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.

src/jobs.c +5 -3
index 3997863..4f02e38 100644
@@ -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";
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

Re: [PATCH v2] jobs: Handle string-based job descriptors

Quoted 14 lines · Herbert Xu
Quoted 10 lines · Stephen Kitt

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.

Thanks for the patch. I'd prefer to move that logic out of the loop, like this:

[...]

src/jobs.c check: · line 717

Quoted 4 lines
src/jobs.c +1 -3
-	while (1) {
-		if (!jp)
-			goto err;
+	while (jp) {

[...]

That is indeed much better, thanks!

Regards,

Stephen