From: Karel Zak Date: Thu, 11 Mar 2021 09:48:36 +0000 (+0100) Subject: mountpoint: different exit status for errors and non-mountpoint situation X-Git-Tag: v2.37-rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0ecd196414c03699cd8e8dd2c6f4fe533999837;p=thirdparty%2Futil-linux.git mountpoint: different exit status for errors and non-mountpoint situation Fixes: https://github.com/karelzak/util-linux/issues/1260 Signed-off-by: Karel Zak --- diff --git a/sys-utils/mountpoint.1 b/sys-utils/mountpoint.1 index a100721433..c22577fd72 100644 --- a/sys-utils/mountpoint.1 +++ b/sys-utils/mountpoint.1 @@ -42,7 +42,17 @@ Display version information and exit. .BR \-h , " \-\-help" Display help text and exit. .SH EXIT STATUS -Zero if the directory or file is a mountpoint, non-zero if not. +.B mountpoint +has the following exit status values: +.TP +.B 0 +success; the directory is a mountpoint, or device is block device on \fB\-\-devno\fR +.TP +.B 1 +failure; incorrect invocation, permissions or system error +.TP +.B 32 +failure; the directory is not a mountpoint, or device is not a block device on \fB\-\-devno\fR .SH ENVIRONMENT .IP LIBMOUNT_DEBUG=all enables libmount debug output. diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c index 052440bd4f..b9904f3cf6 100644 --- a/sys-utils/mountpoint.c +++ b/sys-utils/mountpoint.c @@ -40,6 +40,8 @@ #include "closestream.h" #include "pathnames.h" +#define MOUNTPOINT_EXIT_NOMNT 32 + struct mountpoint_control { char *path; dev_t dev; @@ -201,15 +203,17 @@ int main(int argc, char **argv) return EXIT_FAILURE; } if (ctl.dev_devno) - return print_devno(&ctl) ? EXIT_FAILURE : EXIT_SUCCESS; + return print_devno(&ctl) ? MOUNTPOINT_EXIT_NOMNT : EXIT_SUCCESS; + if ((ctl.nofollow && S_ISLNK(ctl.st.st_mode)) || dir_to_device(&ctl)) { if (!ctl.quiet) printf(_("%s is not a mountpoint\n"), ctl.path); - return EXIT_FAILURE; + return MOUNTPOINT_EXIT_NOMNT; } if (ctl.fs_devno) printf("%u:%u\n", major(ctl.dev), minor(ctl.dev)); else if (!ctl.quiet) printf(_("%s is a mountpoint\n"), ctl.path); + return EXIT_SUCCESS; }