ash: [REDIR] Remove redundant CLOEXEC calls
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 26 Oct 2016 13:38:44 +0000 (15:38 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 26 Oct 2016 13:38:44 +0000 (15:38 +0200)
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>
shell/ash.c

index 0490f7f7d7f2d74a83ac8e5959e7173121297154..b404449d0a9d035e02e33a93619d6863377cfbe0 100644 (file)
@@ -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)
 {
@@ -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
@@ -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;
@@ -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;
@@ -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