diff options
author | jilles <jilles@FreeBSD.org> | 2009-06-13 21:17:45 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2009-06-13 21:17:45 +0000 |
commit | 884d344808b868ba1813aabf798a590a5a99683a (patch) | |
tree | 1ba6a6bdd17a2f3f559156b067a6e4ca4fb08707 /bin/sh/input.c | |
parent | 7decb9c312312e3869ccb7439115644dc95ed665 (diff) | |
download | FreeBSD-src-884d344808b868ba1813aabf798a590a5a99683a.zip FreeBSD-src-884d344808b868ba1813aabf798a590a5a99683a.tar.gz |
Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.
This change only affects strings passed to -c, when the -s
option is not used.
The approach is to check if there may be additional data
in the string after parsing each command. If there is none,
use the EV_EXIT flag so that a fork may be omitted in
specific cases.
If there are empty lines after the command, the check will
not see the end 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.
PR: bin/113860
Reviewed by: stefanf
Approved by: ed (mentor)
Diffstat (limited to 'bin/sh/input.c')
-rw-r--r-- | bin/sh/input.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/bin/sh/input.c b/bin/sh/input.c index 81c1f0b..c97c496 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -321,6 +321,23 @@ check: } /* + * Returns if we are certain we are at EOF. Does not cause any more input + * to be read from the outside world. + */ + +int +preadateof(void) +{ + if (parsenleft > 0) + return 0; + if (parsefile->strpush) + return 0; + if (parsenleft == EOF_NLEFT || parsefile->buf == NULL) + return 1; + return 0; +} + +/* * Undo the last call to pgetc. Only one character may be pushed back. * PEOF may be pushed back. */ |