summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_mount.c
diff options
context:
space:
mode:
authorVratislav Podzimek2017-11-06 11:28:17 +0100
committerKarel Zak2017-11-06 13:05:04 +0100
commit7440665f9bf6b7fe6e14b20ec0e825023e159a6f (patch)
tree64efd0e1ea8995ee7f0a7bfe6a3e8194d8b24f66 /libmount/src/context_mount.c
parentlscpu: Treat read failure on Xen Hypervisor properties as non-fatal (diff)
downloadkernel-qcow2-util-linux-7440665f9bf6b7fe6e14b20ec0e825023e159a6f.tar.gz
kernel-qcow2-util-linux-7440665f9bf6b7fe6e14b20ec0e825023e159a6f.tar.xz
kernel-qcow2-util-linux-7440665f9bf6b7fe6e14b20ec0e825023e159a6f.zip
libmount: Use waitpid() when waiting for mount helper child process
Using wait() in a library may be problematic as it may reap some totally unrelated child process instead of the just forked one. That can result in the library call doing weird things and returning bad return values, but also in a breakage of an arbitrary other thing in the program using the library. [[kzak@redhat.com: - use waitpid() for umount too - keep the current codding style] Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context_mount.c')
-rw-r--r--libmount/src/context_mount.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
index c6a794d7e..b5b57e6bf 100644
--- a/libmount/src/context_mount.c
+++ b/libmount/src/context_mount.c
@@ -576,6 +576,7 @@ static int exec_helper(struct libmnt_context *cxt)
{
char *o = NULL;
int rc;
+ pid_t pid;
assert(cxt);
assert(cxt->fs);
@@ -590,7 +591,8 @@ static int exec_helper(struct libmnt_context *cxt)
DBG_FLUSH;
- switch (fork()) {
+ pid = fork();
+ switch (pid) {
case 0:
{
const char *args[12], *type;
@@ -637,7 +639,7 @@ static int exec_helper(struct libmnt_context *cxt)
default:
{
int st;
- wait(&st);
+ waitpid(pid, &st, 0);
cxt->helper_status = WIFEXITED(st) ? WEXITSTATUS(st) : -1;
DBG(CXT, ul_debugobj(cxt, "%s executed [status=%d]",