Steve Langasek has proposed merging lp:~vorlon/upstart/lp.980917 into
lp:upstart.
Requested reviews:
James Hunt (jamesodhunt)
Upstart Reviewers (upstart-reviewers)
For more details, see:
https://code.launchpad.net/~vorlon/upstart/lp.980917/+merge/117985
Build on top of lp:~jamesodhunt/upstart/bug-980917, addressing the case where
we would mount /dev unnecessarily (and possibly contrary to the system's
filesystem configuration)
--
https://code.launchpad.net/~vorlon/upstart/lp.980917/+merge/117985
Your team Upstart Reviewers is requested to review the proposed merge of
lp:~vorlon/upstart/lp.980917 into lp:upstart.
=== modified file 'init/main.c'
--- init/main.c 2011-12-15 16:26:34 +0000
+++ init/main.c 2012-08-02 20:06:29 +0000
@@ -28,6 +28,7 @@
#include <sys/ioctl.h>
#include <sys/reboot.h>
#include <sys/resource.h>
+#include <sys/mount.h>
#include <errno.h>
#include <stdio.h>
@@ -192,6 +193,9 @@
#ifndef DEBUG
if (use_session_bus == FALSE) {
+ struct stat statbuf;
+ int needs_devtmpfs = 0;
+
/* Check we're root */
if (getuid ()) {
nih_fatal (_("Need to be root"));
@@ -271,9 +275,10 @@
/* Mount the /proc and /sys filesystems, which are pretty much
* essential for any Linux system; not to mention used by
- * ourselves.
+ * ourselves. Also mount /dev/pts to allow CONSOLE_LOG
+ * to function if booted in an initramfs-less environment.
*/
- if (system_mount ("proc", "/proc") < 0) {
+ if (system_mount ("proc", "/proc", (MS_NODEV | MS_NOEXEC | MS_NOSUID)) < 0) {
NihError *err;
err = nih_error_get ();
@@ -282,7 +287,7 @@
nih_free (err);
}
- if (system_mount ("sysfs", "/sys") < 0) {
+ if (system_mount ("sysfs", "/sys", (MS_NODEV | MS_NOEXEC | MS_NOSUID)) < 0) {
NihError *err;
err = nih_error_get ();
@@ -290,6 +295,42 @@
err->message);
nih_free (err);
}
+ /* Check if /dev/ptmx and /dev/pts already exist; if they do,
+ * we should assume we don't need to mount /dev.
+ */
+ if (stat ("/dev/ptmx", &statbuf) < 0 || !S_ISCHR(statbuf.st_mode)
+ || major(statbuf.st_dev) != 5 || minor(statbuf.st_dev) != 2)
+ needs_devtmpfs = 1;
+ if (needs_devtmpfs
+ || stat("/dev/pts", &statbuf) < 0 || !S_ISDIR(statbuf.st_mode))
+ needs_devtmpfs = 1;
+
+ if (needs_devtmpfs) {
+ if (system_mount ("devtmpfs", "/dev", (MS_NOEXEC | MS_NOSUID)) < 0) {
+ NihError *err;
+
+ err = nih_error_get ();
+ nih_error ("%s: %s", _("Unable to mount /dev filesystem"),
+ err->message);
+ nih_free (err);
+ }
+
+ /* Required to exist before /dev/pts accessed */
+ if (mknod ("/dev/ptmx", makedev (5, 2), S_IFCHR) < 0 && errno != EEXIST)
+ nih_error ("Unable to create /dev/ptmx");
+
+ if (mkdir ("/dev/pts", 0755) < 0 && errno != EEXIST)
+ nih_error ("%s: %s", _("Cannot create directory"), "/dev/pts");
+ }
+
+ if (system_mount ("devpts", "/dev/pts", (MS_NOEXEC | MS_NOSUID)) < 0) {
+ NihError *err;
+
+ err = nih_error_get ();
+ nih_error ("%s: %s", _("Unable to mount /dev/pts filesystem"),
+ err->message);
+ nih_free (err);
+ }
} else {
nih_log_set_priority (NIH_LOG_DEBUG);
nih_debug ("Running with UID %d as PID %d (PPID %d)",
=== modified file 'init/system.c'
--- init/system.c 2011-12-09 14:07:11 +0000
+++ init/system.c 2012-08-02 20:06:29 +0000
@@ -164,9 +164,10 @@
/**
* system_mount:
* @type: filesystem type,
- * @dir: mountpoint.
+ * @dir: mountpoint,
+ * @flags: mount flags.
*
- * Mount the kernel filesystem @type at @dir, if not already mounted. This
+ * Mount the kernel filesystem @type at @dir with @flags, if not already mounted. This
* is used to ensure that the proc and sysfs filesystems are always
* available.
*
@@ -177,7 +178,8 @@
**/
int
system_mount (const char *type,
- const char *dir)
+ const char *dir,
+ unsigned long flags)
{
nih_local char *parent = NULL;
char * ptr;
@@ -206,8 +208,7 @@
return 0;
/* Mount the filesystem */
- if (mount ("none", dir, type,
- MS_NODEV | MS_NOEXEC | MS_NOSUID, NULL) < 0)
+ if (mount ("none", dir, type, flags, NULL) < 0)
nih_return_system_error (-1);
return 0;
=== modified file 'init/system.h'
--- init/system.h 2011-05-12 20:42:28 +0000
+++ init/system.h 2012-08-02 20:06:29 +0000
@@ -35,7 +35,8 @@
int system_setup_console (ConsoleType type, int reset)
__attribute__ ((warn_unused_result));
-int system_mount (const char *type, const char *dir)
+int system_mount (const char *type, const char *dir,
+ unsigned long flags)
__attribute__ ((warn_unused_result));
NIH_END_EXTERN
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel