Skip to content

Commit

Permalink
ash: [REDIR] Remove redundant CLOEXEC calls
Browse files Browse the repository at this point in the history
Upstream commit:

    Date: Sun, 6 May 2007 19:28:56 +1000
    [REDIR] Remove redundant CLOEXEC calls

    Now that we're marking file descriptors as CLOEXEC in savefd, we no longer
    need to close them on exec or in setinputfd.

function                                             old     new   delta
ash_main                                            1478    1492     +14
setinputfile                                         224     226      +2
readtoken1                                          2752    2750      -2
shellexec                                            208     198     -10
clearredir                                            30       -     -30
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/2 up/down: 16/-42)            Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  • Loading branch information
Denys Vlasenko committed Oct 26, 2016
1 parent 6477460 commit e19923f
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions shell/ash.c
Original file line number Diff line number Diff line change
Expand Up @@ -5462,16 +5462,6 @@ popredir(int drop, int restore)
* Undo all redirections. Called on error or interrupt.
*/

/*
* Discard all saved file descriptors.
*/
static void
clearredir(int drop)
{
while (redirlist)
popredir(drop, /*restore:*/ 0);
}

static int
redirectsafe(union node *redir, int flags)
{
Expand Down Expand Up @@ -7559,7 +7549,6 @@ shellexec(char **argv, const char *path, int idx)
int exerrno;
int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */

clearredir(/*drop:*/ 1);
envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
if (strchr(argv[0], '/') != NULL
#if ENABLE_FEATURE_SH_STANDALONE
Expand Down Expand Up @@ -10191,7 +10180,6 @@ closescript(void)
static void
setinputfd(int fd, int push)
{
close_on_exec_on(fd);
if (push) {
pushfile();
g_parsefile->buf = NULL;
Expand Down Expand Up @@ -10223,6 +10211,8 @@ setinputfile(const char *fname, int flags)
}
if (fd < 10)
fd = savefd(fd);
else
close_on_exec_on(fd);
setinputfd(fd, flags & INPUT_PUSH_FILE);
out:
INT_ON;
Expand Down Expand Up @@ -13339,7 +13329,8 @@ reset(void)
tokpushback = 0;
checkkwd = 0;
/* from redir.c: */
clearredir(/*drop:*/ 0);
while (redirlist)
popredir(/*drop:*/ 0, /*restore:*/ 0);
}

#if PROFILE
Expand Down

0 comments on commit e19923f

Please sign in to comment.