From c34865b96df98c1f39eeca10134f01287aa235a3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 9 Nov 2016 14:19:22 +0100 Subject: [PATCH] su: use switch() to split after fork Signed-off-by: Karel Zak --- login-utils/su-common.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 -- 2.47.3