From 4c44561d9f97331bb23f900f47a69305091f3ab3 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Fri, 26 Sep 2014 22:27:13 +0800 Subject: [JOBS] Fix off-by-one error for multiple of four job numbers On 29/07/13 23:44, Luigi Tarenga wrote: > hi list, > while writing a script to execute parallel ssh command on many host I found > a strange behavior of dash. I can replicate it with a very simple script but > didn't find any documentation about dash or POSIX that can explain it. > > tested on centos 6.4 (dash 0.5.5.1) and wih dash compiled from source (0.5.7) > the following script reports error: > > #!/bin/dash > > sleep 3 & > sleep 3 & > sleep 3 & > sleep 3 & > > #/bin/true > jobs -l > > wait %1 > wait %2 > wait %3 > wait %4 > > [vortex@lizard ~]$ ./dash-0.5.7/src/dash test.sh > [4] + 4569 Running > [3] - 4568 Running > [2] 4567 Running > [1] 4566 Running > prova: 14: wait: No such job: %4 > [vortex@lizard ~]$ echo $? > 2 Yes, this looks like a bug to me. The number of allocated jobs is always kept as a multiple of four, and the first check in considering whether the job number is valid is "if it's greater than or equal to the number of allocated job, it's invalid". That doesn't look right. That would only be right if jobs were zero-based, but they aren't. If it's exactly equal to the number of available jobs, it can still be valid. It works when adding /bin/true, because four more more jobs end up allocated internally. Signed-off-by: Herbert Xu --- ChangeLog | 1 + src/jobs.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ba67b6e..7b67c0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ 2014-09-26 Harald van Dijk * command: allow combining -p with -v. + * getjob: Fix off-by-one error for multiple of four job numbers 2013-08-23 Herbert Xu diff --git a/src/jobs.c b/src/jobs.c index bf40204..c2c2332 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -699,7 +699,7 @@ check: if (is_number(p)) { num = atoi(p); - if (num < njobs) { + if (num <= njobs) { jp = jobtab + num - 1; if (jp->used) goto gotit; -- cgit 1.4.1 Commit message (Collapse)Author 5 daysAdd photos from September 14June McEnroe 5 daysAdd photos from September 12June McEnroe 5 daysAdd photos from September 7June McEnroe 5 daysAllow not having descriptionsJune McEnroe I'm sorry, I can't keep writing descriptions. It makes posting photos take too long, I often don't know the words for what I'm looking at, and a good description is an entirely different work of art than the photo I took, and I'm just a photographer. It's visual art. 6 daysAutomatically select the last used lens for a bodyJune McEnroe 10 daysAdd photos from September 5June McEnroe Had to prefix the folder number onto these file names manually because they must have come out of a different scanner or something. 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe This seems easier to visually scan. The only other thing I'd like is a nicer date rendering but JavaScript is useless for that. 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe