Add a --mount command to fstabinfo so it can mount specific mount points, as mount can get confused with binded mounts, bug #36.
This commit is contained in:
parent
0fa512c2b5
commit
52a3cc162b
@ -22,10 +22,12 @@ mount_svcdir()
|
|||||||
cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
|
cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \
|
||||||
"${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
|
"${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null
|
||||||
fi
|
fi
|
||||||
if ! mount -t tmpfs -o rw,noexec,nosuid none "${RC_SVCDIR}" 2>/dev/null; then
|
if ! fstabinfo --mount "${RC_SVCDIR}"; then
|
||||||
mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0
|
if ! mount -t tmpfs -o rw,noexec,nosuid none "${RC_SVCDIR}" 2>/dev/null; then
|
||||||
newfs -b 4096 -i 1024 -n /dev/md0
|
mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0
|
||||||
mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}"
|
newfs -b 4096 -i 1024 -n /dev/md0
|
||||||
|
mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
retval=$?
|
retval=$?
|
||||||
if ${dotmp}; then
|
if ${dotmp}; then
|
||||||
|
@ -44,9 +44,7 @@ mount_svcdir()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# If we have no entry in fstab for $RC_SVCDIR, provide our own
|
# If we have no entry in fstab for $RC_SVCDIR, provide our own
|
||||||
if fstabinfo --quiet "${RC_SVCDIR}"; then
|
if ! fstabinfo --mount "${RC_SVCDIR}"; then
|
||||||
mount -n "${RC_SVCDIR}"
|
|
||||||
else
|
|
||||||
mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}"
|
mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -91,9 +89,7 @@ if ${mountproc}; then
|
|||||||
procfs="proc"
|
procfs="proc"
|
||||||
[ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
[ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs"
|
||||||
ebegin "Mounting ${procfs} at /proc"
|
ebegin "Mounting ${procfs} at /proc"
|
||||||
if fstabinfo --quiet /proc; then
|
if ! fstabinfo --mount /proc; then
|
||||||
mount -n /proc
|
|
||||||
else
|
|
||||||
mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc
|
mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc
|
||||||
fi
|
fi
|
||||||
eend $?
|
eend $?
|
||||||
@ -116,9 +112,7 @@ then
|
|||||||
if [ -d /sys ]; then
|
if [ -d /sys ]; then
|
||||||
if ! mountinfo --quiet /sys; then
|
if ! mountinfo --quiet /sys; then
|
||||||
ebegin "Mounting sysfs at /sys"
|
ebegin "Mounting sysfs at /sys"
|
||||||
if fstabinfo --quiet /sys; then
|
if ! fstabinfo --mount /sys; then
|
||||||
mount -n /sys
|
|
||||||
else
|
|
||||||
mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys
|
mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys
|
||||||
fi
|
fi
|
||||||
eend $?
|
eend $?
|
||||||
@ -173,9 +167,7 @@ do
|
|||||||
|
|
||||||
if [ -d "$2" ]; then
|
if [ -d "$2" ]; then
|
||||||
ebegin "Mounting $1 at $2"
|
ebegin "Mounting $1 at $2"
|
||||||
if fstabinfo --quiet "$2"; then
|
if ! fstabinfo --mount "$2"; then
|
||||||
mount -n "$2"
|
|
||||||
else
|
|
||||||
mount -n -t "$1" -o noexec,nosuid"$4" "$5" "$2"
|
mount -n -t "$1" -o noexec,nosuid"$4" "$5" "$2"
|
||||||
fi
|
fi
|
||||||
eend $?
|
eend $?
|
||||||
|
@ -31,6 +31,7 @@ ALL_LINKS= ${BINLINKS} ${SBINLINKS} ${RC_BINLINKS} ${RC_SBINLINKS}
|
|||||||
CLEANFILES+= ${ALL_LINKS}
|
CLEANFILES+= ${ALL_LINKS}
|
||||||
|
|
||||||
LDFLAGS+= -L../librc -L../libeinfo
|
LDFLAGS+= -L../librc -L../libeinfo
|
||||||
|
LDFLAGS+= -Wl,--rpath=../librc -Wl,--rpath=../libeinfo
|
||||||
LDADD+= -lutil -lrc -leinfo
|
LDADD+= -lutil -lrc -leinfo
|
||||||
|
|
||||||
MK= ../../mk
|
MK= ../../mk
|
||||||
|
@ -29,11 +29,13 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
/* Yay for linux and it's non liking of POSIX functions.
|
/* Yay for linux and it's non liking of POSIX functions.
|
||||||
Okay, we could use getfsent but the man page says use getmntent instead
|
Okay, we could use getfsent but the man page says use getmntent instead
|
||||||
@ -41,6 +43,7 @@
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define HAVE_GETMNTENT
|
#define HAVE_GETMNTENT
|
||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
|
#define ENT mntent
|
||||||
#define START_ENT fp = setmntent ("/etc/fstab", "r");
|
#define START_ENT fp = setmntent ("/etc/fstab", "r");
|
||||||
#define GET_ENT getmntent (fp)
|
#define GET_ENT getmntent (fp)
|
||||||
#define GET_ENT_FILE(_name) getmntfile (_name)
|
#define GET_ENT_FILE(_name) getmntfile (_name)
|
||||||
@ -53,6 +56,7 @@
|
|||||||
#else
|
#else
|
||||||
#define HAVE_GETFSENT
|
#define HAVE_GETFSENT
|
||||||
#include <fstab.h>
|
#include <fstab.h>
|
||||||
|
#define ENT fstab
|
||||||
#define START_ENT
|
#define START_ENT
|
||||||
#define GET_ENT getfsent ()
|
#define GET_ENT getfsent ()
|
||||||
#define GET_ENT_FILE(_name) getfsfile (_name)
|
#define GET_ENT_FILE(_name) getfsfile (_name)
|
||||||
@ -88,10 +92,47 @@ static struct mntent *getmntfile (const char *file)
|
|||||||
|
|
||||||
extern const char *applet;
|
extern const char *applet;
|
||||||
|
|
||||||
|
static int do_mount (struct ENT *ent)
|
||||||
|
{
|
||||||
|
char *argv[8];
|
||||||
|
pid_t pid;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
argv[0] = (char *) "/sbin/mount";
|
||||||
|
argv[1] = (char *) "-o";
|
||||||
|
argv[2] = ENT_OPTS (*ent);
|
||||||
|
argv[3] = (char *) "-t";
|
||||||
|
argv[4] = ENT_TYPE (*ent);
|
||||||
|
argv[5] = ENT_BLOCKDEVICE (*ent);
|
||||||
|
argv[6] = ENT_FILE (*ent);
|
||||||
|
argv[7] = NULL;
|
||||||
|
switch (pid = vfork()) {
|
||||||
|
case -1:
|
||||||
|
eerrorx ("%s: vfork: %s", applet,
|
||||||
|
strerror (errno));
|
||||||
|
/* NOTREACHED */
|
||||||
|
case 0:
|
||||||
|
execv (argv[0], argv);
|
||||||
|
eerror ("%s: execv: %s", applet,
|
||||||
|
strerror (errno));
|
||||||
|
_exit(EXIT_FAILURE);
|
||||||
|
/* NOTREACHED */
|
||||||
|
default:
|
||||||
|
waitpid (pid, &status, 0);
|
||||||
|
if (WIFEXITED (status))
|
||||||
|
return (WEXITSTATUS(status));
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "_usage.h"
|
#include "_usage.h"
|
||||||
#define getoptstring "bmop:t:" getoptstring_COMMON
|
#define getoptstring "Mbmop:t:" getoptstring_COMMON
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
|
{ "mount", 0, NULL, 'M' },
|
||||||
{ "blockdevice", 0, NULL, 'b' },
|
{ "blockdevice", 0, NULL, 'b' },
|
||||||
|
{ "mountargs", 0, NULL, 'm' },
|
||||||
{ "options", 0, NULL, 'o' },
|
{ "options", 0, NULL, 'o' },
|
||||||
{ "passno", 1, NULL, 'p' },
|
{ "passno", 1, NULL, 'p' },
|
||||||
{ "fstype", 1, NULL, 't' },
|
{ "fstype", 1, NULL, 't' },
|
||||||
@ -99,6 +140,7 @@ static const struct option longopts[] = {
|
|||||||
};
|
};
|
||||||
static const char * const longopts_help[] = {
|
static const char * const longopts_help[] = {
|
||||||
"Extract the block device",
|
"Extract the block device",
|
||||||
|
"Mounts the filesytem from the mountpoint",
|
||||||
"Extract the options field",
|
"Extract the options field",
|
||||||
"Extract or query the pass number field",
|
"Extract or query the pass number field",
|
||||||
"List entries with matching file system type",
|
"List entries with matching file system type",
|
||||||
@ -107,18 +149,15 @@ static const char * const longopts_help[] = {
|
|||||||
#include "_usage.c"
|
#include "_usage.c"
|
||||||
|
|
||||||
#define OUTPUT_FILE (1 << 1)
|
#define OUTPUT_FILE (1 << 1)
|
||||||
|
#define OUTPUT_MOUNTARGS (1 << 2)
|
||||||
#define OUTPUT_OPTIONS (1 << 3)
|
#define OUTPUT_OPTIONS (1 << 3)
|
||||||
#define OUTPUT_PASSNO (1 << 4)
|
#define OUTPUT_PASSNO (1 << 4)
|
||||||
#define OUTPUT_BLOCKDEV (1 << 5)
|
#define OUTPUT_BLOCKDEV (1 << 5)
|
||||||
|
#define OUTPUT_MOUNT (1 << 6)
|
||||||
|
|
||||||
int fstabinfo (int argc, char **argv)
|
int fstabinfo (int argc, char **argv)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GETMNTENT
|
struct ENT *ent;
|
||||||
FILE *fp;
|
|
||||||
struct mntent *ent;
|
|
||||||
#else
|
|
||||||
struct fstab *ent;
|
|
||||||
#endif
|
|
||||||
int result = EXIT_SUCCESS;
|
int result = EXIT_SUCCESS;
|
||||||
char *token;
|
char *token;
|
||||||
int i;
|
int i;
|
||||||
@ -128,6 +167,10 @@ int fstabinfo (int argc, char **argv)
|
|||||||
char *file;
|
char *file;
|
||||||
bool filtered = false;
|
bool filtered = false;
|
||||||
|
|
||||||
|
#ifdef HAVE_GETMNTENT
|
||||||
|
FILE *fp;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Ensure that we are only quiet when explicitly told to be */
|
/* Ensure that we are only quiet when explicitly told to be */
|
||||||
unsetenv ("EINFO_QUIET");
|
unsetenv ("EINFO_QUIET");
|
||||||
|
|
||||||
@ -135,12 +178,18 @@ int fstabinfo (int argc, char **argv)
|
|||||||
longopts, (int *) 0)) != -1)
|
longopts, (int *) 0)) != -1)
|
||||||
{
|
{
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'M':
|
||||||
|
output = OUTPUT_MOUNT;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
output = OUTPUT_BLOCKDEV;
|
output = OUTPUT_BLOCKDEV;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
output = OUTPUT_OPTIONS;
|
output = OUTPUT_OPTIONS;
|
||||||
break;
|
break;
|
||||||
|
case 'm':
|
||||||
|
output = OUTPUT_MOUNTARGS;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
switch (optarg[0]) {
|
switch (optarg[0]) {
|
||||||
@ -213,6 +262,19 @@ int fstabinfo (int argc, char **argv)
|
|||||||
case OUTPUT_BLOCKDEV:
|
case OUTPUT_BLOCKDEV:
|
||||||
printf ("%s\n", ENT_BLOCKDEVICE (ent));
|
printf ("%s\n", ENT_BLOCKDEVICE (ent));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OUTPUT_MOUNT:
|
||||||
|
result += do_mount (ent);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OUTPUT_MOUNTARGS:
|
||||||
|
printf ("-o %s -t %s %s %s\n",
|
||||||
|
ENT_OPTS (ent),
|
||||||
|
ENT_TYPE (ent),
|
||||||
|
ENT_BLOCKDEVICE (ent),
|
||||||
|
file);
|
||||||
|
break;
|
||||||
|
|
||||||
case OUTPUT_OPTIONS:
|
case OUTPUT_OPTIONS:
|
||||||
printf ("%s\n", ENT_OPTS (ent));
|
printf ("%s\n", ENT_OPTS (ent));
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user