History log of /netbsd-src/bin/sh/eval.c (Results 76 – 100 of 197)
Revision Date Author Comments
# 404b1d02 03-May-2016 kre <kre@NetBSD.org>

Fix things so that STATIC can me made static (-DSTATIC=static)
and have the shell still compile, link, and run...

ok christos@


# 1d680406 03-May-2016 kre <kre@NetBSD.org>

PR bin/43639 - check that a file being read by the '.' command
is a regular file, even when it is given as a full pathname.


# 1fad4bb6 02-May-2016 christos <christos@NetBSD.org>

Fix handing of user file descriptors outside the 0..9 range.
Also, move (most of) the shell's internal use fd's to much
higher values (depending upon what ulimit -n allows) so they
are less likely to

Fix handing of user file descriptors outside the 0..9 range.
Also, move (most of) the shell's internal use fd's to much
higher values (depending upon what ulimit -n allows) so they
are less likely to clash with user supplied fd numbers. A future
patch will (hopefully) avoid this problem completely by dynamically
moving the shell's internal fds around as needed. (From kre@)

show more ...


# 0c73873e 16-Mar-2016 christos <christos@NetBSD.org>

Keep redirs for subshells.


# 2baec48e 13-Mar-2016 christos <christos@NetBSD.org>

We want this to work too:
$ cat sep1
#!/bin/sh
{ ./sep2; } 3>out

$ cat sep2
#!/bin/sh
echo sep2 >&3

$ ./sep1


# 5047abd1 12-Mar-2016 christos <christos@NetBSD.org>

Don't close-on-exec redirections created explicitly for the command being
ran; i.e. we want this to work:
$ cat succ1
#!/bin/sh
./succ2 6>out

$ cat succ2
#!/bin/sh
echo succ2 >&6

$ ./succ1

Don't close-on-exec redirections created explicitly for the command being
ran; i.e. we want this to work:
$ cat succ1
#!/bin/sh
./succ2 6>out

$ cat succ2
#!/bin/sh
echo succ2 >&6

$ ./succ1

And this to fail:
$ cat fail1
#!/bin/sh
exec 6> out
echo "fail1" >&6
./fail2
exec 6>&-

$ cat fail2
#!obj.amd64/sh
echo "fail2" >&6

$ ./fail1
./fail2: 6: Bad file descriptor

