umount: clean --recursive

- mark some options combinations mutually exclusive
 - reset libmount context before next umount (this is important!)

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-11-15 11:55:48 +01:00
parent 1f8590b56b
commit a8cc72dea0
1 changed files with 17 additions and 0 deletions

View File

@ -289,6 +289,11 @@ static int umount_one(struct libmnt_context *cxt, const char *spec)
if (!spec)
return MOUNT_EX_SOFTWARE;
/* We have to reset the context to make this function and the
* context re-usable more than once (for example in --recursive)
*/
mnt_reset_context(cxt);
if (mnt_context_set_target(cxt, spec))
err(MOUNT_EX_SYSERR, _("failed to set umount target"));
@ -343,6 +348,8 @@ static int umount_recursive(struct libmnt_context *cxt, const char *spec)
tb = mnt_new_table();
if (!tb)
err(MOUNT_EX_SYSERR, _("libmount table allocation failed"));
mnt_table_set_parser_errcb(tb, table_parser_errcb);
/*
* Don't use mtab here. The recursive umount depends on child-parent
* relationship defined by mountinfo file.
@ -397,6 +404,14 @@ int main(int argc, char **argv)
{ NULL, 0, 0, 0 }
};
static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
{ 'R','a' }, /* recursive,all */
{ 'O','R','t'}, /* options,recursive,types */
{ 'R','r' }, /* recursive,read-only */
{ 0 }
};
int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
sanitize_env();
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@ -418,6 +433,8 @@ int main(int argc, char **argv)
if (mnt_context_is_restricted(cxt) && !strchr("hdilVv", c))
exit_non_root(option_to_longopt(c, longopts));
err_exclusive_options(c, longopts, excl, excl_st);
switch(c) {
case 'a':
all = 1;