]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: check waitpid() return code
authorKarel Zak <kzak@redhat.com>
Mon, 6 Nov 2017 12:22:07 +0000 (13:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 6 Nov 2017 12:22:07 +0000 (13:22 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
libmount/src/context_umount.c

index b5b57e6bf1e74d22ef568dd4fcb800a1e1cd6334..79322c061c3a2e2e8423a6abbe91fb247f61e4fb 100644 (file)
@@ -639,12 +639,18 @@ static int exec_helper(struct libmnt_context *cxt)
        default:
        {
                int st;
-               waitpid(pid, &st, 0);
-               cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
 
-               DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d]",
-                                       cxt->helper, cxt->helper_status));
-               cxt->helper_exec_status = rc = 0;
+               if (waitpid(pid, &st, 0) == (pid_t) -1) {
+                       cxt->helper_status = -1;
+                       rc = -errno;
+               } else {
+                       cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
+                       cxt->helper_exec_status = rc = 0;
+               }
+               DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d, rc=%d%s]",
+                               cxt->helper,
+                               cxt->helper_status, rc,
+                               rc ? " waitpid failed" : ""));
                break;
        }
 
index e8fb37357c9ad5de0b29da8ca1e2d09534dbe987..f6b4ba737e03f50654adaa9a08873cba225a5ba7 100644 (file)
@@ -583,12 +583,18 @@ static int exec_helper(struct libmnt_context *cxt)
        default:
        {
                int st;
-               waitpid(pid, &st, 0);
-               cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
 
-               DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d]",
-                                       cxt->helper, cxt->helper_status));
-               cxt->helper_exec_status = rc = 0;
+               if (waitpid(pid, &st, 0) == (pid_t) -1) {
+                       cxt->helper_status = -1;
+                       rc = -errno;
+               } else {
+                       cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
+                       cxt->helper_exec_status = rc = 0;
+               }
+               DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d, rc=%d%s]",
+                               cxt->helper,
+                               cxt->helper_status, rc,
+                               rc ? " waitpid failed" : ""));
                break;
        }