]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: use errexec()
authorKarel Zak <kzak@redhat.com>
Thu, 1 Feb 2018 14:37:22 +0000 (15:37 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 1 Feb 2018 14:37:22 +0000 (15:37 +0100)
The new macro is fully compatible with original (coreutils) code.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index 32cdd1954ed7ebb6c697b00dfd8ff9c3a1a96997..afd75a1f1a9a0ec29cc89c71f6c0f4bea4038bf6 100644 (file)
@@ -103,11 +103,6 @@ UL_DEBUG_DEFINE_MASKNAMES(su) = UL_DEBUG_EMPTY_MASKNAMES;
 extern char **environ;
 #endif
 
-enum {
-       EXIT_CANNOT_INVOKE = 126,
-       EXIT_ENOENT = 127
-};
-
 enum {
        SIGTERM_IDX = 0,
        SIGINT_IDX,
@@ -1041,7 +1036,6 @@ static void run_shell(
        size_t n_args = 1 + su->fast_startup + 2 * ! !command + n_additional_args + 1;
        const char **args = xcalloc(n_args, sizeof *args);
        size_t argno = 1;
-       int rc;
 
        DBG(MISC, ul_debug("starting shell [shell=%s, command=\"%s\"%s%s]",
                                shell, command,
@@ -1070,9 +1064,7 @@ static void run_shell(
        memcpy(args + argno, additional_args, n_additional_args * sizeof *args);
        args[argno + n_additional_args] = NULL;
        execv(shell, (char **)args);
-
-       rc = errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE;
-       err(rc, _("failed to execute %s"), shell);
+       errexec(shell);
 }
 
 /* Return true if SHELL is a restricted shell (one not returned by