[PATCH] [EVAL] Force fork if any trap is set, not just on EXIT.

2010-05-14 Thread Jilles Tjoelker
mp; sleep 1; kill $!;wait' This works correctly even without this patch. Signed-off-by: Jilles Tjoelker --- src/eval.c |4 ++-- src/trap.c | 16 +++- src/trap.h |2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/eval.c b/src/eval.c index 62d9d5d..e7c

[PATCH] [EXPAND] Fix corruption of redirections with byte 0x81.

2010-05-16 Thread Jilles Tjoelker
r Korolkov in Ubuntu #422298. Signed-off-by: Jilles Tjoelker --- src/expand.c |2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/src/expand.c b/src/expand.c index 48c45e5..f2f964c 100644 --- a/src/expand.c +++ b/src/expand.c @@ -210,8 +210,6 @@ expandarg(union node *arg, s

Re: unexpected parameter expansion

2010-05-19 Thread Jilles Tjoelker
don't have a patch to suggest. I think this part needs a testsuite before any further changes :) You could start from the posh or FreeBSD sh testsuites and what's in the commit messages. Or if you have little programmer time but lots of CPU time, rebuild all packages in the debian archive

Re: wait regression in 3800d4

2010-05-22 Thread Jilles Tjoelker
the most common use of the wait builtin. I can even reproduce the regression with the test script in 3800d49's commit message: sometimes I see a line *** 148 meaning that the wait builtin was aborted by SIGCHLD (even though no CHLD trap has been set); however only on an SMP system. (This is on FreeBS

Re: [PATCH 1/4] [VAR] Add localvars nesting

2010-05-26 Thread Jilles Tjoelker
ot;not in a function"); > + > argv = argptr; > while ((name = *argv++) != NULL) { > mklocal(name); This change (failing local outside functions), while a good idea, should be mentioned in the commit message/changelog, as it might break certain scripts. (Note that in mksh local is an alias for typeset, which will work outside functions.) -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH 4/4] [VAR] Replace cmdenviron with localvars

2010-05-26 Thread Jilles Tjoelker
x27;local' may need additional magic to avoid making things local to the temporary regular-builtin scope. I suppose only functions should induce scope for 'local', such that things like command eval 'local i' continue to create a variable local to the function. -- Jilles

Re: Job control bug in revision 3800d4934391b,

2010-05-28 Thread Jilles Tjoelker
sting scripts suggests that traps should not abort a read. Executing the trap right away is useful in case it does something such as exiting, and should be safe given that traps are already invoked from deeper levels of recursion of the interpreter. If the trap executes a break, continue or return com

Re: [PATCH 4/4] [VAR] Replace cmdenviron with localvars

2010-05-29 Thread Jilles Tjoelker
ly and ksh93's typeset are special as well), consensus seems to be for local to be a regular builtin. posh's local was special for a short time, but this was then reverted. Nevertheless, it is very nice to have IFS=: read ... working again. -- Jilles Tjoelker -- To unsubscribe from this list:

debian patches to exit with code 127 for nonexistent/directory scripts

2010-06-05 Thread Jilles Tjoelker
clear about what 'command .' should do, but is very clear that failure to find/read a dot script shall not cause an interactive shell to exit. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org M

Re: Some utf-8 characters are cut in the middle on redirections

2010-08-08 Thread Jilles Tjoelker
which is not in any dash release yet. The patch should apply to older dash versions also. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: No wildcard expansion with redirected filenames

2010-08-08 Thread Jilles Tjoelker
posed to work. POSIX says that a non-interactive shell must not generate pathnames for a redirection; an interactive shell may do so, provided there is exactly one match. Dash is primarily meant as a non-interactive shell and wants to be as small as possible, and therefore never generates pathnames for

Re: The Greek letter "rho" is considered as two letters

2010-08-08 Thread Jilles Tjoelker
stent behaviour with other utilities that do support locales. For FreeBSD's /bin/sh, which is another ash variant, I think some degree of locale support (at least for utf-8) is desirable at some point. This would include changing pattern matching and ${#var}. I don't know what Herbert Xu

Re: "fc -l" broken between v0.5.5.1 and v0.5.6

2010-08-08 Thread Jilles Tjoelker
duced the problem. See git help bisect or http://www.kernel.org/pub/software/scm/git/docs/git-bisect-lk2009.html . -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

[PATCH] [VAR] Fix history (libedit only).

2010-08-13 Thread Jilles Tjoelker
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 ca

Re: trap bug in recent versions of dash

2010-08-15 Thread Jilles Tjoelker
missing here. > } > 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 da

Re: trap bug in recent versions of dash

2010-08-22 Thread Jilles Tjoelker
On Mon, Aug 16, 2010 at 01:52:56PM +0200, Guido Berhoerster wrote: > * Jilles Tjoelker [2010-08-15 22:05]: > > On Wed, Aug 11, 2010 at 10:06:16AM +0200, Guido Berhoerster wrote: > > > with the latest git version of dash trap actions are not > > > evaluated in the co

Re: [Partial patch] IFS and read builtin

2010-08-22 Thread Jilles Tjoelker
mporting FreeBSD's code at less than 50. It will also fix an edge case with the splitting. The last two lines of FreeBSD's builtins/read1.0 test are: echo " 1 ,2 3," | { IFS=', ' read a b c; echo "x${a}x${b}x${c}x"; } echo " 1 ,2 3,,"

Re: [Partial patch] IFS and read builtin

2010-08-23 Thread Jilles Tjoelker
On Mon, Aug 23, 2010 at 02:03:01AM +0200, Harald van Dijk wrote: > On 23/08/10 01:00, Jilles Tjoelker wrote: > > On Mon, Aug 23, 2010 at 12:20:12AM +0200, Harald van Dijk wrote: > >>[...] > >> echo a:b | { IFS=: read a b; echo $a; } > >>[...] > > &g

Re: trap bug in recent versions of dash

2010-08-23 Thread Jilles Tjoelker
On Mon, Aug 23, 2010 at 12:40:48PM +0200, Guido Berhoerster wrote: > * Jilles Tjoelker [2010-08-23 00:32]: > > If you want to try something, here is a patch. I have verified that the > > only change to the results of FreeBSD sh's testsuite is that the test > > builti

Re: [Partial patch] IFS and read builtin

2010-08-24 Thread Jilles Tjoelker
On Tue, Aug 24, 2010 at 12:51:47AM +0200, Harald van Dijk wrote: > On 23/08/10 21:35, Jilles Tjoelker wrote: > > I think you should do what you think is best for the stability of your > > product. Because dash releases are not extensively tested, I'd recommend > > a

Re: read() builtin doesn't read integer value /proc files (but bash's does)

2010-09-02 Thread Jilles Tjoelker
way to read these files needs to be documented, and clear violations that will not work properly should cause an error (in this case, this means that reading one byte from offset 0 should fail like reading one byte from offset 1 does). -- Jilles Tjoelker -- To unsubscribe from this list: send the

Re: read() builtin doesn't read integer value /proc files (but bash's does)

2010-09-03 Thread Jilles Tjoelker
very common construct while read x; do ... done stops working. A possible fix is to check first if the input supports seeking. If it does, use the buffering and at the end of the line seek backwards for the number of bytes remaining in the buffer. If it does not, read one byte at a time. -- Ji

Re: read() builtin doesn't read integer value /proc files (but bash's does)

2010-09-04 Thread Jilles Tjoelker
On Sat, Sep 04, 2010 at 08:20:33PM +0200, Steve Schnepp wrote: > 2010/9/3 Jilles Tjoelker : > > This patch assumes that the file descriptor is discarded afterwards (its > > position does not matter). Therefore the very common construct > >  while read x; do > >    ...

[PATCH] [BUILTIN] Fix various issues with read by importing the NetBSD/FreeBSD code.

2010-09-07 Thread Jilles Tjoelker
This reverts the change to make read use the code from expand.c. Although read's splitting is similar to the splitting done as part of word expansions, the differences appear to add more complexity than the common code saves. The new code is from FreeBSD (which was originally taken from NetBSD). T

Re: [PATCH] fix UTF-8 issues in read() builtin

2010-09-07 Thread Jilles Tjoelker
rd}.) The patch I posted separately fixes the handling of 0x81 and various other issues with read (by using separate code instead of trying to use expand.c). Backslash escaping works too although I have just found some bugs with corner cases. -- Jilles Tjoelker -- To unsubscribe from this list: sen

Re: exit-ing in a trap handler uses the wrong exit code

2010-09-25 Thread Jilles Tjoelker
ll terminate the process immediately. In any case, if the shell itself gets an actual SIGSEGV, its state is probably too messed up to continue executing a script. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: bug with <&- under ulimit -n

2010-10-27 Thread Jilles Tjoelker
y most kinds of Korn shell and dash. The latter behaviour is shown by the Bourne shell, most other ash derivatives, bash and zsh. A command like (ulimit -n 10; /bin/foo 3<&- 4<&-; :) will only work in a shell that uses the latter behaviour. I consider both behaviours valid and shell

Re: static vs. dynamic scoping

2010-11-10 Thread Jilles Tjoelker
hese were converted to the local mechanism recently). The real efficiency benefit of static scoping comes when disallowing access to locals when the name is not known at compile time: at run time, the names of the locals are not necessary. -- Jilles Tjoelker -- To unsubscribe from this list: se

Re: [PATCH] Improved LINENO support

2010-11-10 Thread Jilles Tjoelker
so nested function definitions may lead to incorrect line numbers, but that could be fixed.) I think this patch will increase dash's code size at least a little, which is always a consideration here. I can also look at getting this into FreeBSD sh. Thanks, -- Jilles Tjoelker -- To unsubscribe fro

Re: [PATCH] Improved LINENO support

2010-11-12 Thread Jilles Tjoelker
. Second idea: use a per-word LINENO but somehow ensure it is the same for all words in a command. I think this is wrong, but perhaps I'm wrong. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org M

Re: Quoted closing brace in variable default expansion

2010-11-13 Thread Jilles Tjoelker
ile ksh93 treats it as an incomplete command.) As for the portable alternative, split up the command. Either put the '}'-containing thing in a variable and use that as alternative or use an explicit conditional. The Autoconf documentation has more information, for example. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: dash "set -e" breaks "trap INT"

2010-11-13 Thread Jilles Tjoelker
at all, only the EXIT trap. The cause is that sleep also gets the SIGINT and terminates on it, which can be seen by removing set -e and adding echo rc=$? after sleep. ksh93 has a sleep builtin, but this has no effect on above. Behaviour remains the same with /bin/sleep. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

[PATCH] [REDIR] Replace GPL noclobberopen code with the FreeBSD version.

2010-11-20 Thread Jilles Tjoelker
Replace noclobberopen() from bash with the FreeBSD code for noclobber opens. This also reduces code size by eliminating an unnecessary check. --- src/redir.c | 77 +++--- 1 files changed, 15 insertions(+), 62 deletions(-) diff --git a/src/red

[PATCH] [PARSER] Remove backslash before } in double-quotes in variable

2010-11-21 Thread Jilles Tjoelker
The backslash prevents the closing brace from terminating the substitution, therefore it should be removed. FreeBSD sh test expansion/plus-minus2.0 starts working, no other tests are affected. Example: printf "%s\n" ${$+\}} ${$+"\}"} "${$+\}}" should print } three times, without backslashes. --

[PATCH] [EXPAND] Do not split the result of tilde expansion

2010-12-05 Thread Jilles Tjoelker
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; prin

Re: read() builtin doesnt read integer value /proc files (but bashs does)

2010-12-18 Thread Jilles Tjoelker
On Wed, Dec 15, 2010 at 12:55:51PM -0600, Jonathan Nieder wrote: > Cristian Ionescu-Idbohrn wrote: > > On Sun, 28 Nov 2010, Herbert Xu wrote: > > > On Sat, Sep 04, 2010 at 07:35:04PM +0000, Jilles Tjoelker wrote: > >>> This discarding is still bad as it thro

Re: setvar MIA?

2011-01-11 Thread Jilles Tjoelker
of Almquist's additions like this one is certainly questionable; many of them have been removed. However, setvar has been available and documented in /bin/sh in all versions of FreeBSD, which makes removal less likely at this point. -- Jilles Tjoelker -- To unsubscribe from this list: sen

Re: [PATCH 1/3] Port to Solaris

2011-01-21 Thread Jilles Tjoelker
he way, I wonder what the advantage of imaxdiv() above separate % and / is. Compilers can detect the matching between a % b and a / b and do it in one operation, and any use of imaxdiv() trips gcc's -Waggregate-return. -- Jilles Tjoelker -- To unsubscribe from this list: send the line &

Re: jobs in scripts?

2011-03-09 Thread Jilles Tjoelker
allows 'kill' without depending on obscure corners of shells. If your script runs for a long time, use of $! should be paired with 'wait' (either for all $! values obtained or without parameters) so that the shell can forget about old jobs. Some shells are buggy and remem

Re: [PATCH] [BUILTIN] Fix corruption of reads with byte 0x81

2011-03-10 Thread Jilles Tjoelker
ed characters that should not be IFS splitting points, which is only relevant for WORD in ${VAR+WORD} and ${VAR-WORD}. A downside of this is that quoted and unquoted CTL* bytes cannot be distinguished; therefore I have solved this differently in FreeBSD. -- Jilles Tjoelker -- To unsubscribe from

Re: [PATCH] [PARSER] Remove backslash before } in double-quotes in variable

2011-03-11 Thread Jilles Tjoelker
On Thu, Mar 10, 2011 at 04:59:27PM +0800, Herbert Xu wrote: > On Sun, Nov 21, 2010 at 02:42:22PM +0100, Jilles Tjoelker wrote: > > The backslash prevents the closing brace from terminating the > > substitution, therefore it should be removed. > > > > FreeBSD sh test exp

Re: shift "fatal error"

2011-03-15 Thread Jilles Tjoelker
is). This was done a few years ago when the syntax-error property of special builtins was implemented, as making a too high shift count fatal caused a configure script in the FreeBSD base system to fail. I would not encourage the extension of accepting arithmetic expressions because that requires a s

Re: [PATCH/RFC dash 0/4] Avoid a fork before running last command given to -c

2011-04-17 Thread Jilles Tjoelker
On Fri, Apr 15, 2011 at 09:07:09PM +0800, Herbert Xu wrote: > On Sun, Apr 10, 2011 at 07:18:17AM +, Jonathan Nieder wrote: > > Jilles Tjoelker wrote[0]: > > > Regarding sh -c optimization, I am in favour of this. Uselessly waiting > > > 'sh -c' proc

Re: [PATCH] JOBS: fix klibc DEBUG compilation

2011-06-03 Thread Jilles Tjoelker
if /* DEBUG */ Why not just replace the non-standard setlinebuf() call with the standard setvbuf(tracefile, NULL, _IOLBF, 0); ? This appears to work just as well on FreeBSD and is C99 compliant (no POSIX needed here). The #define SMALL is only for disabling line editing and history (using libedi

Re: Porting dash to OpenBSD

2011-07-03 Thread Jilles Tjoelker
h other awk invocations, it seems more usual to use NR rather than FNR. They both do the same thing if there is only one input file. The nl utility has caused more portability problems already; the code in master has different options. This is so even though nl is in SUSv4 under the XSI option. We alr

Re: 'continue' does not work in files sourced with dotcmd

2011-07-09 Thread Jilles Tjoelker
evalskip = 0; + if (skip == SKIPFILE) + evalskip = 0; break; } } Using evalskip &= ~SKIPFILE; instead of if (skip == SKIPFILE) evalskip = 0; should also work and might genera

Re: 'continue' does not work in files sourced with dotcmd

2011-07-10 Thread Jilles Tjoelker
On Sat, Jul 09, 2011 at 10:07:30PM +0800, Herbert Xu wrote: > On Sat, Jul 09, 2011 at 03:07:04PM +0200, Jilles Tjoelker wrote: > > A fix for dash is below. The dash code is broken in a different way than > > the FreeBSD sh code was, but the patched code is pretty much the same. >

Re: Bug: temporary assignments vs shell function

2011-07-31 Thread Jilles Tjoelker
ell is different again, though. It ignores the assignments completely and does not even expand them (a y=${someunsetvar?} assignment is silently ignored). -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@

Re: evaluation of env variables in DASH

2011-10-19 Thread Jilles Tjoelker
. The fix is to use printf(1) instead of echo(1) if there is a possibility the string may start with '-' or contain '\'. In this case, printf '%s\n' "$A" This has been asked/reported more frequently and the answer has been that it will not be changed.

Re: Question about job control in non-interactive shells

2012-01-13 Thread Jilles Tjoelker
one or more processes they know are part of the job in this case, but dash calls kill() on a process group that is guaranteed not to exist. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH] var.c: check for valid variable name before printing in "export -p"

2012-02-25 Thread Jilles Tjoelker
kipping the shell if the command is simple enough) and particularly for dash for historical/compatibility reasons. I did something similar to the OP's patch in FreeBSD (SVN r223183): "set" and "export -p" skip variables with invalid names. Note that this problem cannot oc

Re: [PATCH] var.c: check for valid variable name before printing in "export -p"

2012-02-25 Thread Jilles Tjoelker
On Sun, Feb 26, 2012 at 01:31:55AM +1100, Herbert Xu wrote: > On Sat, Feb 25, 2012 at 03:30:04PM +0100, Jilles Tjoelker wrote: > > Most shells pass the environment variable through, such as bash, > > zsh, ksh93 and most ash derivatives. However, the original Bourne > > shell

Re: local var=$(cat) only reads one line

2012-04-09 Thread Jilles Tjoelker
less. Dash had this behaviour for some time but it was dropped again because of inconsistencies between implementations. However, there appears to be some sort of agreement on how it should work now: http://austingroupbugs.net/view.php?id=351 (scroll down to note 943). -- Jilles Tjoelke

Re: [BUG] dash doesn't report syntax error when it should on stray "fi"

2012-04-24 Thread Jilles Tjoelker
If there is an error in a command substitution that is normally not executed, most shells (except ash derivatives) will not notice this. For example, FreeBSD 9.0's sh is one of the few shells that detects the error in: if false; then `fi`; fi -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: wait and ctrl+Z

2012-05-03 Thread Jilles Tjoelker
> Are you suggesting that wait should always be used in a loop? With what > check exactly? Only if you have set any traps that resume execution of the original script (i.e. do not exit the process). Otherwise, if 'wait' is being called without parameters, you can do something like until wait; do :; done If 'wait' is being called with parameters, the required loop is very complicated. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH] Set SA_RESTART flag on SIGCHLD handler

2012-06-22 Thread Jilles Tjoelker
alled because of CHLD traps should remain unchanged. The former seems safest because SA_RESTART handlers still cause visible effects such as short writes. In case of a script doing 'trap "" CHLD', it is perhaps undesirable for "wait" to block forever, given that wait(2) doesn't do that either. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH] [BUILTIN] Allow SIG* signal names.

2012-07-03 Thread Jilles Tjoelker
), its usability goal makes that it has many non-mandatory features. You may like posh which attempts to comply to Debian policy only, even at the cost of usability. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [EXPAND] Nested parameter expansion results in an empty string when quoted

2012-08-28 Thread Jilles Tjoelker
gree with some of the choices I have made where POSIX (as modified by interpretations) is silent. The mksh, a shell from a different lineage, also has a good set of test cases. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH] sleep builtin

2012-11-02 Thread Jilles Tjoelker
eptable that an interactive sleep command cannot be ^Z'ed. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [PATCH] implement privmode support in dash

2013-08-22 Thread Jilles Tjoelker
check the return value from setuid() and similar functions. In particular, some versions of Linux may fail setuid() for [EAGAIN], leaving the process running with the same privileges. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Fwd: bug? Spawned childs always remain in zombie state

2013-08-23 Thread Jilles Tjoelker
etting CPU time often enough, this may legitimately happen if the loop contains a read builtin. In FreeBSD sh, I added a check for zombies before forking the first process of a background job. Some other shells call waitpid() or similar from a SIGCHLD handler; this reaps zombies faster at the cos

Re: glob pattern and redirected input file name

2013-08-30 Thread Jilles Tjoelker
with pathnames starting with '-', containing backslashes or ending with newlines. In a script you might do set -- foo-*.tar.gz if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then echo "Bad wildcard" exit 2 fi tar -xzf "$1" -- Jille

Re: exec command and error checking

2014-01-28 Thread Jilles Tjoelker
it is more useful. Note that the two behaviours are indistinguishable if a single simple command is entered. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Bug in man page

2014-03-14 Thread Jilles Tjoelker
id to be a "character string"; this may be a C'ism (meaning that it is not a wide character string). Note that a "byte" in POSIX terminology is a "character" in C standard terminology. I think the former is less ambiguous in general and should be the preferred ter

Re: "command -p" does not correctly limit search to a safe PATH

2014-09-27 Thread Jilles Tjoelker
o, but it can be found back through git history. Alternatively, you could rely on the linker combining common string constant endings: put in some #define for "/usr/sbin:/usr/bin:/sbin:/bin" and make defpathvar a #define instead of a const array. -- Jilles Tjoelker -- To unsubscribe from t

Re: Line continuation and variables