XXX: Do we want a -k (keep flag on exec to make redirections not close-on-exec?

show more ...


# f87bc150 12-Mar-2016 christos <christos@NetBSD.org>

Improve quoting in the output from sh -x - use less unnecessary
quotes ('_' and '.' do not need quoting) and never quote the '=' in
an assignment (or it would not be one.) From kre, with some refacto

Improve quoting in the output from sh -x - use less unnecessary
quotes ('_' and '.' do not need quoting) and never quote the '=' in
an assignment (or it would not be one.) From kre, with some refactoring
to be blamed to me.

show more ...


# a584b40f 29-Feb-2016 christos <christos@NetBSD.org>

Complete implementation of the noexec option (-n) including
disabling noexec, if the shell is interactive, each time that
a new command is about to be read. Also correct the -I
(ignoreeof) option so

Complete implementation of the noexec option (-n) including
disabling noexec, if the shell is interactive, each time that
a new command is about to be read. Also correct the -I
(ignoreeof) option so that it only applies to interactive shells,
as required by posix. (from kre)

show more ...


# bc8cfb7d 27-Feb-2016 christos <christos@NetBSD.org>

Improve debugging, from kre (I hooked it to the build).


# 8b2383fc 24-Feb-2016 christos <christos@NetBSD.org>

PR/46327: David Mandelberg: Fix exit codes of background jobs (from kre)


# 9e6b737d 22-Feb-2016 christos <christos@NetBSD.org>

PR/43255: Make -n apply to the -c string so sh -n -c 'commands' works
as it should. Also, other places where the shell parses strings of
commands are also now controlled by -n (traps, eval, ...) (fr

PR/43255: Make -n apply to the -c string so sh -n -c 'commands' works
as it should. Also, other places where the shell parses strings of
commands are also now controlled by -n (traps, eval, ...) (from kre)

show more ...


# d18385a5 04-Jan-2016 christos <christos@NetBSD.org>

Don't leak redirected rescriptors to exec'ed processes. This is what ksh
does, but bash does not. For example:

$ cat test1
#!/bin/sh
exec 6> out
echo "test" >&6
sh ./test2
ex

Don't leak redirected rescriptors to exec'ed processes. This is what ksh
does, but bash does not. For example:

$ cat test1
#!/bin/sh
exec 6> out
echo "test" >&6
sh ./test2
exec 6>&-
$ cat test2
echo "test2" >&6
$ ./test1
./test2: 6: Bad file descriptor

This fixes by side effect the problem of the rc system leaking file descriptors
7 and 8 to all starting daemons:

$ fstat -p 1359
USER CMD PID FD MOUNT INUM MODE SZ|DV R/W
root powerd 1359 wd / 2 drwxr-xr-x 512 r
root powerd 1359 0 / 63029 crw-rw-rw- null rw
root powerd 1359 1 / 63029 crw-rw-rw- null rw
root powerd 1359 2 / 63029 crw-rw-rw- null rw
root powerd 1359 3* kqueue pending 0
root powerd 1359 4 / 64463 crw-r----- power r
root powerd 1359 7 flags 0x80034<ISTTY,MPSAFE,LOCKSWORK,CLEAN>
root powerd 1359 8 flags 0x80034<ISTTY,MPSAFE,LOCKSWORK,CLEAN>
root powerd 1359 9* pipe 0xfffffe815d7bfdc0 -> 0x0 w

Note fd=7,8 pointing to the revoked pty from the parent rc process.

show more ...


# 334f5d77 02-Jan-2015 christos <christos@NetBSD.org>

Define an undocumented -F option to only use fork instead of vfork for
debugging purposes.


# 01f35fcc 31-May-2014 christos <christos@NetBSD.org>

PR/48843: Jarmo Jaakkola: dot commands mess up scope nesting tracking

Evaluation of commands goes completely haywire if a file containing
a break/continue/return command outside its "intended" scope

PR/48843: Jarmo Jaakkola: dot commands mess up scope nesting tracking

Evaluation of commands goes completely haywire if a file containing
a break/continue/return command outside its "intended" scope is sourced
using a dot command inside its "intended" scope. The main symptom is
not exiting from the sourced file when supposed to, leading to evaluation
of commands that were not supposed to be evaluated. A secondary symptom
is that these extra commands are not evaluated correctly, as some of them
are skipped. Some examples are listed in the How-To-Repeat section.

According to the POSIX standard, this is how it should work:
dot:
The shell shall execute commands from the file in the current
environment.
break:
The break utility shall exit from the smallest enclosing for, while,
or until loop, [...]
continue:
The continue utility shall return to the top of the smallest
enclosing for, while, or until loop, [...]
return:
The return utility shall cause the shell to stop executing
the current function or dot script. If the shell is not currently
executing a function or dot script, the results are unspecified.

It is clear that return should return from a sourced file, which
it does not do. Whether break and continue should work from the sourced
file might be debatable. Because the dot command says "in the current
environment", I'd say yes. In any case, it should not fail in weird
ways like it does now!

The problems occur with return (a) and break/continue (b) because:
1) dotcmd() does not record the function nesting level prior to
sourcing the file nor does it touch the loopnest variable,
leading to either
2 a) returncmd() being unable to detect that it should not set
evalskip to SKIPFUNC but SKIPFILE, or
b) breakcmd() setting evalskip to SKIPCONT or SKIPBREAK,
leading to
3) cmdloop() not detecting that it should skip the rest of
the file, due to only checking for SKIPFILE.
The result is that cmdloop() keeps executing lines from the file
whilst evalskip is set, which is the main symptom. Because
evalskip is checked in multiple places in eval.c, the secondary
symptom appears.
>How-To-Repeat:
Run the following script:

printf "break\necho break1; echo break2" >break
printf "continue\necho continue1; echo continue2" >continue
printf "return\necho return1; echo return2" >return

