#include "optutils.h"
static int quiet;
+static int graceful;
static struct ul_env_list *envs_removed;
static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)),
fputs(_(" -v, --verbose say what is being done\n"), out);
fputs(_(" -q, --quiet suppress 'not mounted' error messages\n"), out);
fputs(_(" -N, --namespace <ns> perform umount in another namespace\n"), out);
+ fputs(_(" -g, --graceful don't return an error when the mountpoint has already\n"
+ " been unmounted or the directory does not exist\n"), out);
fputs(USAGE_SEPARATOR, out);
fprintf(out, USAGE_HELP_OPTIONS(25));
int rc;
rc = mnt_context_get_excode(cxt, api_rc, buf, sizeof(buf));
+ /* exit succesfully even if the filesystem has already been unmounted or does not exist */
+ if (graceful && rc == MNT_EX_FAIL && mnt_context_syscall_called(cxt)
+ && (mnt_context_get_syscall_errno(cxt) == EINVAL
+ || mnt_context_get_syscall_errno(cxt) == ENOENT))
+ return MNT_EX_SUCCESS;
/* suppress "not mounted" error message */
if (quiet) {
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' },
{ "namespace", required_argument, NULL, 'N' },
+ { "graceful", no_argument, NULL, 'g' },
{ NULL, 0, NULL, 0 }
};
mnt_context_set_tables_errcb(cxt, table_parser_errcb);
- while ((c = getopt_long(argc, argv, "aAcdfhilnqRrO:t:vVN:",
+ while ((c = getopt_long(argc, argv, "aAcdfghilnqRrO:t:vVN:",
longopts, NULL)) != -1) {
err(MNT_EX_SYSERR, _("failed to set target namespace to %s"), pid ? path : optarg);
break;
}
-
+ case 'g':
+ graceful = 1;
+ break;
case 'h':
mnt_free_context(cxt);
usage();