]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mountpoint: different exit status for errors and non-mountpoint situation
authorKarel Zak <kzak@redhat.com>
Thu, 11 Mar 2021 09:48:36 +0000 (10:48 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Mar 2021 09:48:36 +0000 (10:48 +0100)
Fixes: https://github.com/karelzak/util-linux/issues/1260
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/mountpoint.1
sys-utils/mountpoint.c

index a100721433b3f8ddf03696e12689f5df04f0bb88..c22577fd72b51f7beb110ffda6203ddffb5efb5a 100644 (file)
@@ -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.
index 052440bd4f43f49a1161f24aa73a330b405d0301..b9904f3cf681289924f2280770d19f46b88ff0ec 100644 (file)
@@ -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;
 }