It is possible for WIFSTOPPED to be true even if waitpid() is not

given WUNTRACED if the child is ptraced.  Don't exit the waitpid()
loop if WIFSTOPPED is true, just in case.
This commit is contained in:
Todd C. Miller
2015-10-02 11:24:01 -06:00
parent 3f883a80a5
commit 5ad68edd65
3 changed files with 26 additions and 9 deletions

View File

@@ -591,9 +591,13 @@ send_mail(const char *fmt, ...)
break;
default:
/* Parent. */
do {
for (;;) {
rv = waitpid(pid, &status, 0);
} while (rv == -1 && errno == EINTR);
if (rv == -1 && errno != EINTR)
break;
if (rv != -1 && !WIFSTOPPED(status))
break;
}
return true; /* not debug */
}
@@ -732,9 +736,13 @@ send_mail(const char *fmt, ...)
fputs("\n\n", mail);
fclose(mail);
do {
rv = waitpid(pid, &status, 0);
} while (rv == -1 && errno == EINTR);
for (;;) {
rv = waitpid(pid, &status, 0);
if (rv == -1 && errno != EINTR)
break;
if (rv != -1 && !WIFSTOPPED(status))
break;
}
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
_exit(0);
}

View File

@@ -849,9 +849,13 @@ run_command(char *path, char **argv)
break; /* NOTREACHED */
}
do {
for (;;) {
rv = waitpid(pid, &status, 0);
} while (rv == -1 && errno == EINTR);
if (rv == -1 && errno != EINTR)
break;
if (rv != -1 && !WIFSTOPPED(status))
break;
}
if (rv != -1)
rv = WIFEXITED(status) ? WEXITSTATUS(status) : -1;

View File

@@ -300,8 +300,13 @@ sudo_askpass(const char *askpass, const char *prompt)
(void) sigaction(SIGPIPE, &saved_sa_pipe, NULL);
/* Wait for child to exit. */
while (waitpid(child, &status, 0) == -1 && errno == EINTR)
continue;
for (;;) {
pid_t rv = waitpid(child, &status, 0);
if (rv == -1 && errno != EINTR)
break;
if (rv != -1 && !WIFSTOPPED(status))
break;
}
if (pass == NULL)
errno = EINTR; /* make cancel button simulate ^C */