summaryrefslogtreecommitdiffstats
path: root/login-utils/su-common.c
diff options
context:
space:
mode:
authorKarel Zak2017-08-17 12:01:01 +0200
committerKarel Zak2017-09-18 11:49:11 +0200
commit305ef556d615816079d9970e1c4b28cfd2428740 (patch)
tree635ca7366ecb5967ba3d7a46a0949c0f227548a8 /login-utils/su-common.c
parentsu: make wait_for_child() usable in arbitrary situation (diff)
downloadkernel-qcow2-util-linux-305ef556d615816079d9970e1c4b28cfd2428740.tar.gz
kernel-qcow2-util-linux-305ef556d615816079d9970e1c4b28cfd2428740.tar.xz
kernel-qcow2-util-linux-305ef556d615816079d9970e1c4b28cfd2428740.zip
su: move parent signals setup to separate function
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/su-common.c')
-rw-r--r--login-utils/su-common.c59
1 files changed, 33 insertions, 26 deletions
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