summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-11-18 20:54:28 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-11-19 14:36:12 +0100
commit01c94d1bc4d80b8ff23401462dfe4dca7148adb1 (patch)
tree5bb8f1f84ebd07569b65e8b0a9b4de9975d064ac /src
parent6642637ef37258686c34f5b630d5fcba99bea3ee (diff)
downloadsssd-01c94d1bc4d80b8ff23401462dfe4dca7148adb1.tar.gz
sssd-01c94d1bc4d80b8ff23401462dfe4dca7148adb1.tar.xz
sssd-01c94d1bc4d80b8ff23401462dfe4dca7148adb1.zip
SERVER: Check the return value of waitpid
We should at least print an error message and error out if waitpid() fails. https://fedorahosted.org/sssd/ticket/1651
Diffstat (limited to 'src')
-rw-r--r--src/util/server.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/util/server.c b/src/util/server.c
index 3dc9bcc0b..b3073fcd1 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -79,9 +79,9 @@ static void deamon_parent_sigterm(int sig)
void become_daemon(bool Fork)
{
- pid_t pid;
+ pid_t pid, cpid;
int status;
- int ret;
+ int ret, error;
if (Fork) {
pid = fork();
@@ -93,15 +93,31 @@ void become_daemon(bool Fork)
CatchSignal(SIGTERM, deamon_parent_sigterm);
/* or exit when sssd monitor is terminated */
- waitpid(pid, &status, 0);
-
- /* return error if we didn't exited normally */
- ret = 1;
-
- if (WIFEXITED(status)) {
- /* but return our exit code otherwise */
- ret = WEXITSTATUS(status);
- }
+ do {
+ errno = 0;
+ cpid = waitpid(pid, &status, 0);
+ if (cpid == 1) {
+ /* An error occurred while waiting */
+ error = errno;
+ if (error != EINTR) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Error [%d][%s] while waiting for child\n",
+ error, strerror(error)));
+ /* Forcibly kill this child */
+ kill(pid, SIGKILL);
+ ret = 1;
+ }
+ }
+
+ error = 0;
+ /* return error if we didn't exited normally */
+ ret = 1;
+
+ if (WIFEXITED(status)) {
+ /* but return our exit code otherwise */
+ ret = WEXITSTATUS(status);
+ }
+ } while (error == EINTR);
_exit(ret);
}