while true; do . ./break; done

for i in 1 2; do . ./continue; done

func() {
. ./return
}
func

No output should be produced, but instead this is the result:
break1
continue1
continue1
return1

The main symptom is evident from the unexpected output and the secondary
one from the fact that there are no lines with '2' in them.
>Fix:
Here is patch to src/bin/sh to fix the above problems. It keeps
track of the function nesting level at the beginning of a dot command
to enable the return command to work properly.

I also changed the undefined-by-standard functionality of the return
command when it's not in a dot command or function from (indirectly)
exiting the shell to being silently ignored. This was done because
the previous way has at least one bug: the shell exits without asking
for confirmation when there are stopped jobs.

Because I read the standard to mean that break and continue should have
an effect outside the sourced file, that's how I implemented it. For what
it's worth, this also seems to be what bash does. Also laziness, because
this way required no changes to loopnesting tracking. If this is not
wanted, it might make sense to move the nesting tracking to the inputfile
stack.

The patch also does some clean-up to reduce the amount of global
variables by moving the dotcmd() and the find_dot_file() functions from
main.c to eval.c and making in_function() a proper function.

show more ...


# 1468e9a3 26-Jan-2014 christos <christos@NetBSD.org>

explain why forks fail


# 44f76837 27-Jun-2013 yamt <yamt@NetBSD.org>

fix descriptor leaks. PR/47805

this fix was taken from FreeBSD SVN rev 199953 (Jilles Tjoelker)
------------------------------------------------------------------------
r199953 | jilles | 2

fix descriptor leaks. PR/47805

this fix was taken from FreeBSD SVN rev 199953 (Jilles Tjoelker)
------------------------------------------------------------------------
r199953 | jilles | 2009-11-30 07:33:59 +0900 (Mon, 30 Nov 2009) | 16 lines

Fix some cases where file descriptors from redirections leak to programs.

- Redirecting fds that were not open before kept two copies of the
redirected file.
sh -c '{ :; } 7>/dev/null; fstat -p $$; true'
(both fd 7 and 10 remained open)
- File descriptors used to restore things after redirection were not
set close-on-exec, instead they were explicitly closed before executing
a program normally and before executing a shell procedure. The latter
must remain but the former is replaced by close-on-exec.
sh -c 'exec 7</; { exec fstat -p $$; } 7>/dev/null; true'
(fd 10 remained open)

The examples above are simpler than the testsuite because I do not want to
use fstat or procstat in the testsuite.

show more ...


# 21353481 02-Mar-2013 christos <christos@NetBSD.org>

PR/47608: Robert Elz: ``var=value func-call'' does not export var in the
function (+FIX)


# 0e82f4eb 02-Jan-2013 dsl <dsl@NetBSD.org>

include limits.h for CHAR_MIN


# 0adfd5e0 14-Jun-2012 joerg <joerg@NetBSD.org>

Make sure temp_path is always initialised, even if mklocal fails.
Make sure to restore localvars, even if possibly leaking memory.
Discussed with christos@


# 1847bab5 14-Nov-2011 christos <christos@NetBSD.org>

PR/45613: Aleksey Cheusov: /bin/sh: 'set -e' + 'if eval false' problem
Fixed from: http://www.freebsd.org/cgi/query-pr.cgi?pr=134881&cat=


# 9f61b804 31-Aug-2011 plunky <plunky@NetBSD.org>

NULL does not need a cast


# db28d566 17-Feb-2011 pooka <pooka@NetBSD.org>

Tell copyfd if the caller wants the exact tofd to just fd >= tofd.
Fixes "echo foo > /rump/bar" in a rump hijacked shell.

reviewed by christos


# eb956cbd 03-Jun-2010 christos <christos@NetBSD.org>

need errno for the debug build.


# f82c1d73 03-Jun-2010 christos <christos@NetBSD.org>

set -e is supposed to work inside eval; skip EV_TESTED.


# 10aa8c24 07-Oct-2009 christos <christos@NetBSD.org>

only for when trap if we are going to exit.


12345678