From: nilfsuser5678 <189666860+nilfsuser5678@users.noreply.github.com> Date: Fri, 29 Nov 2024 17:27:12 +0000 (+0000) Subject: libmount: exec mount helpers with posixly correct argument order X-Git-Tag: v2.42-start~129^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d680b72ac61644e4ba177e6569d8ca13580c248;p=thirdparty%2Futil-linux.git libmount: exec mount helpers with posixly correct argument order This improves compatibility with non-gnu userspaces. On systems where the libc provides posix getopt instead of gnu getopt, mount helpers which use getopt to parse arguments will not parse options which appear after non-option arguments. This patch ensures mount/unmount work as expected in this situation. mount: fix expected argument order for mount helpers in tests --- diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 62a7dface..af2fd7ed4 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -429,31 +429,33 @@ static int exec_helper(struct libmnt_context *cxt) type = mnt_fs_get_fstype(cxt->fs); args[i++] = cxt->helper; /* 1 */ - args[i++] = mnt_fs_get_srcpath(cxt->fs);/* 2 */ - args[i++] = mnt_fs_get_target(cxt->fs); /* 3 */ if (mnt_context_is_sloppy(cxt)) - args[i++] = "-s"; /* 4 */ + args[i++] = "-s"; /* 2 */ if (mnt_context_is_fake(cxt)) - args[i++] = "-f"; /* 5 */ + args[i++] = "-f"; /* 3 */ if (mnt_context_is_nomtab(cxt)) - args[i++] = "-n"; /* 6 */ + args[i++] = "-n"; /* 4 */ if (mnt_context_is_verbose(cxt)) - args[i++] = "-v"; /* 7 */ + args[i++] = "-v"; /* 5 */ if (o) { - args[i++] = "-o"; /* 8 */ - args[i++] = o; /* 9 */ + args[i++] = "-o"; /* 6 */ + args[i++] = o; /* 7 */ } if (type && strchr(type, '.') && !endswith(cxt->helper, type)) { - args[i++] = "-t"; /* 10 */ - args[i++] = type; /* 11 */ + args[i++] = "-t"; /* 8 */ + args[i++] = type; /* 9 */ } if (namespace) { - args[i++] = "-N"; /* 12 */ - args[i++] = namespace; /* 13 */ + args[i++] = "-N"; /* 10 */ + args[i++] = namespace; /* 11 */ } + + args[i++] = mnt_fs_get_srcpath(cxt->fs);/* 12 */ + args[i++] = mnt_fs_get_target(cxt->fs); /* 13 */ + args[i] = NULL; /* 14 */ for (i = 0; args[i]; i++) DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"", diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 64a1d884b..3ae77778f 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -711,29 +711,30 @@ static int exec_helper(struct libmnt_context *cxt) type = mnt_fs_get_fstype(cxt->fs); args[i++] = cxt->helper; /* 1 */ - args[i++] = mnt_fs_get_target(cxt->fs); /* 2 */ if (mnt_context_is_nomtab(cxt)) - args[i++] = "-n"; /* 3 */ + args[i++] = "-n"; /* 2 */ if (mnt_context_is_lazy(cxt)) - args[i++] = "-l"; /* 4 */ + args[i++] = "-l"; /* 3 */ if (mnt_context_is_force(cxt)) - args[i++] = "-f"; /* 5 */ + args[i++] = "-f"; /* 4 */ if (mnt_context_is_verbose(cxt)) - args[i++] = "-v"; /* 6 */ + args[i++] = "-v"; /* 5 */ if (mnt_context_is_rdonly_umount(cxt)) - args[i++] = "-r"; /* 7 */ + args[i++] = "-r"; /* 6 */ if (type && strchr(type, '.') && !endswith(cxt->helper, type)) { - args[i++] = "-t"; /* 8 */ - args[i++] = type; /* 9 */ + args[i++] = "-t"; /* 7 */ + args[i++] = type; /* 8 */ } if (namespace) { - args[i++] = "-N"; /* 10 */ - args[i++] = namespace; /* 11 */ + args[i++] = "-N"; /* 9 */ + args[i++] = namespace; /* 10 */ } + args[i++] = mnt_fs_get_target(cxt->fs); /* 11 */ + args[i] = NULL; /* 12 */ for (i = 0; args[i]; i++) DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"", diff --git a/tests/expected/mount/special-basic b/tests/expected/mount/special-basic index 99997d354..ae1c36858 100644 --- a/tests/expected/mount/special-basic +++ b/tests/expected/mount/special-basic @@ -1 +1 @@ -/sbin/mount.mytest called with "/foo /bar -o rw" +/sbin/mount.mytest called with "-o rw /foo /bar" diff --git a/tests/expected/mount/special-multi-types b/tests/expected/mount/special-multi-types index 99997d354..ae1c36858 100644 --- a/tests/expected/mount/special-multi-types +++ b/tests/expected/mount/special-multi-types @@ -1 +1 @@ -/sbin/mount.mytest called with "/foo /bar -o rw" +/sbin/mount.mytest called with "-o rw /foo /bar" diff --git a/tests/expected/mount/special-options b/tests/expected/mount/special-options index 820a74a9f..b7fdad97e 100644 --- a/tests/expected/mount/special-options +++ b/tests/expected/mount/special-options @@ -1 +1 @@ -/sbin/mount.mytest called with "/foo /bar -o rw,foo" +/sbin/mount.mytest called with "-o rw,foo /foo /bar" diff --git a/tests/expected/mount/special-user b/tests/expected/mount/special-user index 02c112e18..1c79c32ea 100644 --- a/tests/expected/mount/special-user +++ b/tests/expected/mount/special-user @@ -1 +1 @@ -/sbin/mount.mytest called with "/foo /bar -o rw,user,noexec,nosuid,nodev,abc" +/sbin/mount.mytest called with "-o rw,user,noexec,nosuid,nodev,abc /foo /bar" diff --git a/tests/expected/mount/special-username b/tests/expected/mount/special-username index c19256290..c8b94a727 100644 --- a/tests/expected/mount/special-username +++ b/tests/expected/mount/special-username @@ -1 +1 @@ -/sbin/mount.mytest called with "/foo /bar -o rw,user=name,abc" +/sbin/mount.mytest called with "-o rw,user=name,abc /foo /bar"