summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2017-08-16 14:03:06 +0200
committerKarel Zak2017-09-18 11:49:11 +0200
commitb55e712816f11626d4ae466742bbf0ff0b405310 (patch)
treeb7969f976207bdf072735100dcefded71f69b7ad /login-utils
parentsu: keep old sigactions in control struct (diff)
downloadkernel-qcow2-util-linux-b55e712816f11626d4ae466742bbf0ff0b405310.tar.gz
kernel-qcow2-util-linux-b55e712816f11626d4ae466742bbf0ff0b405310.tar.xz
kernel-qcow2-util-linux-b55e712816f11626d4ae466742bbf0ff0b405310.zip
su: make wait_for_child() usable in arbitrary situation
For example if called more than once; to keep PTY code simple and robust. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/su-common.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/login-utils/su-common.c b/login-utils/su-common.c
index 48812cbc1..f4e11dd2d 100644
--- a/login-utils/su-common.c
+++ b/login-utils/su-common.c
@@ -334,21 +334,23 @@ static void supam_open_session(struct su_context *su)
static int wait_for_child(struct su_context *su)
{
- pid_t pid;
+ pid_t pid = (pid_t) -1;;
int status = 0;
- DBG(SIG, ul_debug("waiting for child [%d]...", su->child));
- for (;;) {
- pid = waitpid(su->child, &status, WUNTRACED);
-
- if (pid != (pid_t) - 1 && WIFSTOPPED(status)) {
- kill(getpid(), SIGSTOP);
- /* once we get here, we must have resumed */
- kill(pid, SIGCONT);
- } else
- break;
+ if (su->child != (pid_t) -1) {
+ DBG(SIG, ul_debug("waiting for child [%d]...", su->child));
+ for (;;) {
+ pid = waitpid(su->child, &status, WUNTRACED);
+
+ if (pid != (pid_t) - 1 && WIFSTOPPED(status)) {
+ kill(getpid(), SIGSTOP);
+ /* once we get here, we must have resumed */
+ kill(pid, SIGCONT);
+ } else
+ break;
+ }
}
- if (pid != (pid_t) - 1) {
+ if (pid != (pid_t) -1) {
if (WIFSIGNALED(status)) {
fprintf(stderr, "%s%s\n",
strsignal(WTERMSIG(status)),