dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Handle string-based job descriptors
@ 2016-06-03  7:54 Stephen Kitt
  2016-06-06 14:45 ` [PATCH v2] jobs: " Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Kitt @ 2016-06-03  7:54 UTC (permalink / raw)
  To: dash; +Cc: 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.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 src/jobs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/jobs.c b/src/jobs.c
index c2c2332..37f3b41 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -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;
-- 
2.8.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] jobs: Handle string-based job descriptors
  2016-06-03  7:54 [PATCH] Handle string-based job descriptors Stephen Kitt
@ 2016-06-06 14:45 ` Herbert Xu
  2016-06-07 14:43   ` Stephen Kitt
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2016-06-06 14:45 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: dash

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] jobs: Handle string-based job descriptors
  2016-06-06 14:45 ` [PATCH v2] jobs: " Herbert Xu
@ 2016-06-07 14:43   ` Stephen Kitt
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Kitt @ 2016-06-07 14:43 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

On Mon, 6 Jun 2016 22:45:27 +0800, Herbert Xu <herbert@gondor.apana.org.au>
wrote:
> 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:
[...]

> -	while (1) {
> -		if (!jp)
> -			goto err;
> +	while (jp) {
[...]

That is indeed much better, thanks!

Regards,

Stephen

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-07 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03  7:54 [PATCH] Handle string-based job descriptors Stephen Kitt
2016-06-06 14:45 ` [PATCH v2] jobs: " Herbert Xu
2016-06-07 14:43   ` Stephen Kitt

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).