From: Karel Zak Date: Wed, 9 Nov 2016 13:19:22 +0000 (+0100) Subject: su: use switch() to split after fork X-Git-Tag: v2.31-rc1~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c34865b96df98c1f39eeca10134f01287aa235a3;p=thirdparty%2Futil-linux.git su: use switch() to split after fork Signed-off-by: Karel Zak --- diff --git a/login-utils/su-common.c b/login-utils/su-common.c index e004e22cf0..b153909c8c 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -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