| Commit message (Collapse) | Author | Age |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On 12/03/2012 05:59 PM, Harald van Dijk wrote:
> On 12/03/2012 08:42 AM, Roy wrote:
>> MSYS libc does not support %j[dXx] format, only %ll[dXx] is supported.
>>
>> diff --git a/src/bltin/printf.c b/src/bltin/printf.c
>> index 893295c..12ce660 100644
>> --- a/src/bltin/printf.c
>> +++ b/src/bltin/printf.c
>> @@ -319,11 +319,12 @@ mklong(const char *str, const char *ch)
>> char *copy;
>> size_t len;
>>
>> - len = ch - str + 3;
>> + len = ch - str + 4;
>> STARTSTACKSTR(copy);
>> copy = makestrspace(len, copy);
>> - memcpy(copy, str, len - 3);
>> - copy[len - 3] = 'j';
>> + memcpy(copy, str, len - 4);
>> + copy[len - 4] = 'l';
>> + copy[len - 3] = 'l';
>> copy[len - 2] = *ch;
>> copy[len - 1] = '\0';
>> return (copy);
>
> The calling code uses the result to print intmax_t and uintmax_t values.
> Printing intmax_t values with %lld is wrong, this will only work if
> intmax_t is really a typedef for long long (which may be true on your
> system, but is not required by the standard).
>
> The other patch that Jonathan linked to should work just fine.
Here's a slightly tweaked version of that patch. Regardless of whether
PRIdMAX is defined as "jd" or as "lld", the use of memcpy here, first
copying "jd"/"lld" and the null byte, and only changing the 'd' after
that, surprisingly results in slightly shorter object code than the
original byte-by-byte approach, even though memcpy is fully inlined.
Perhaps that could be a reason for applying this, even if the original
reason for it, making the code work on not-quite-conforming systems,
isn't good enough to get it in dash.
Tested with normal glibc, and with glibc hacked to not provide PRIdMAX.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Tue, Aug 28, 2012 at 01:27:24PM +0000, Todor Vlaev wrote:
>
> While playing around with parameter expansion I noticed that the
> following didn't work in dash (dash 0.5.5.1-7.4ubuntu1) as compared
> to bash even though I believe it should be POSIX-compliant:
>
> my_str=swan; last_char="${my_str#${my_str%?}}"; echo ${last_char}
>
> If the double quotes are removed, the last character is printed correctly.
>
> At a quick glance through the commits after the 0.5.5.1 release I saw
> the following bug fix. Could it be related?
>
> 0d7d66039b614b642c775432fd64aa8c11f9a64d
> [EXPAND] Fix quoted pattern patch breakage
We need to propagate EXP_QPAT in subevalvar as otherwise a nested
parameter expansion within subevalvar may be expanded incorrectly.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
| |
This is a small patch to fix the paragraph about 'wait' in the dash manpage.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
I recently found myself in need to have dash support 'ulimit -r' to
set maximum realtime priority. Attached is a patch that adds the
parameter to the builtin ulimit command and updates the manpage.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Otherwise, this:
$ perl -le 'print "v"x(2**31+1) ."=1"' | dash
provokes integer overflow:
(gdb) bt
#0 doformat (dest=0x61d580, f=0x416a08 "%s: %d: %s: ", ap=0x7fffffffd308)
at output.c:310
#1 0x00000000004128c1 in outfmt (file=0x61d580, fmt=0x416a08 "%s: %d: %s: ")
at output.c:257
#2 0x000000000040382e in exvwarning2 (msg=0x417339 "Out of space",
ap=0x7fffffffd468) at error.c:125
#3 0x000000000040387e in exverror (cond=1, msg=0x417339 "Out of space",
ap=0x7fffffffd468) at error.c:156
#4 0x0000000000403938 in sh_error (msg=0x417339 "Out of space") at error.c:172
#5 0x000000000040c970 in ckmalloc (nbytes=18446744071562067984)
at memalloc.c:57
#6 0x000000000040ca78 in stalloc (nbytes=18446744071562067972)
at memalloc.c:132
#7 0x000000000040ece9 in grabstackblock (len=18446744071562067972)
at memalloc.h:67
#8 0x00000000004106b5 in readtoken1 (firstc=118, syntax=0x419522 "",
eofmark=0x0, striptabs=0) at parser.c:1040
#9 0x00000000004101a4 in xxreadtoken () at parser.c:826
#10 0x000000000040fe1d in readtoken () at parser.c:697
#11 0x000000000040edcc in parsecmd (interact=0) at parser.c:145
#12 0x000000000040c679 in cmdloop (top=1) at main.c:224
#13 0x000000000040c603 in main (argc=2, argv=0x7fffffffd9f8) at main.c:178
#8 0x00000000004106b5 in readtoken1 (firstc=118, syntax=0x419522 "",
eofmark=0x0, striptabs=0) at parser.c:1040
1040 grabstackblock(len);
(gdb) p len
$30 = -2147483644
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Tue, Feb 14, 2012 at 10:48:48AM +0000, harald@redhat.com wrote:
>
> "export -p" prints all environment variables, without checking if the
> environment variable is a valid dash variable name.
>
> IMHO, the only valid usecase for "export -p" is to eval the output.
>
> $ eval $(export -p); echo OK
> OK
>
> Without this patch the following test does error out with:
>
> test.py:
> import os
> os.environ["test-test"]="test"
> os.environ["test_test"]="test"
> os.execv("./dash", [ './dash', '-c', 'eval $(export -p); echo OK' ])
>
> $ python test.py
> ./dash: 1: export: test-test: bad variable name
>
> Of course the results can be more evil, if the environment variable
> name is crafted, that it injects valid shell code.
This patch fixes the issue by sanitising all environment variable names
upon entry into the shell.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
| |
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
| |
Simply specify --disable-lineno to configure.
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
| |
dash rather pointlessly calls imaxdiv, only to discard one of its
results. The call was already made conditional a while back because some
systems don't have imaxdiv, but the generated code for the version with
imaxdiv and the one with / and % is identical (with GCC 4.6.1 or ICC
12.0.2, with -O0, -O2 or -Os), so it could just as well go entirely to
clean up the code a little bit.
Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
dash didn't compile in DEBUG mode against klibc for all long time.
Now it only fails at link stage for not having setlinebuf(3) and
freopen(3).
Fixes:
usr/dash/show.o: In function `opentrace':
show.c:(.text+0x36): undefined reference to `freopen'
show.c:(.text+0x86): undefined reference to `setlinebuf'
Skip setlinebuf and use fclose/fopen inside __KLIBC__
Compile tested with debug in klibc and against glibc in dash repo.
Signed-off-by: maximilian attems <max@stro.at>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Currently upon leaving a dotcmd the evalskip state is reset so
if a continue/break statement is used within a dot script it would
have no effect outside of the dot script.
This is inconsistent with other shells.
This patch is based on one by Jilles Tjoelker and only clears
SKIPFUNC when leaving a dot script. As a result continue/break
will remain in effect.
It also merges SKIPFUNC/SKIPFILE as they have no practical difference.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
* src/eval.c (evalbltin, evalfun): Set savehandler before calling
setjmp with the possible "goto *done", where savehandler is used.
Otherwise, clang warns that "Assigned value is garbage or undefined"
at the point where "savehandler" is used on the RHS.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
| |
* src/memalloc.c (makestrspace): Remove dead store.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
* src/memalloc.c (growstackblock): Remove declaration and set of
set-but-not-used variable. Also remove a stray space-before-TAB.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
The patch to make outc into an inline function created an unnecessary
promotion in echocmd due to its use of char vs. the int used by outc.
This patch changes echocmd to use int instead.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
As "gcc -pedantic" warns, ISO C forbids conditional expressions with
only one void side. So the (needslow ? slowpath() : fastpath) code
for outc in the !USE_GLIBC_STDIO case might not be portable.
More importantly, it's hard to read. Rip it out and replace it
with an inline function which should generate the same code.
Reported-by: Szabolcs Nagy <nsz@port70.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
From: Kalle Olavi Niemitalo <kon@iki.fi>
LANG=C man dash shows:
PS1 The primary prompt string, which defaults to ``$ '', unless
you are the superuser, in which case it defaults to ``# ''.
PS2 The secondary prompt string, which defaults to ``> ''.
PS4 Output before each line when execution trace (set -x) is
enabled, defaults to ``+ ''.
Each of the documented default values has a graphic character and
two spaces between the quotation marks. However, the actual
default values have only one space, rather than two.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Sun, Apr 10, 2011 at 07:36:49AM +0000, Jonathan Nieder wrote:
> From: Jilles Tjoelker <jilles@stack.nl>
> Date: Sat, 13 Jun 2009 16:17:45 -0500
>
> This change only affects strings passed to -c, when the -s option is
> not used.
>
> Use the EV_EXIT flag to inform the eval machinery that the string
> being passed is the entirety of input. This way, a fork may be
> omitted in many special cases.
>
> If there are empty lines after the last command, the evalcmd will not
> see the end early enough and forks will not be omitted. The same thing
> seems to happen in bash.
>
> Example:
> sh -c 'ps lT'
> No longer shows a shell process waiting for ps to finish.
>
> [jn: ported from FreeBSD SVN r194128. Bugs are mine.]
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Instead of detecting EOF using the input layer, I'm going to
use the parser instead. In either case, we always have to read
ahead in order to complete the parsing of the previous node.
Therefore we always know whether there is more to come, except
in the case where we see a newline/semicolon or similar.
For the purposes of sh -c, this should be sufficient.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The original ash defered forking commands in backquotes so builtins
could be run in the same context as the shell. This behavior was
controlled using the EV_BACKCMD to evaltree.
Unfortunately, as Matthias Scheler noticed in 1999 (NetBSD PR/7814),
the result was counterintuitive; for example, echo "`cd /`" would
change the cwd. So ash 0.3.5 left out that optimization. The
EV_BACKCMD codepath stayed around, unused.
Some time between ash 0.3.5-11 and ash 0.3.8-37, Debian ash omitted
the EV_BACKCMD pathway by guarding it with #ifdef notyet. In dash
0.5.1 and later, the commented code is no more. Let's finish the job
and remove the last vestiges. If someone wants to work on omitting
the fork in backcmd, the remaining hints are not going to be very
helpful, anyway.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Sun, Nov 07, 2010 at 02:21:21AM +0000, Jonathan Nieder wrote:
>
> Just ran into some strange behavior:
>
> $ cat test.sh
> #!/bin/sh
> echo hello >greeting
> cat <<EOF &&
> $(cat greeting)
> EOF
> {
> echo $?
> cat greeting
> } >/dev/null
>
>
> $ sh test.sh
> hello
> test.sh: 7: {: not found
> 127
> hello
> test.sh: 10: Syntax error: "}" unexpected
>
> bash, mksh, pdksh, and ksh93 all print hello as expected. The problem
> is reproducible with all versions of dash in the git repo.
This is caused by the clobbering of checkkwd due to readtoken
recursion while parsing a here document.
This patch fixes it by saving the original value of checkkwd.
Reported-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When tracing (with the DEBUG compile-time option set to 1 or 2),
exverror calls TRACEV to print its arguments before passing them on.
So the arguments are consumed by the time exvwarning looks for them,
resulting in a segfault:
$ sh -c '"'
sh: Syntax error: Unterminated quoted string
$ sh -o debug -c '"'
sh: Segmentation fault (core dumped)
Make a copy with va_copy to avoid this.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Here's another bug bisecting to f42e443bb ([EXPAND] Fix
ifsfirst/ifslastp leak, 2010-09-08). It was found with the following
test case, based on the configure script for Tracker:
dash -x -c '
<<-_ACEOF
$@
_ACEOF
exec
' - abcdefgh
+
+ exec �a
exec: 1: : Permission denied
The missing ifsfree call is in expandarg when it returns to openhere
during here document expansion.
Reported-by: Aurelien Jarno <aurel32@debian.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is not unrelated: I changed the meaning of struct funcnode's field n
to refer to the function definition, rather than the list of the
function's commands, because I needed to refer to the function
definition node from evalfun, which only gets passed a funcnode. But it
is something that could be applied independently (without being useful
by itself), so I've attached it as a separate patch for easier review.
Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- 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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
The new read(1) implementation incorrectly assumes that ifsbreakup
ignores characters escaped by CTLESC. As such it fails to handle
backslashes except for escaping newlines.
This patch makes it use recordregion for every part that isn't
escaped by a backslash.
Reported-by: Jilles Tjoelker <jilles@stack.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Tim Allen wrote:
> The POSIX specification for the dot command[1] states:
>
> EXIT STATUS
> Returns the value of the last command executed, or a zero exit
> status if no command is executed.
>
> If an empty file is sourced, then "no command is executed"
I agree. Looking through "git log --patch src/main.c", though, I find
v0.5.3~42 (Do not clobber exit status in dotcmd., 2005-03-03), which
appears to have been meant to take care of the following case:
$ cat printstatus.sh
echo $?
$ false
$ . ./printstatus.sh
1
I wonder if the following on top might help (imitating evalcmd)?
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The changeset 55c46b7286f5d9f2d8291158203e2b61d2494420
[BUILTIN] Honor tab as IFS whitespace when splitting fields in readcmd
uses CTLESC to prevent field splitting in read(1). However,
it did not escape CTLESC itself in the input stream. This patch
adds the necessary CTLESC characters so that CTLESC isn't corrupted.
Reported-by: Alexey Gladkov <gladkov.alexey@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- 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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A tilde expansion generates a valid pathname. Splitting it using IFS
either leaves it unchanged or changes it to something unintended.
This fixes FreeBSD sh test expansion/tilde1.0 and does not change the
outcome of the other tests.
This fixes Debian bug #601096.
Example:
IFS=m HOME=/tmp; printf "%s\n" ~
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
| |
Replace noclobberopen() from bash with the FreeBSD code for noclobber
opens.
This also reduces code size by eliminating an unnecessary check.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Sun, Nov 07, 2010 at 04:04:20PM -0600, Jonathan Nieder wrote:
>
> Herbert Xu wrote:
>
> > commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa
> > Author: Herbert Xu <herbert@gondor.apana.org.au>
> > Date: Wed Sep 8 20:07:26 2010 +0800
> >
> > [EXPAND] Fix ifsfirst/ifslastp leak
>
> Another puzzle bisecting to f42e443bb. This one comes from the
> grub-mkconfig script:
>
> $ sh -c 'datadir=/usr/share; pkgdatadir=${datadir}/`cat`' 2>&1 | cat -A
> cat: M-^\^M^F^HM-4^M^F^HM-(^M^F^H: No such file or directory$
> cat: M-(^M^F^H: No such file or directory$
>
> Still reproducible with 016b529. I'll try to find time to look into
> it, but thought you might like to know nevertheless.
This is the symptom of another leak. In this case evalbackcmd
occurs in the middle of an expansion (as it should) but the forked
child never clears the previous IFS state.
This patch adds the missing ifsfree call.
This wasn't as much of a problem as the previously discovered leaks
since all it means is that the child gets to carry around the parent's
expansion state and the child is usually short-lived.
Reported-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
trap.c: In function 'exitshell':
trap.c:354: warning: variable 'status' might be clobbered by 'longjmp' or 'vfork'
Signed-off-by: Maciej Żenczykowski <zenczykowski@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
| |
At some point between ash 0.3.5-11.0.1 and ash 0.3.8-37, Debian
ash stopped using the EXSHELLPROC exception to handle shell
scripts without a magic number.
Remove all remaining references to it to avoid confusion.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The intended semantics of EXEXEC are identical to EXEXIT, so
simplify by using EXEXIT directly.
Functional change: in edge cases (exec within a trap handler),
this causes the exit status from exec not to be clobbered.
For example, without this patch:
$ sh -c 'trap "exec nonexistent" EXIT'; echo $?
exec: 1: nonexistent: not found
0
And with it:
$ sh -c 'trap "exec nonexistent" EXIT'; echo $?
exec: 1: nonexistent: not found
127
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit makes dash exit with return code 127 instead of 2 if
started as non-interactive shell with a non-existent command_file
specified as argument (or a directory), as documented in
http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14
The wrong exit code was reported by Clint Adams and Jari Aalto through
http://bugs.debian.org/548743
http://bugs.debian.org/548687
Signed-off-by: Gerrit Pape <pape@smarden.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
Some errors have exit status values specified by POSIX and it is
therefore desirable to be able to set the exit status at the EXERROR
source rather than in main.c.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
| |
While inspecting some dash scripts on my system, I was surprised to
see that some of them use an open parenthesis at the beginning of case
patterns while that's not mentioned in the manpage. Dash currently is
fine with and without that parenthesis (parser.c:413). The attached
patch documents this feature.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Wed, Aug 11, 2010 at 08:06:16AM +0000, Guido Berhoerster wrote:
>
> with the latest git version of dash trap actions are not
> evaluated in the context of a function.
>
> The following script demonstrates the bug:
> ----8<----
> read_timeout () {
> saved_traps="$(trap)"
> trap 'printf "timed out\n"; eval "${saved_traps}"; return' TERM
> ( sleep $1; kill -TERM $$ ) >/dev/null 2>&1 &
> timer_pid=$!
> read $2
> kill $timer_pid 2>/dev/null
> }
>
> read_timeout 5 value
> printf "read \"%s\"\n" "${value:=default}"
>
> ---->8----
> The return statement in the trap inside the read_timeout function
> does not return from the function but rather exits the script.
>
> With dash 0.5.5.1 it works as expected.
This bug was caused by the SKIPEVAL removal. When the SKIPEVAL
hack was added to improve set -e support in traps, dotrap was
changed to return whether set -e was detected. After the removal
of SKIPEVAL, set -e is now handled through exraise.
However, dotrap still returned a value which is now incorrectly
used to trigger an exraise.
This patch removes the vestigial link between dotrap and exraise.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa
[EXPAND] Fix ifsfirst/ifslastp leak
revealed yet another ifsfirst/ifslastp leak in casematch.
Previously it was hidden because ifsfirst/ifslastp was cleared
unconditionally on entry (which caused the leakage of those
entries).
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
| |
evalcommand always clobbers the exit status in case of an EXEXEC
which means that exec always fails with exit status 2 regardless
of what it actually returns.
This patch adds the missing check for EXEXEC so that the correct
exit status is preserved.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
| |
The new read(1) code fails to handle the last variable correctly if
it happens to be terminated by IFS characters. Those characters
are included in the last variable but they should not be.
This patch fixes this.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
As it stands expandarg may return with a non-NULL ifslastp which
then confuses any subsequent ifsbreakup user that doesn't clear
it directly.
What's worse, if we get interrupted before we hit ifsfree in
expandarg we will leak memory.
This patch fixes this by always calling ifsfree in expandarg
thus ensuring that ifslastp is always NULL on the normal path.
It also adds an ifsfree call to the RESET path to ensure that
memory isn't leaked.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Git commit 0df96793ef6aa103df228d7dfe56099b7d721a15 "[SHELL] Add
preliminary LINENO support" added the LINENO variable in the middle of
other initialized variables, causing some macros for TERM and HISTSIZE
to break (both of these are only used if libedit support is compiled in,
which is not the case by default).
The breakage is the same as can be seen by setting HISTSIZE=0.
Also add a comment warning about this.
Reported-by: Wez Furlong <kingwez@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Example:
$ dash -c 'set -e; (false); echo here'
here
With this commit, dash exits 1 before echo.
The bug was reported by Stefan Fritsch through
http://bugs.debian.org/514863
Signed-off-by: Gerrit Pape <pape@smarden.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
| |
The notyet code is identical to the current code.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Brian Koropoff reported that the new var patches broke the following
script:
#!/bin/dash
GDM_LANG="bar"
OPTION="foo"
unset GDM_LANG
# OPTION has mysteriously become unset
echo "$OPTION"
He correctly diagnosed this as a result of removing all variables
in the hash chain preceding the one that should be removed in
setvareq.
He also provided a patch to fix this.
This patch is based on his but without keeping the original vpp.
As a result, we now store new variables at the end of the hash
chain instead of the beginning.
To make this work, setvareq/setvar now returns the vp pointer
modified. In case they're used to unset a variable the pointer
returned is undefined. This is because mklocal needs it and
used to get it by assuming that the new variable always appear
at the beginning of the chain.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
According to
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_12
"A subshell environment shall be created as a duplicate of the shell
environment, except that signal traps set by that shell environment
shall be set to the default values."
Currently the eflag is cleared when forking a subshell, e.g.
$ dash -c 'set -e ; z=$(false;echo foo) ; echo $z'
foo
With this commit the eflag is preserved for subshells, and dash exits 1
before echo.
The problem was reported by Vincent Lefevre through
http://bugs.debian.org/514863
Signed-off-by: Gerrit Pape <pape@smarden.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|