]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
su: use switch() to split after fork
authorKarel Zak <kzak@redhat.com>
Wed, 9 Nov 2016 13:19:22 +0000 (14:19 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 18 Sep 2017 09:48:56 +0000 (11:48 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/su-common.c

index e004e22cf0ecc028a4e748ed6921ebc2dd35c514..b153909c8c5cc68c85b59e42f963fbd6aec1f2bb 100644 (file)
@@ -288,18 +288,22 @@ static void create_watching_parent(struct su_context *su)
        struct sigaction oldact[3];
        int status = 0;
 
-       memset(oldact, 0, sizeof(oldact));
-
-       child = fork();
-       if (child == (pid_t) - 1) {
+       switch ((int) (child = fork())) {
+       case -1: /* error */
                supam_cleanup(su, PAM_ABORT);
                err(EXIT_FAILURE, _("cannot create child process"));
-       }
+               break;
 
-       /* the child proceeds to run the shell */
-       if (child == 0)
+       case 0: /* child */
                return;
 
+       default: /* parent */
+               break;
+       }
+
+       memset(oldact, 0, sizeof(oldact));
+
+
        /* In the parent watch the child.  */
 
        /* su without pam support does not have a helper that keeps