From: Vratislav Podzimek Date: Mon, 6 Nov 2017 10:28:17 +0000 (+0100) Subject: libmount: Use waitpid() when waiting for mount helper child process X-Git-Tag: v2.32-rc1~227 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7440665f9bf6b7fe6e14b20ec0e825023e159a6f;p=thirdparty%2Futil-linux.git 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 --- diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index c6a794d7e2..b5b57e6bf1 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]", diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index a8124629f3..e8fb37357c 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -521,6 +521,7 @@ eperm: static int exec_helper(struct libmnt_context *cxt) { int rc; + pid_t pid; assert(cxt); assert(cxt->fs); @@ -536,7 +537,8 @@ static int exec_helper(struct libmnt_context *cxt) DBG_FLUSH; - switch (fork()) { + pid = fork(); + switch (pid) { case 0: { const char *args[10], *type; @@ -581,7 +583,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]",