dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Stephen Kitt <steve@sk2.org>
Cc: dash@vger.kernel.org
Subject: [PATCH v2] jobs: Handle string-based job descriptors
Date: Mon, 6 Jun 2016 22:45:27 +0800	[thread overview]
Message-ID: <20160606144527.GA23630@gondor.apana.org.au> (raw)
In-Reply-To: <1464940471-9819-1-git-send-email-steve@sk2.org>

On Fri, Jun 03, 2016 at 09:54:31AM +0200, Stephen Kitt wrote:
> 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>

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

---8<---
From: Stephen Kitt <steve@sk2.org>

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>

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";
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2016-06-06 14:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03  7:54 [PATCH] Handle string-based job descriptors Stephen Kitt
2016-06-06 14:45 ` Herbert Xu [this message]
2016-06-07 14:43   ` [PATCH v2] jobs: " Stephen Kitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160606144527.GA23630@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=steve@sk2.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).