2014-10-29 Thread Jilles Tjoelker
} > + > + return c; > +} > + > > > /* This implementation of pgetc_eatbnl() does not allow pushing back a backslash, since that would call pungetc() twice without an intervening pgetc(). However, some places do attempt to push back a backslash. As a result, a script fi

Re: command substitutions in $PS4

2014-11-30 Thread Jilles Tjoelker
stitution in PS4 (POSIX does not require it anyway). It is treated as a syntax error. Talking about syntax errors, dash has a problem there as well. If there is a syntax error in PS4 and set -x is enabled, it will not execute any simple commands (assignments to PS4 cause an error a

Re: Possibly wrong handling of $_?

2014-12-25 Thread Jilles Tjoelker
course, be done in a myriad of other ways, but this one just seemed like > the most elegant to me. Whether this counts as a "need" or not is not for > me to say. > Personally I'd say the main argument for adding support for "$_" to dash > would be to avoid my

Re: getopts doesn't properly update OPTIND when called from function

2015-06-01 Thread Jilles Tjoelker
> So either way, I think something should change. But if you prefer to get > clarification first about the intended meaning of the POSIX wording, > that certainly seems reasonable to me. I think the POSIX wording is clear enough, but it may not be desirable to change getopts to work

Re: Ignored alias inside for loop

2015-07-26 Thread Jilles Tjoelker
The result is ok when running dash -c '. ./alias1.sh' but a command not found error message when running ksh93 -c '. ./alias1.sh'. Similarly, a string as passed to the -c option or eval or trap builtins may or may not be parsed fully before execution. -- Jilles Tjoelker -

Re: Ignored alias inside for loop

2015-07-26 Thread Jilles Tjoelker
t; > That doesn't seem to work either (in dash or bash). eval foobarbaz This may not be practical since it needs to be done for every alias use. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: shell: dash - large file support

2015-07-26 Thread Jilles Tjoelker
() or lstat() is always wrong, since the inode number may not fit in a non-largefile ino_t. This happens in various cases: test -ef/-nt/-ot, finding a dot script (. special builtin) and some related to the current directory. On another note, test -nt/-ot should really compare the nanoseconds parts as w

Re: dash: read does not ignore trailing spaces

2015-12-02 Thread Jilles Tjoelker
v ; echo "<$v>" ; }' correctly prints . Since dash has its own code for read's splitting, it is not possible to take a fix from NetBSD or FreeBSD sh, other than by replacing the splitting code completely with their version. -- Jilles Tjoelker -- To unsubscribe from this

Re: heredoc and subshell

2016-02-23 Thread Jilles Tjoelker
On Wed, Feb 24, 2016 at 01:07:44AM +0300, Oleg Bulatov wrote: > trying to minimize a shell code I found an unobvious moment with > heredocs and subshells. > Is it specified by POSIX how next code should be parsed? dash output > for this code differs from bash and zsh. > --- code > prefix() { sed

Re: Declaring local variables inside while loop leads to memory leak

2016-07-26 Thread Jilles Tjoelker
ot of memory. The memory is freed when the function returns. This could be fixed by adding a check before making a variable local but that might make functions with many distinct locals slower. Also note that the problem does not occur if local is used at the top of a function only, as recommended b

Re: [PATCH 2/2] histedit: Remove non-glibc fallback code

2016-08-04 Thread Jilles Tjoelker
of these methods to reset getopt(). However, removing the dependency on this feature is simple. The shell already features a function nextopt() that can be used to parse options and is automatically set up for builtins. >From 23da600dcff616662a93f307420d9142598e2cae Mon Sep 17 00:00:00 2001 Fro

Re: [PATCH 2/2] histedit: Remove non-glibc fallback code

2016-08-08 Thread Jilles Tjoelker
On Thu, Aug 04, 2016 at 05:59:08PM +0200, Jilles Tjoelker wrote: > >From 23da600dcff616662a93f307420d9142598e2cae Mon Sep 17 00:00:00 2001 > From: Jilles Tjoelker > Date: Thu, 4 Aug 2016 17:51:12 +0200 > Subject: [PATCH 1/2] [HISTEDIT] Stop depending on getopt reset feature. >

Re: declaration utilities (was: [bug-diffutils] bug#24116: [platform-testers] new snapshot available: diffutils-3.3.50-0353)

2016-08-23 Thread Jilles Tjoelker
e that the current standard forbids special quoting rules for export and readonly, making this change sooner rather than later will be helpful to users. Looking at ChangeLog.O, I can see dash had special quoting rules for export, readonly and local between 1997 and 2001. They were removed, basically,

Re: [BUG] regression in builtin echo

2016-09-02 Thread Jilles Tjoelker
cause all characters following it in the arguments to be ignored (so not only in the argument where \c occurs). For example: echo 'a\cb' c; echo d shall write "ad" followed by a newline. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Parameter expansion, patterns and fnmatch

2016-09-02 Thread Jilles Tjoelker
d to say. Looking at as simple code as possible, this seems, however, unhelpful. Since a pattern like *[ should match the literal string *[ in the choice where brackets that do not introduce a bracket expression are supposed to disable other special characters and any earlier work on the * is theref

Re: [BUG] regression in builtin echo

2016-09-02 Thread Jilles Tjoelker
On Fri, Sep 02, 2016 at 10:19:12PM +0800, Herbert Xu wrote: > On Fri, Sep 02, 2016 at 04:16:31PM +0200, Jilles Tjoelker wrote: > > Unlike Harald van Dijk's patch, the above patch breaks \c. Per POSIX > > (XSI option), \c shall cause all characters following it in the > &g

Re: dash tested against ash testsuite: 17 failures

2016-10-10 Thread Jilles Tjoelker
$b" > > You can imagine... not everything went well here... > Again, this is probably down to legitimate differences in the > notoriously unportable "echo" builtin. Test this using printf instead. Seems like it. > > ash-vars/var_unbackslash.tests > ITYM ash-vars/var_unbackslash1.tests > > echo Forty two:$\ > > (\ > > (\ > > 42\ > > )\ > > ) > > dash says: Syntax error: Missing '))' > Yes, but it's not clear to me that it shouldn't. > Hmm... maybe this is indeed a bug: > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_01 > "A that is not quoted shall preserve the literal value of > the following character, with the exception of a . If a > follows the , the shell shall interpret this as > line continuation. The and shall be removed before > splitting the input into tokens. Since the escaped is removed > entirely from the input and is not replaced by any white space, it > cannot serve as a token separator." > So, unless I'm misreading this, it looks like backslashes need to be > parsed before *any* other kind of lexical analysis. Yes, for sequences that are not quoted. For example, contains two characters between the quotes, not zero. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: Bug? "fstat64(f, &sb) < 0 && S_ISREG(sb.st_mode)"

2016-10-26 Thread Jilles Tjoelker
system call > It seems to be the same case for mksh, ksh93, posh, pdksh. Not that it > matters though. Blocking is intended behaviour when opening a fifo without a counterparty. It can be used to good effect for synchronizing processes, sometimes even without transferring any data. -- Jilles

Re: [PATCH] trap: fix memory leak in exitshell()

2016-11-22 Thread Jilles Tjoelker
probably use the exception handling already present in the function to fix this. Note that ckfree() should only be used while INTOFF is in effect, both to avoid longjmp'ing out of free() and to ensure exactly one free in the presence of interruptions and errors. -- Jilles Tjoelker -- To unsub

Re: why does dash save, dup, and restore redirected descriptor in the parent, rather than redirect in the child?

2017-02-03 Thread Jilles Tjoelker
n64 fails? How should the child inform the parent > of this specific error? In general, you are right, but in the shell's case there is no difficulty. The error is reported via an error message to stderr and a non-zero exit status of the command, and the child process can easily do those t

Re: [PATCH] Don't execute binary files if execve() returned ENOEXEC.

2017-02-07 Thread Jilles Tjoelker
7;s definition. This check might cause a terse script with binary to fail to execute, but I have not received bug reports about that. Stopping the check with a \n will cause a PNG header to be considered text. Also, FreeBSD sh uses O_NONBLOCK when opening the file and pread() to read the data, in

Re: [PATCH] Don't execute binary files if execve() returned ENOEXEC.

2017-02-08 Thread Jilles Tjoelker
On Wed, Feb 08, 2017 at 09:02:33AM +0100, Adam Borowski wrote: > On Tue, Feb 07, 2017 at 11:52:08PM +0100, Jilles Tjoelker wrote: > > On Tue, Feb 07, 2017 at 09:33:07AM +0100, Adam Borowski wrote: > > > Both "dash -c foo" and "./foo" are supposed

Re: Small cleanup to src/dash.1 - Command Line Editing

2017-06-23 Thread Jilles Tjoelker
irly formal style of man pages avoids contractions, just like it avoids "you". The reference to the "later document" can probably be removed as well, since said document does not exist yet after many years. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [BUG] quoted substring parameter expansion ignores single-quotes in the arg

2017-10-21 Thread Jilles Tjoelker
this bug is caused by not distinguishing between +/-/=/? and #/##/%/%% varieties in the parser. Not maintaining state for eacg nesting level makes the parser more elegant, but it is untenable since there is no way one can parse both "${v+'}" and "${v#'*'}" correct

Re: [BUG] $PATH not fully searched

2018-01-10 Thread Jilles Tjoelker
ded, I strongly recommend quoting it since some shells such as dash do not implement the special rule for assignment utilities yet. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: expand: Do not quote backslashes in unquoted parameter expansion

2018-03-27 Thread Jilles Tjoelker
what they do because > they're not doing this optimisation. They do what they do because > they have broken POSIX because they always treat backslashes that > arise from parameter expansion as literal backslashes. Let's use clear terminology: if it affects behaviour, it is by defini

Re: Regression in dash 0.5.10 related to subshells

2018-05-06 Thread Jilles Tjoelker
gotsigchld) > + dowait(jp ? DOWAIT_BLOCK : DOWAIT_NORMAL, jp); > if (!jp) > return exitstatus; > st = getstatus(jp); Now each of the first four executable lines of waitforjob() does something different for jp == NULL and jp != NULL. It probably makes more

Re: builtin: Mark more regular built-ins

2018-05-15 Thread Jilles Tjoelker
ionale is that pwd should have been here since long ago (because it is in the list in XCU 2.9.1.1 Command Search and Execution), while the other three are new in SUSv4tc2. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to ma

Re: exec: Stricter pathopt parsing

2018-05-15 Thread Jilles Tjoelker
ative to hash -r that does not need the XSI option. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: [v2 PATCH] expand: Escape minus sign in arithmetic expansion

2018-05-31 Thread Jilles Tjoelker
lt; This negation overflows if result is INTMAX_MIN, leading to undefined behaviour. Perhaps leave the memtodest call but use STADJUST to remove the minus sign itself, leaving only the CTLESC or nothing. > + len++; > + } > + > + len += cvtnum(result); > >

Re: [PATCH 1/6] exec: Don't execute binary files if execve() returned ENOEXEC.

2018-09-11 Thread Jilles Tjoelker
if (c == '\n') > + return 0; > + } > + return 0; > +} > + > + > STATIC void > tryexec(char *cmd, char **argv, char **envp) > { > @@ -162,6 +192,8 @@ repeat: > execve(cmd, argv, envp); > #endif > if (cmd != path_bshell && errno == ENOEXEC) { > + if (file_is_binary(cmd)) > + return; > *argv-- = cmd; > *argv = cmd = path_bshell; > goto repeat; -- Jilles Tjoelker

Re: [PATCH 4/5] Stop using deprecated function sigsetmask()

2018-10-16 Thread Jilles Tjoelker
e important than making the executable as small as possible, but the maintainer may not agree. -- Jilles Tjoelker

Re: [PATCH] Use a real non-cryptographic hash algorithm

2018-11-16 Thread Jilles Tjoelker
mination, and they are not in the public domain > like FNV-1a. > [snip] > +hashval = (hashval ^ (unsigned char)*p++) * FNV_PRIME; > [snip] > +hashval = (hashval ^ (unsigned char)*p++) * FNV_PRIME; > [snip] > +hashval = (hashval ^ (unsigned char) *p++) + FNV_PRIME; I suppose this latter one should be * instead of + as well? -- Jilles Tjoelker

Re: [PATCH] main: don't raise exception when executing dotcmd() on a non-existent file

2018-11-24 Thread Jilles Tjoelker
-existent-file Time-of-check-time-of-use issues should not be an issue for config files. Alternatively, one could try command . ./non-existent-file || true but this may ignore more errors than desired (such as syntax errors in the sourced file) and does not work correctly in yash 2.30. -- Jilles Tjoelker

Re: [v2 PATCH] eval: Reset handler when entering a subshell

2019-03-03 Thread Jilles Tjoelker
shell does not support the option, it exits. The fairly old dash v0.5.9.1 I tried works even differently, writing an error message (to stderr) followed by a. So it first continues after the error and then aborts when '.' ends. This seems clearly broken (but I think things have changed since back then). -- Jilles Tjoelker

  1   2   >