From e058a6c1a0ee3969a08550ed2ae0259d600ba4ab Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 27 Apr 2017 14:25:57 +0200 Subject: umount: use MNT_EX_* from libmount Signed-off-by: Karel Zak --- sys-utils/umount.c | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'sys-utils/umount.c') diff --git a/sys-utils/umount.c b/sys-utils/umount.c index 783d3d8ff..ed8fd4fe2 100644 --- a/sys-utils/umount.c +++ b/sys-utils/umount.c @@ -33,7 +33,6 @@ #include "c.h" #include "env.h" #include "optutils.h" -#include "exitcodes.h" #include "closestream.h" #include "pathnames.h" #include "canonicalize.h" @@ -66,7 +65,7 @@ static void __attribute__((__noreturn__)) print_version(void) fputs(*p++, stdout); } fputs(")\n", stdout); - exit(MOUNT_EX_SUCCESS); + exit(MNT_EX_SUCCESS); } static void __attribute__((__noreturn__)) usage(FILE *out) { @@ -102,7 +101,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out) fputs(USAGE_VERSION, out); fprintf(out, USAGE_MAN_TAIL("umount(8)")); - exit(out == stderr ? MOUNT_EX_USAGE : MOUNT_EX_SUCCESS); + exit(out == stderr ? MNT_EX_USAGE : MNT_EX_SUCCESS); } static void __attribute__((__noreturn__)) exit_non_root(const char *option) @@ -113,16 +112,16 @@ static void __attribute__((__noreturn__)) exit_non_root(const char *option) if (ruid == 0 && euid != 0) { /* user is root, but setuid to non-root */ if (option) - errx(MOUNT_EX_USAGE, + errx(MNT_EX_USAGE, _("only root can use \"--%s\" option " "(effective UID is %u)"), option, euid); - errx(MOUNT_EX_USAGE, _("only root can do that " + errx(MNT_EX_USAGE, _("only root can do that " "(effective UID is %u)"), euid); } if (option) - errx(MOUNT_EX_USAGE, _("only root can use \"--%s\" option"), option); - errx(MOUNT_EX_USAGE, _("only root can do that")); + errx(MNT_EX_USAGE, _("only root can use \"--%s\" option"), option); + errx(MNT_EX_USAGE, _("only root can do that")); } static void success_message(struct libmnt_context *cxt) @@ -169,7 +168,7 @@ static int umount_all(struct libmnt_context *cxt) itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) { warn(_("failed to initialize libmount iterator")); - return MOUNT_EX_SYSERR; + return MNT_EX_SYSERR; } while (mnt_context_next_umount(cxt, itr, &fs, &mntrc, &ignored) == 0) { @@ -182,7 +181,7 @@ static int umount_all(struct libmnt_context *cxt) } else { int xrc = mk_exit_code(cxt, mntrc); - if (xrc == MOUNT_EX_SUCCESS + if (xrc == MNT_EX_SUCCESS && mnt_context_is_verbose(cxt)) printf("%-25s: successfully unmounted\n", tgt); rc |= xrc; @@ -198,15 +197,15 @@ static int umount_one(struct libmnt_context *cxt, const char *spec) int rc; if (!spec) - return MOUNT_EX_SOFTWARE; + return MNT_EX_SOFTWARE; if (mnt_context_set_target(cxt, spec)) - err(MOUNT_EX_SYSERR, _("failed to set umount target")); + err(MNT_EX_SYSERR, _("failed to set umount target")); rc = mnt_context_umount(cxt); rc = mk_exit_code(cxt, rc); - if (rc == MOUNT_EX_SUCCESS && mnt_context_is_verbose(cxt)) + if (rc == MNT_EX_SUCCESS && mnt_context_is_verbose(cxt)) success_message(cxt); mnt_reset_context(cxt); @@ -217,7 +216,7 @@ static struct libmnt_table *new_mountinfo(struct libmnt_context *cxt) { struct libmnt_table *tb = mnt_new_table(); if (!tb) - err(MOUNT_EX_SYSERR, _("libmount table allocation failed")); + err(MNT_EX_SYSERR, _("libmount table allocation failed")); mnt_table_set_parser_errcb(tb, table_parser_errcb); mnt_table_set_cache(tb, mnt_context_get_cache(cxt)); @@ -241,7 +240,7 @@ static int umount_one_if_mounted(struct libmnt_context *cxt, const char *spec) rc = mnt_context_find_umount_fs(cxt, spec, &fs); if (rc == 1) { - rc = MOUNT_EX_SUCCESS; /* already unmounted */ + rc = MNT_EX_SUCCESS; /* already unmounted */ mnt_reset_context(cxt); } else if (rc < 0) { rc = mk_exit_code(cxt, rc); /* error */ @@ -260,7 +259,7 @@ static int umount_do_recurse(struct libmnt_context *cxt, int rc; if (!itr) - err(MOUNT_EX_SYSERR, _("libmount iterator allocation failed")); + err(MNT_EX_SYSERR, _("libmount iterator allocation failed")); /* umount all children */ for (;;) { @@ -268,13 +267,13 @@ static int umount_do_recurse(struct libmnt_context *cxt, if (rc < 0) { warnx(_("failed to get child fs of %s"), mnt_fs_get_target(fs)); - rc = MOUNT_EX_SOFTWARE; + rc = MNT_EX_SOFTWARE; goto done; } else if (rc == 1) break; /* no more children */ rc = umount_do_recurse(cxt, tb, child); - if (rc != MOUNT_EX_SUCCESS) + if (rc != MNT_EX_SUCCESS) goto done; } @@ -292,7 +291,7 @@ static int umount_recursive(struct libmnt_context *cxt, const char *spec) tb = new_mountinfo(cxt); if (!tb) - return MOUNT_EX_SOFTWARE; + return MNT_EX_SOFTWARE; /* it's always real mountpoint, don't assume that the target maybe a device */ mnt_context_disable_swapmatch(cxt, 1); @@ -301,7 +300,7 @@ static int umount_recursive(struct libmnt_context *cxt, const char *spec) if (fs) rc = umount_do_recurse(cxt, tb, fs); else { - rc = MOUNT_EX_USAGE; + rc = MNT_EX_USAGE; warnx(access(spec, F_OK) == 0 ? _("%s: not mounted") : _("%s: not found"), spec); @@ -324,7 +323,7 @@ static int umount_alltargets(struct libmnt_context *cxt, const char *spec, int r */ rc = mnt_context_find_umount_fs(cxt, spec, &fs); if (rc == 1) { - rc = MOUNT_EX_USAGE; + rc = MNT_EX_USAGE; warnx(access(spec, F_OK) == 0 ? _("%s: not mounted") : _("%s: not found"), spec); @@ -334,18 +333,18 @@ static int umount_alltargets(struct libmnt_context *cxt, const char *spec, int r return mk_exit_code(cxt, rc); /* error */ if (!mnt_fs_get_srcpath(fs) || !mnt_fs_get_devno(fs)) - errx(MOUNT_EX_USAGE, _("%s: failed to determine source " + errx(MNT_EX_USAGE, _("%s: failed to determine source " "(--all-targets is unsupported on systems with " "regular mtab file)."), spec); itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) - err(MOUNT_EX_SYSERR, _("libmount iterator allocation failed")); + err(MNT_EX_SYSERR, _("libmount iterator allocation failed")); /* get on @cxt independent mountinfo */ tb = new_mountinfo(cxt); if (!tb) { - rc = MOUNT_EX_SOFTWARE; + rc = MNT_EX_SOFTWARE; goto done; } @@ -365,7 +364,7 @@ static int umount_alltargets(struct libmnt_context *cxt, const char *spec, int r else rc = umount_one_if_mounted(cxt, mnt_fs_get_target(fs)); - if (rc != MOUNT_EX_SUCCESS) + if (rc != MNT_EX_SUCCESS) break; } @@ -389,7 +388,7 @@ static char *sanitize_path(const char *path) p = canonicalize_path_restricted(path); if (!p) - err(MOUNT_EX_USAGE, "%s", path); + err(MNT_EX_USAGE, "%s", path); return p; } @@ -442,7 +441,7 @@ int main(int argc, char **argv) mnt_init_debug(0); cxt = mnt_new_context(); if (!cxt) - err(MOUNT_EX_SYSERR, _("libmount context allocation failed")); + err(MNT_EX_SYSERR, _("libmount context allocation failed")); mnt_context_set_tables_errcb(cxt, table_parser_errcb); @@ -495,7 +494,7 @@ int main(int argc, char **argv) break; case 'O': if (mnt_context_set_options_pattern(cxt, optarg)) - err(MOUNT_EX_SYSERR, _("failed to set options pattern")); + err(MNT_EX_SYSERR, _("failed to set options pattern")); break; case 't': types = optarg; @@ -507,7 +506,7 @@ int main(int argc, char **argv) print_version(); break; default: - errtryhelp(MOUNT_EX_USAGE); + errtryhelp(MNT_EX_USAGE); } } -- cgit v1.2.3-55-g7522