From fb7e447486c7f659ab00df33185cbff8be4be18e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 6 Nov 2017 13:22:07 +0100 Subject: [PATCH] libmount: check waitpid() return code Signed-off-by: Karel Zak --- libmount/src/context_mount.c | 16 +++++++++++----- libmount/src/context_umount.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index b5b57e6bf1..79322c061c 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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; } diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index e8fb37357c..f6b4ba737e 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -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; } -- 2.47.3