]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: reduce file-descriptors cleanup overhead
authorKarel Zak <kzak@redhat.com>
Thu, 17 Oct 2019 08:41:39 +0000 (10:41 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 17 Oct 2019 08:45:16 +0000 (10:45 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/883
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index d213e4784b8bb20a8089b62f5b491df51a57c4af..23bb3c43449d27b033dd2a7462be9d1972702585 100644 (file)
@@ -1116,14 +1116,15 @@ static void __attribute__((__noreturn__)) usage(void)
 int main(int argc, char **argv)
 {
        int c;
-       int cnt;
        char *childArgv[10];
        char *buff;
        int childArgc = 0;
        int retcode;
        struct sigaction act;
        struct passwd *pwd;
-
+       static const int wanted_fds[] = {
+               STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO
+       };
        struct login_context cxt = {
                .tty_mode = TTY_MODE,             /* tty chmod() */
                .pid = getpid(),                  /* PID */
@@ -1218,8 +1219,7 @@ int main(int argc, char **argv)
                        *p++ = ' ';
        }
 
-       for (cnt = get_fd_tabsize() - 1; cnt > 2; cnt--)
-               close(cnt);
+       close_all_fds(wanted_fds, ARRAY_SIZE(wanted_fds));
 
        setpgrp();       /* set pgid to pid this means that setsid() will fail */
        init_tty(&cxt);