From 305ef556d615816079d9970e1c4b28cfd2428740 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 17 Aug 2017 12:01:01 +0200 Subject: su: move parent signals setup to separate function Signed-off-by: Karel Zak --- login-utils/su-common.c | 59 +++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'login-utils/su-common.c') diff --git a/login-utils/su-common.c b/login-utils/su-common.c index f4e11dd2d..ff96a18c5 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -371,34 +371,9 @@ static int wait_for_child(struct su_context *su) return status; } -static void create_watching_parent(struct su_context *su) +static void parent_setup_signals(struct su_context *su) { sigset_t ourset; - int status; - - DBG(MISC, ul_debug("forking...")); - - switch ((int) (su->child = fork())) { - case -1: /* error */ - supam_cleanup(su, PAM_ABORT); - err(EXIT_FAILURE, _("cannot create child process")); - break; - - case 0: /* child */ - return; - - default: /* parent */ - DBG(MISC, ul_debug("child [pid=%d]", (int) su->child)); - break; - } - - - /* In the parent watch the child. */ - - /* su without pam support does not have a helper that keeps - sitting on any directory so let's go to /. */ - if (chdir("/") != 0) - warn(_("cannot change directory to %s"), "/"); /* * Signals setup @@ -464,6 +439,38 @@ static void create_watching_parent(struct su_context *su) caught_signal = true; } } +} + + +static void create_watching_parent(struct su_context *su) +{ + int status; + + DBG(MISC, ul_debug("forking...")); + + switch ((int) (su->child = fork())) { + case -1: /* error */ + supam_cleanup(su, PAM_ABORT); + err(EXIT_FAILURE, _("cannot create child process")); + break; + + case 0: /* child */ + return; + + default: /* parent */ + DBG(MISC, ul_debug("child [pid=%d]", (int) su->child)); + break; + } + + + /* In the parent watch the child. */ + + /* su without pam support does not have a helper that keeps + sitting on any directory so let's go to /. */ + if (chdir("/") != 0) + warn(_("cannot change directory to %s"), "/"); + + parent_setup_signals(su); /* * Wait for child -- cgit v1.2.3-55-g7522