mount_util: derive add/remove-mount result from exit status

add_mount(), exec_umount() and remove_mount() returned waitpid()'s pid
on success rather than 0, contradicting the documented '0 or -1' contract
(harmless today only because every caller tests == -1). They also tested
the raw wait status, and read it uninitialized when waitpid() itself
failed.

Read the status only on the success path and decode it with
WIFEXITED()/WEXITSTATUS(), matching how check_is_mount() in fusermount.c
already does it, so these helpers return 0 or -1 as advertised.

Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
This commit is contained in:
Bernd Schubert
2026-06-14 00:15:19 +02:00
parent 6806ad4e1c
commit da15a2f6ed
+6 -10
View File
@@ -295,9 +295,8 @@ static int add_mount(const char *progname, const char *fsname,
if (res == -1)
fprintf(stderr, "%s: waitpid of %d: %s\n", progname,
pid, strerror(errno));
if (status != 0)
res = -1;
else
res = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : -1;
out_restore:
sigprocmask(SIG_SETMASK, &oldmask, NULL);
@@ -350,10 +349,8 @@ static int exec_umount(const char *progname, const char *rel_mnt, int lazy)
res = waitpid(pid, &status, 0);
if (res == -1)
fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
if (status != 0) {
res = -1;
}
else
res = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : -1;
out_restore:
sigprocmask(SIG_SETMASK, &oldmask, NULL);
@@ -407,9 +404,8 @@ static int remove_mount(const char *progname, const char *mnt)
res = waitpid(pid, &status, 0);
if (res == -1)
fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
if (status != 0)
res = -1;
else
res = (WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : -1;
out_restore:
sigprocmask(SIG_SETMASK, &oldmask, NULL);