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>
This commit is contained in:
parent
a9b9d59d62
commit
7440665f9b
|
@ -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]",
|
||||
|
|
|
@ -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]",
|
||||
|
|
Loading…
Reference in New Issue