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>
This commit is contained in:
Karel Zak 2017-08-16 14:03:06 +02:00
parent 665f36bed9
commit b55e712816
1 changed files with 13 additions and 11 deletions

View File

@ -334,9 +334,10 @@ static void supam_open_session(struct su_context *su)
static int wait_for_child(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; int status = 0;
if (su->child != (pid_t) -1) {
DBG(SIG, ul_debug("waiting for child [%d]...", su->child)); DBG(SIG, ul_debug("waiting for child [%d]...", su->child));
for (;;) { for (;;) {
pid = waitpid(su->child, &status, WUNTRACED); pid = waitpid(su->child, &status, WUNTRACED);
@ -348,7 +349,8 @@ static int wait_for_child(struct su_context *su)
} else } else
break; break;
} }
if (pid != (pid_t) - 1) { }
if (pid != (pid_t) -1) {
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
fprintf(stderr, "%s%s\n", fprintf(stderr, "%s%s\n",
strsignal(WTERMSIG(status)), strsignal(WTERMSIG(status)),