summary refs log tree commit diff
path: root/src/jobs.c (follow)
Commit message (Collapse)AuthorAge
* trap: Globally rename pendingsigs to pending_sigDenys Vlasenko2018-03-10
| | | | | | | | | | | | This variable does not contain "sigs" (plural). It contains either 0 or (one) signal number of a pending signal. For someone unfamiliar with this code, "pendingsigs" name is confusing - it hints at being an array or bit mask of pending singnals. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com> CC: dash@vger.kernel.org Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* jobs: Handle string-based job descriptorsStephen Kitt2016-09-02
| | | | | | | | | | | | | | 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>
* jobs: Don't attempt to access job table for job %0Tobias Klauser2016-06-06
| | | | | | | | | | | | | If job %0 is (mistakenly) specified, an out-of-bounds access to the jobtab occurs in function getjob() if num = 0: jp = jobtab + 0 - 1 Fix this by checking that the job number is larger than 0 before accessing the jobtab. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Fix off-by-one error for multiple of four job numbersHarald van Dijk2014-09-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <herbert@gondor.apana.org.au>
* [SHELL] Improve LINENO supportHarald van Dijk2011-03-15
| | | | | | | | | | | | This patch improves LINENO support by storing line numbers in the parse tree, for commands as well as for function definitions. It makes LINENO behaves properly when calling functions, and has the added benefit of improved line numbers in error messages when the last-parsed command is not the last-executed one. It removes the earlier LINENO support, and instead sets LINENO from evaltree when a command is executed Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to SolarisBrian Koropoff2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Solaris lacks paths.h and the various _PATH_* #defines. Check for them in configure.ac and fall back on the usual suspects when they are missing. - Older Solaris lacks isblank(), and versions that have it use a macro. Check for the declaration in configure.ac and fall back on a naive version when missing. - Older Solaris does not support %jd (intmax_t) in format strings, but it does support the PRIdMAX macro from inttypes.h. Do a configure check for PRIdMAX and use it in the code. If it doesn't exist, define it to "lld" when sizeof(long long) equals sizeof(intmax_t) as this is more likely to work on older systems. Otherwise, use "jd" and hope for the best. - Older Solaris lacks stdint.h, but inttypes.h provides the same types and works on all platforms I've tried dash on, so just use it instead. - Older Solaris doesn't like it when vsnprintf() is passed a NULL buffer (in violation of the POSIX spec, of course). Pass a 1-byte dummy buffer instead. - Solaris lacks tempfile and mktemp programs. Fall back on a "good-enough" custom function in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to AIXBrian Koropoff2011-03-10
| | | | | | | | | | | | | | - AIX lacks a WCOREDUMP macro. It's just used to append "(core dumped)" to the crash message, so #ifdef around it. - For some reason, the nl program on AIX defaults to not printing line numbers ("-b n"), even though the spec says it should default to "-b t". Explicitly pass "-b a" for good measure in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Debug compile fixmaximilian attems2010-09-08
| | | | | | | | | | | No point in tracing a no longer undeclared "ps->cmd", fixes: jobs.c: In function \u2018commandtext\u2019: jobs.c:1192: error: \u2018ps\u2019 undeclared (first use in this function) jobs.c:1192: error: (Each undeclared identifier is reported only once jobs.c:1192: error: for each function it appears in.) Signed-off-by: maximilian attems <max@stro.at> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Fix wait regression where it does not wait for all jobsHerbert Xu2010-05-27
| | | | | | | | | | | The sigsuspend patch broke wait by making it return after just one job has completed. This is because we rely on pendingsigs to signal work and never clear it until waitcmd finishes. This patch adds a separate gotsigchld for this purpose so we can clear it before we start waiting. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [REDIR] Fix incorrect savefd conversionsHerbert Xu2009-06-27
| | | | | | | | | When I added savefd we may end up closing stderr if that is how we get to the tty. This patch fixes by adding a second argument to indicate what fd should be closed which lets jobs.c get around the problem. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Do not close stderr when /dev/tty fails to openHerbert Xu2009-02-22
| | | | | | | | | As it stands if we fail to open /dev/tty we end up closing stderr after saving it at a higher fd. Thanks to David van Gorkom for reporting this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Fix dowait signal raceHerbert Xu2009-02-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This test program by Alexey Gladkov can cause dash to enter an infinite loop in waitcmd. #!/bin/dash trap "echo TRAP" USR1 stub() { echo ">>> STUB $1" >&2 sleep $1 echo "<<< STUB $1" >&2 kill -USR1 $$ } stub 3 & stub 2 & until { echo "###"; wait; } do echo "*** $?" done The problem is that if we get a signal after the wait3 system call has returned but before we get to INTON in dowait, then we can jump back up to the top and lose the exit status. So if we then wait for the job that has just exited, then it'll stay there forever. I made the original change that caused this bug to fix pretty much the same bug but in the opposite direction. That is, if we get a signal after we enter wait3 but before we hit the kernel then it too can cause the wait to go on forever (assuming the child doesn't exit). In fact this is pretty much exactly the scenario that you'll find in glibc's documentation on pause(). The solution is given there too, in the form of sigsuspend, which is the only way to do the check and wait atomically. So this patch fixes Alexey's race without reintroducing the old bug by converting the blocking wait3 to a sigsuspend. In order to do this we need to set a signal handler for SIGCHLD, so the code has been modified to always do that. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILD] Fixed build on OS XMark Mentovai2009-01-13
| | | | | | | | | | | | | | | | | | | | Hi, Herbert and friends. I've created a small patch that allows dash to be built on Mac OS X. I'm contributing it here with the hope that it's suitable for inclusion in dash. The changes in this patch are: - __attribute__((__alias__())) is not supported, add an autoconf check - open64 is not present although the stat64 family is, separate the autoconf checks - A syntax error had slipped into a non-glibc codepath - mkbuiltins had a nonportable mktemp invocation for the case where tempfile is not availalble Nothing in this patch is actually Mac OS X-specific, so it might aid portability to other platforms as well. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [JOBS] Fix cmdtxt crash on if statementsLarry Doolittle2008-05-02
| | | | | | | | | | | | | | | | (Herbert: for context, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467065 ) This is a real bug in upstream dash, which has existed since at least dash-0.5.1 (July 2004). It is a latent bug in cmdtxt() (which I think applies only to pipes) as it handles "if" commands. The attached patch fixes it for me. It's possible this patch will fix one or more of #462414, #462977, and #463649. I'll send messages there to see if the submitters can test. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXPAND] Move parse-time quote flag detection to run-timeHerbert Xu2007-09-25
| | | | | | | | | | | | | | | | | | | | Because the parser does not recursively parse parameter expansion with respect to quotes, we can't accurately determine quote status at parse time. This patch works around this by moving the quote detection to run-time where we do interpret it recursively. Test case: foo=\\ echo "<${foo#[\\]}>" Old result: <\> New result: <>
* [REDIR] Replace copyfd by savefd and use dup2 elsewhereHerbert Xu2007-05-12
| | | | | | | There are two kinds of users to copyfd, those that want to copy an fd to an exact value and those that want to move an fd to a value >= 10. The former can simply use dup2 directly while the latter share a lot of common code that now constitutes savefd.
* [PARSER] Only use signed char for syntax arraysHerbert Xu2006-04-23
| | | | | | | | | The existing scheme of using the native char for syntax array indicies makes cross-compiling difficult. Therefore it makes sense to choose one specific sign for everyone. Since signed chars are native to most platforms and i386, it makes more sense to use that if we are to choose one type for everyone.
* [JOBS] Fixed support for disabling job controlHerbert Xu2005-10-30
| | | | | Since nobody has compiled with JOBS turned off for quite a while, it has bit-rotted. This patch makes it build again.
* [SIGNAL] Added default implementation of strsignalHerbert Xu2005-10-29
| | | | klibc doesn't have strsignal but it does have sys_siglist.
* Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu2005-10-29
| | | | | | | | | | | This change updates the BSD licence to the three-clause version since NetBSD has already done so. This makes dash GPL-compatible. It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file. I've added "copyright by Herbert Xu" to most files. Finally all CVS IDs and inclusion of sys/cdefs.h have been removed. The latter is needed for support of klibc.
* Renamed error to sh_error.herbert2005-09-26
|
* Changed boolean rootshell into shlvl counter.herbert2005-09-26
|
* Allow negative pid argument to kill(1) in src/jobs.c.herbert2005-09-26
|
* Initial import.Herbert Xu2005-09-26