On Mon, Nov 19, 2012 at 10:23:45AM +0100, Ondrej Kos wrote:
> On 11/19/2012 12:05 AM, Jakub Hrozek wrote:
> >We should at least print an error message and error out if waitpid()
> >fails.
> >
> >https://fedorahosted.org/sssd/ticket/1651
> >
> >
> >
> >_______________________________________________
> >sssd-devel mailing list
> >sssd-devel@lists.fedorahosted.org
> >https://lists.fedorahosted.org/mailman/listinfo/sssd-devel
> >
> 
> I noticed this warning while compiling:
> 
> src/util/server.c: In function 'become_daemon':
> src/util/server.c:123:18: warning: 'ret' may be used uninitialized
> in this function [-Wmaybe-uninitialized]
> 
> Could you please add the missing initialization? Ack on the patch though.
> 
> Ondra

Interesting, I don't see that warning..but gcc is right, in case the
waitpid call failed, we would return garbage and I would just
substitute one Coverity warning for another.

Thanks, a new patch is attached.
>From efd2cce0de480ccb7a6f585f4fb933c506241d2f Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Sun, 18 Nov 2012 20:54:28 +0100
Subject: [PATCH] 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
---
 src/util/server.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/util/server.c b/src/util/server.c
index 
3dc9bcc0becbafc440a8d8ccf1a1bf1bbaadc622..b3073fcd130ba67a8cc7b5d63b8d1a20e28807ac
 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);
+            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;
+                    }
+                }
 
-            /* return error if we didn't exited normally */
-            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);
-            }
+                if (WIFEXITED(status)) {
+                    /* but return our exit code otherwise */
+                    ret = WEXITSTATUS(status);
+                }
+            } while (error == EINTR);
 
             _exit(ret);
         }
-- 
1.8.0

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to