mountpoint: different exit status for errors and non-mountpoint situation

Fixes: https://github.com/karelzak/util-linux/issues/1260
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-03-11 10:48:36 +01:00
parent 6b6dbcbae6
commit e0ecd19641
2 changed files with 17 additions and 3 deletions

View 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.

View 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;
}