diff --git a/sh.BSD/init.sh.in b/sh.BSD/init.sh.in index 8d08b0c4..dbff7368 100644 --- a/sh.BSD/init.sh.in +++ b/sh.BSD/init.sh.in @@ -22,10 +22,12 @@ mount_svcdir() cp -p "${RC_SVCDIR}"/deptree "${RC_SVCDIR}"/depconfig \ "${RC_SVCDIR}"/nettree "${RC_LIBDIR}"/tmp 2>/dev/null fi - if ! mount -t tmpfs -o rw,noexec,nosuid none "${RC_SVCDIR}" 2>/dev/null; then - mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0 - newfs -b 4096 -i 1024 -n /dev/md0 - mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}" + if ! fstabinfo --mount "${RC_SVCDIR}"; then + if ! mount -t tmpfs -o rw,noexec,nosuid none "${RC_SVCDIR}" 2>/dev/null; then + mdconfig -a -t malloc -s "${rc_svcsize:-1024}"k -u 0 + newfs -b 4096 -i 1024 -n /dev/md0 + mount -o rw,noexec,nosuid /dev/md0 "${RC_SVCDIR}" + fi fi retval=$? if ${dotmp}; then diff --git a/sh.Linux/init.sh.in b/sh.Linux/init.sh.in index 190f8f17..ac1ae0a6 100644 --- a/sh.Linux/init.sh.in +++ b/sh.Linux/init.sh.in @@ -44,9 +44,7 @@ mount_svcdir() fi # If we have no entry in fstab for $RC_SVCDIR, provide our own - if fstabinfo --quiet "${RC_SVCDIR}"; then - mount -n "${RC_SVCDIR}" - else + if ! fstabinfo --mount "${RC_SVCDIR}"; then mount -n -t "${fs}" ${fsopts} "${devdir}" "${RC_SVCDIR}" fi @@ -91,9 +89,7 @@ if ${mountproc}; then procfs="proc" [ "${RC_UNAME}" = "GNU/kFreeBSD" ] && proc="linprocfs" ebegin "Mounting ${procfs} at /proc" - if fstabinfo --quiet /proc; then - mount -n /proc - else + if ! fstabinfo --mount /proc; then mount -n -t "${procfs}" -o noexec,nosuid,nodev proc /proc fi eend $? @@ -116,9 +112,7 @@ then if [ -d /sys ]; then if ! mountinfo --quiet /sys; then ebegin "Mounting sysfs at /sys" - if fstabinfo --quiet /sys; then - mount -n /sys - else + if ! fstabinfo --mount /sys; then mount -n -t sysfs -o noexec,nosuid,nodev sysfs /sys fi eend $? @@ -173,9 +167,7 @@ do if [ -d "$2" ]; then ebegin "Mounting $1 at $2" - if fstabinfo --quiet "$2"; then - mount -n "$2" - else + if ! fstabinfo --mount "$2"; then mount -n -t "$1" -o noexec,nosuid"$4" "$5" "$2" fi eend $? diff --git a/src/rc/Makefile b/src/rc/Makefile index 6e0ca8d3..7f179fcc 100644 --- a/src/rc/Makefile +++ b/src/rc/Makefile @@ -31,6 +31,7 @@ ALL_LINKS= ${BINLINKS} ${SBINLINKS} ${RC_BINLINKS} ${RC_SBINLINKS} CLEANFILES+= ${ALL_LINKS} LDFLAGS+= -L../librc -L../libeinfo +LDFLAGS+= -Wl,--rpath=../librc -Wl,--rpath=../libeinfo LDADD+= -lutil -lrc -leinfo MK= ../../mk diff --git a/src/rc/fstabinfo.c b/src/rc/fstabinfo.c index 4c60044b..fa5fc201 100644 --- a/src/rc/fstabinfo.c +++ b/src/rc/fstabinfo.c @@ -29,11 +29,13 @@ * SUCH DAMAGE. */ +#include #include #include #include #include #include +#include /* Yay for linux and it's non liking of POSIX functions. Okay, we could use getfsent but the man page says use getmntent instead @@ -41,6 +43,7 @@ #ifdef __linux__ #define HAVE_GETMNTENT #include +#define ENT mntent #define START_ENT fp = setmntent ("/etc/fstab", "r"); #define GET_ENT getmntent (fp) #define GET_ENT_FILE(_name) getmntfile (_name) @@ -53,6 +56,7 @@ #else #define HAVE_GETFSENT #include +#define ENT fstab #define START_ENT #define GET_ENT getfsent () #define GET_ENT_FILE(_name) getfsfile (_name) @@ -88,10 +92,47 @@ static struct mntent *getmntfile (const char *file) 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" -#define getoptstring "bmop:t:" getoptstring_COMMON +#define getoptstring "Mbmop:t:" getoptstring_COMMON static const struct option longopts[] = { + { "mount", 0, NULL, 'M' }, { "blockdevice", 0, NULL, 'b' }, + { "mountargs", 0, NULL, 'm' }, { "options", 0, NULL, 'o' }, { "passno", 1, NULL, 'p' }, { "fstype", 1, NULL, 't' }, @@ -99,6 +140,7 @@ static const struct option longopts[] = { }; static const char * const longopts_help[] = { "Extract the block device", + "Mounts the filesytem from the mountpoint", "Extract the options field", "Extract or query the pass number field", "List entries with matching file system type", @@ -107,18 +149,15 @@ static const char * const longopts_help[] = { #include "_usage.c" #define OUTPUT_FILE (1 << 1) +#define OUTPUT_MOUNTARGS (1 << 2) #define OUTPUT_OPTIONS (1 << 3) #define OUTPUT_PASSNO (1 << 4) #define OUTPUT_BLOCKDEV (1 << 5) +#define OUTPUT_MOUNT (1 << 6) int fstabinfo (int argc, char **argv) { -#ifdef HAVE_GETMNTENT - FILE *fp; - struct mntent *ent; -#else - struct fstab *ent; -#endif + struct ENT *ent; int result = EXIT_SUCCESS; char *token; int i; @@ -128,6 +167,10 @@ int fstabinfo (int argc, char **argv) char *file; bool filtered = false; +#ifdef HAVE_GETMNTENT + FILE *fp; +#endif + /* Ensure that we are only quiet when explicitly told to be */ unsetenv ("EINFO_QUIET"); @@ -135,12 +178,18 @@ int fstabinfo (int argc, char **argv) longopts, (int *) 0)) != -1) { switch (opt) { + case 'M': + output = OUTPUT_MOUNT; + break; case 'b': output = OUTPUT_BLOCKDEV; break; case 'o': output = OUTPUT_OPTIONS; break; + case 'm': + output = OUTPUT_MOUNTARGS; + break; case 'p': switch (optarg[0]) { @@ -213,6 +262,19 @@ int fstabinfo (int argc, char **argv) case OUTPUT_BLOCKDEV: printf ("%s\n", ENT_BLOCKDEVICE (ent)); 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: printf ("%s\n", ENT_OPTS (ent)); break;