8000 findmnt: fix -k option parsing regression · util-linux/util-linux@9d4df79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d4df79

Browse files
committed
findmnt: fix -k option parsing regression
It's a really bad idea to change any existing short option to support optional arguments. Fixes: #3512 References: 841d15e Signed-off-by: Karel Zak <kzak@redhat.com> (cherry picked from commit 0ecaef6)
1 parent a3cff26 commit 9d4df79

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

misc-utils/findmnt.8.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Use JSON output format.
8787
*-k*, *--kernel*[_=method_]::
8888
Reads information about filesystems from the kernel. This is the default output. The format is tree-like and only includes mount options managed by the kernel (see also *--mtab*).
8989
+
90-
The optional argument _method_ can be either:
90+
The optional argument _method_ is supported only for the long variant (--kernel). The short variant (-k) defaults to the mountinfo method for backward compatibility. The supported methods can be either:
9191
+
9292
* *mountinfo* - this is the default method and it reads data from the _/proc/self/mountinfo_ file.
9393
+

misc-utils/findmnt.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,8 @@ static void __attribute__((__noreturn__)) usage(void)
15311531
fputs(_(" -F, --tab-file <path> alternative file for -s, -m or -k options\n"), out);
15321532
fputs(_(" -m, --mtab search in table of mounted filesystems\n"
15331533
" (includes user space mount options)\n"), out);
1534-
fputs(_(" -k, --kernel[=<method>] search in kernel mount table (default)\n"
1534+
fputs(_(" -k alias to '--kernel mountinfo'\n"), out);
1535+
fputs(_(" --kernel[=<method>] search in kernel mount table (default)\n"
15351536
" <method> is mountinfo or listmount\n"), out);
15361537
fputs(_(" -N, --task <tid> use alternative namespace (/proc/<tid>/mountinfo file)\n"), out);
15371538
fputs(_(" -p, --poll[=<list>] monitor changes in table of mounted filesystems\n"), out);
@@ -1764,7 +1765,8 @@ int main(int argc, char *argv[])
17641765
FINDMNT_OPT_SHADOWED,
17651766
FINDMNT_OPT_HYPERLINK,
17661767
FINDMNT_OPT_ID,
1767-
FINDMNT_OPT_UNIQ_ID
1768+
FINDMNT_OPT_UNIQ_ID,
1769+
FINDMNT_OPT_KERNEL
17681770
};
17691771

17701772
static const struct option longopts[] = {
@@ -1781,7 +1783,7 @@ int main(int argc, char *argv[])
17811783
{ "help", no_argument, NULL, 'h' },
17821784
{ "invert", no_argument, NULL, 'i' },
17831785
{ "json", no_argument, NULL, 'J' },
1784-
{ "kernel", optional_argument, NULL, 'k' },
1786+
{ "kernel", optional_argument, NULL, FINDMNT_OPT_KERNEL },
17851787
{ "list", no_argument, NULL, 'l' },
17861788
{ "mountpoint", required_argument, NULL, 'M' },
17871789
{ "mtab", no_argument, NULL, 'm' },
@@ -1844,7 +1846,7 @@ int main(int argc, char *argv[])
18441846
findmnt.flags |= FL_TREE;
18451847

18461848
while ((c = getopt_long(argc, argv,
1847-
"AabCcDd:ehIiJfF:o:O:p::PQ:k::lmM:nN:rst:uvRS:T:Uw:VxyH",
1849+
"AabCcDd:ehIiJfF:o:O:p::PQ:klmM:nN:rst:uvRS:T:Uw:VxyH",
18481850
longopts, NULL)) != -1) {
18491851

18501852
err_exclusive_options(c, longopts, excl, excl_st);
@@ -1941,6 +1943,9 @@ int main(int argc, char *argv[])
19411943
findmnt.flags &= ~FL_TREE;
19421944
break;
19431945
case 'k':
1946+
tabtype = TABTYPE_KERNEL_MOUNTINFO;
1947+
break;
1948+
case FINDMNT_OPT_KERNEL:
19441949
if (optarg) {
19451950
if (strcmp(optarg, "mountinfo") == 0)
19461951
tabtype = TABTYPE_KERNEL_MOUNTINFO;

0 commit comments

Comments
 (0)
0