mount: support -i; pass through -f and -n to helpers as necessary
function old new delta mount_it_now 298 345 +47 singlemount 776 772 -4 Signed-off-by: Colin Watson <cjwatson@ubuntu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b96159d663
commit
e2e4cc249d
@ -2900,6 +2900,9 @@
|
|||||||
IF_NOT_FEATURE_MTAB_SUPPORT( \
|
IF_NOT_FEATURE_MTAB_SUPPORT( \
|
||||||
"\n -f Dry run" \
|
"\n -f Dry run" \
|
||||||
) \
|
) \
|
||||||
|
) \
|
||||||
|
IF_FEATURE_MOUNT_HELPERS( \
|
||||||
|
"\n -i Don't run mount helper" \
|
||||||
) \
|
) \
|
||||||
IF_FEATURE_MTAB_SUPPORT( \
|
IF_FEATURE_MTAB_SUPPORT( \
|
||||||
"\n -n Don't update /etc/mtab" \
|
"\n -n Don't update /etc/mtab" \
|
||||||
|
@ -79,15 +79,21 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if ENABLE_FEATURE_MTAB_SUPPORT
|
#if ENABLE_FEATURE_MTAB_SUPPORT
|
||||||
#define useMtab (!(option_mask32 & OPT_n))
|
#define USE_MTAB (!(option_mask32 & OPT_n))
|
||||||
#else
|
#else
|
||||||
#define useMtab 0
|
#define USE_MTAB 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_MOUNT_FAKE
|
#if ENABLE_FEATURE_MOUNT_FAKE
|
||||||
#define fakeIt (option_mask32 & OPT_f)
|
#define FAKE_IT (option_mask32 & OPT_f)
|
||||||
#else
|
#else
|
||||||
#define fakeIt 0
|
#define FAKE_IT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_MOUNT_HELPERS
|
||||||
|
#define HELPERS_ALLOWED (!(option_mask32 & OPT_i))
|
||||||
|
#else
|
||||||
|
#define HELPERS_ALLOWED 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -360,7 +366,7 @@ static llist_t *get_block_backed_filesystems(void)
|
|||||||
"/proc/filesystems",
|
"/proc/filesystems",
|
||||||
};
|
};
|
||||||
char *fs, *buf;
|
char *fs, *buf;
|
||||||
llist_t *list = 0;
|
llist_t *list = NULL;
|
||||||
int i;
|
int i;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
@ -369,10 +375,11 @@ static llist_t *get_block_backed_filesystems(void)
|
|||||||
if (!f) continue;
|
if (!f) continue;
|
||||||
|
|
||||||
while ((buf = xmalloc_fgetline(f)) != NULL) {
|
while ((buf = xmalloc_fgetline(f)) != NULL) {
|
||||||
if (!strncmp(buf, "nodev", 5) && isspace(buf[5]))
|
if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5]))
|
||||||
continue;
|
continue;
|
||||||
fs = skip_whitespace(buf);
|
fs = skip_whitespace(buf);
|
||||||
if (*fs=='#' || *fs=='*' || !*fs) continue;
|
if (*fs == '#' || *fs == '*' || !*fs)
|
||||||
|
continue;
|
||||||
|
|
||||||
llist_add_to_end(&list, xstrdup(fs));
|
llist_add_to_end(&list, xstrdup(fs));
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -398,7 +405,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (fakeIt) {
|
if (FAKE_IT) {
|
||||||
if (verbose >= 2)
|
if (verbose >= 2)
|
||||||
bb_error_msg("would do mount('%s','%s','%s',0x%08lx,'%s')",
|
bb_error_msg("would do mount('%s','%s','%s',0x%08lx,'%s')",
|
||||||
mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
|
mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
|
||||||
@ -414,11 +421,15 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
|
|||||||
|
|
||||||
// If mount failed, try
|
// If mount failed, try
|
||||||
// helper program mount.<mnt_type>
|
// helper program mount.<mnt_type>
|
||||||
if (ENABLE_FEATURE_MOUNT_HELPERS && rc) {
|
if (HELPERS_ALLOWED && rc) {
|
||||||
char *args[6];
|
char *args[8];
|
||||||
int errno_save = errno;
|
int errno_save = errno;
|
||||||
args[0] = xasprintf("mount.%s", mp->mnt_type);
|
args[0] = xasprintf("mount.%s", mp->mnt_type);
|
||||||
rc = 1;
|
rc = 1;
|
||||||
|
if (FAKE_IT)
|
||||||
|
args[rc++] = (char *)"-f";
|
||||||
|
if (ENABLE_FEATURE_MTAB_SUPPORT && !USE_MTAB)
|
||||||
|
args[rc++] = (char *)"-n";
|
||||||
args[rc++] = mp->mnt_fsname;
|
args[rc++] = mp->mnt_fsname;
|
||||||
args[rc++] = mp->mnt_dir;
|
args[rc++] = mp->mnt_dir;
|
||||||
if (filteropts) {
|
if (filteropts) {
|
||||||
@ -449,7 +460,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
|
|||||||
// If the mount was successful, and we're maintaining an old-style
|
// If the mount was successful, and we're maintaining an old-style
|
||||||
// mtab file by hand, add the new entry to it now.
|
// mtab file by hand, add the new entry to it now.
|
||||||
mtab:
|
mtab:
|
||||||
if (useMtab && !rc && !(vfsflags & MS_REMOUNT)) {
|
if (USE_MTAB && !rc && !(vfsflags & MS_REMOUNT)) {
|
||||||
char *fsname;
|
char *fsname;
|
||||||
FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
|
FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
|
||||||
const char *option_str = mount_option_str;
|
const char *option_str = mount_option_str;
|
||||||
@ -1570,8 +1581,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
|
|||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
long vfsflags;
|
long vfsflags;
|
||||||
char *loopFile = 0, *filteropts = 0;
|
char *loopFile = NULL, *filteropts = NULL;
|
||||||
llist_t *fl = 0;
|
llist_t *fl = NULL;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
vfsflags = parse_mount_options(mp->mnt_opts, &filteropts);
|
vfsflags = parse_mount_options(mp->mnt_opts, &filteropts);
|
||||||
@ -1581,21 +1592,28 @@ static int singlemount(struct mntent *mp, int ignore_busy)
|
|||||||
mp->mnt_type = NULL;
|
mp->mnt_type = NULL;
|
||||||
|
|
||||||
// Might this be a virtual filesystem?
|
// Might this be a virtual filesystem?
|
||||||
if (ENABLE_FEATURE_MOUNT_HELPERS
|
if (ENABLE_FEATURE_MOUNT_HELPERS && strchr(mp->mnt_fsname, '#')) {
|
||||||
&& (strchr(mp->mnt_fsname, '#'))
|
char *args[35];
|
||||||
) {
|
char *s;
|
||||||
char *s, *p, *args[35];
|
int n;
|
||||||
int n = 0;
|
// fsname: "cmd#arg1#arg2..."
|
||||||
// FIXME: does it allow execution of arbitrary commands?!
|
// WARNING: allows execution of arbitrary commands!
|
||||||
// What args[0] can end up with?
|
// Try "mount 'sh#-c#sh' bogus_dir".
|
||||||
for (s = p = mp->mnt_fsname; *s && n < 35-3; ++s) {
|
// It is safe ONLY because non-root
|
||||||
if (s[0] == '#' && s[1] != '#') {
|
// cannot use two-argument mount command
|
||||||
*s = '\0';
|
// and using one-argument "mount 'sh#-c#sh'" doesn't work:
|
||||||
args[n++] = p;
|
// "mount: can't find sh#-c#sh in /etc/fstab"
|
||||||
p = s + 1;
|
// (if /etc/fstab has it, it's ok: root sets up /etc/fstab).
|
||||||
|
|
||||||
|
s = mp->mnt_fsname;
|
||||||
|
n = 0;
|
||||||
|
args[n++] = s;
|
||||||
|
while (*s && n < 35 - 2) {
|
||||||
|
if (*s++ == '#' && *s != '#') {
|
||||||
|
s[-1] = '\0';
|
||||||
|
args[n++] = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args[n++] = p;
|
|
||||||
args[n++] = mp->mnt_dir;
|
args[n++] = mp->mnt_dir;
|
||||||
args[n] = NULL;
|
args[n] = NULL;
|
||||||
rc = wait4pid(xspawn(args));
|
rc = wait4pid(xspawn(args));
|
||||||
@ -1704,7 +1722,8 @@ static int singlemount(struct mntent *mp, int ignore_busy)
|
|||||||
for (fl = fslist; fl; fl = fl->link) {
|
for (fl = fslist; fl; fl = fl->link) {
|
||||||
mp->mnt_type = fl->data;
|
mp->mnt_type = fl->data;
|
||||||
rc = mount_it_now(mp, vfsflags, filteropts);
|
rc = mount_it_now(mp, vfsflags, filteropts);
|
||||||
if (!rc) break;
|
if (!rc)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user