summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac13
-rw-r--r--lib/consoles.c73
2 files changed, 86 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 3be3715e5..c0783056c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1296,6 +1296,19 @@ if test "x$enable_use_tty_group" = xyes; then
AC_DEFINE(USE_TTY_GROUP, 1, [Should wall and write be installed setgid tty?])
fi
+
+AC_ARG_ENABLE([sulogin-emergency-mount],
+ AS_HELP_STRING([--disable-sulogin-emergency-mount],
+ [do not use emergency mount of /dev and /proc for sulogin]),
+ [], enable_sulogin_emergency_mount=yes
+)
+
+if test "x$enable_sulogin_emergency_mount" = xyes; then
+ AC_DEFINE(USE_SULOGIN_EMERGENCY_MOUNT, 1,
+ [Should sulogin use a emergency mount of /dev and /proc?])
+fi
+
+
AC_ARG_ENABLE([makeinstall-chown],
AS_HELP_STRING([--disable-makeinstall-chown], [do not do chown-like operations during "make install"]),
[], enable_makeinstall_chown=yes
diff --git a/lib/consoles.c b/lib/consoles.c
index 21c5a249a..7175a0882 100644
--- a/lib/consoles.c
+++ b/lib/consoles.c
@@ -39,6 +39,16 @@
#include <dirent.h>
#include <unistd.h>
+#ifdef USE_SULOGIN_EMERGENCY_MOUNT
+# include <sys/mount.h>
+# include <linux/fs.h>
+# include <linux/magic.h>
+# include <linux/major.h>
+# ifndef MNT_DETACH
+# define MNT_DETACH 2
+# endif
+#endif
+
#include "c.h"
#include "canonicalize.h"
#include "consoles.h"
@@ -77,6 +87,64 @@ dbgprint(const char *mesg, ...)
fputc('\n', stderr);
}
+#ifdef USE_SULOGIN_EMERGENCY_MOUNT
+/*
+ * Make C library standard calls such like ttyname(3) work
+ * even if the system does not show any of the standard
+ * directories.
+ */
+
+static uint32_t emergency_flags;
+# define MNT_PROCFS 0x0001
+# define MNT_DEVTMPFS 0x0002
+
+static __attribute__((__destructor__))
+void emergency_do_umounts(void)
+{
+ if (emergency_flags & MNT_DEVTMPFS)
+ umount2("/dev", MNT_DETACH);
+ if (emergency_flags & MNT_PROCFS)
+ umount2("/proc", MNT_DETACH);
+}
+
+static __attribute__((__constructor__))
+void emergency_do_mounts(void)
+{
+ struct stat rt, xt;
+
+ if (emergency_flags) {
+ emergency_flags = 0;
+ return;
+ }
+
+ if (stat("/", &rt) != 0) {
+ warn("can not get file status of root file system\n");
+ return;
+ }
+
+ if (stat("/proc", &xt) == 0
+ && rt.st_dev == xt.st_dev
+ && mount("proc", "/proc", "proc", MS_RELATIME, NULL) == 0)
+ emergency_flags |= MNT_PROCFS;
+
+ if (stat("/dev", &xt) == 0
+ && rt.st_dev == xt.st_dev
+ && mount("devtmpfs", "/dev", "devtmpfs",
+ MS_RELATIME, "mode=0755,nr_inodes=0") == 0) {
+
+ emergency_flags |= MNT_DEVTMPFS;
+ mknod("/dev/console", S_IFCHR|S_IRUSR|S_IWUSR,
+ makedev(TTYAUX_MAJOR, 1));
+
+ if (symlink("/proc/self/fd", "/dev/fd") == 0) {
+ ignore_result( symlink("fd/0", "/dev/stdin") );
+ ignore_result( symlink("fd/1", "/dev/stdout") );
+ ignore_result( symlink("fd/2", "/dev/stderr") );
+ }
+ }
+}
+#endif /* USE_SULOGIN_EMERGENCY_MOUNT */
+
/*
* Read and allocate one line from file,
* the caller has to free the result
@@ -182,6 +250,11 @@ char* scandev(DIR *dir, dev_t comparedev)
continue;
if ((size_t)snprintf(path, sizeof(path), "/dev/%s", dent->d_name) >= sizeof(path))
continue;
+#ifdef USE_SULOGIN_EMERGENCY_MOUNT
+ if (emergency_flags & MNT_DEVTMPFS)
+ mknod(path, S_IFCHR|S_IRUSR|S_IWUSR, comparedev);
+#endif
+
name = canonicalize_path(path);
break;
}