chiark / gitweb /
util: add extra safety check to in_initrd()
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Jul 2012 16:46:26 +0000 (18:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Jul 2012 16:46:26 +0000 (18:46 +0200)
initrds can only be on tmpfs or ramfs, so check for that

TODO
src/shared/util.c

diff --git a/TODO b/TODO
index 96db4a57d89232d01a6999c4057200765b7ec164..3d55f8a2d20c2d2060c1aa94403bdcc2f1b05adb 100644 (file)
--- a/TODO
+++ b/TODO
@@ -20,6 +20,18 @@ Bugfixes:
 * we pull src/core/manager.h into src/shared/src/shared/path-lookup.c which is the wrong direction
    rename enum "ManagerRunningAs" to "SystemdRunningAs" and move it to shared/
 
+* crash happens when running a service as forking and then changing it to simple and reloading.
+
+  Jul 09 18:20:57 mop systemd[1]: usbmuxd.service operation timed out. Terminating.
+  Jul 09 18:20:57 mop systemd[1]: Unit usbmuxd.service entered failed state.
+  Jul 09 18:22:24 mop systemd[1]: PID 21814 read from file /var/run/usbmuxd.pid does not exist.
+  Jul 09 18:22:24 mop systemd[1]: Unit usbmuxd.service entered failed state.
+  Jul 09 18:22:33 mop systemd[1]: Reloading.
+  Jul 09 18:22:37 mop systemd[1]: Assertion 's->type == SERVICE_FORKING' failed at src/core/service.c:3007, function service_sigchld_eve...Aborting.
+  Jul 09 18:22:37 mop systemd[1]: Caught <ABRT>, dumped core as pid 21865.
+  Jul 09 18:22:37 mop systemd[1]: Freezing execution.
+  Jul 09 18:22:37 mop [21866]: Process 21865 (systemd) dumped core.
+
 Features:
 
 * switch-root add extra safety check
index 41505b2ca79bac962510704a22c65fbea92ba2df..8caac7b597fb0f3393c77e1ad2fce3fabdb91bb3 100644 (file)
@@ -54,6 +54,8 @@
 #include <glob.h>
 #include <grp.h>
 #include <sys/mman.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
 
 #include "macro.h"
 #include "util.h"
@@ -5738,9 +5740,24 @@ bool is_valid_documentation_url(const char *url) {
 
 bool in_initrd(void) {
         static int saved = -1;
+        struct statfs s;
 
-        if (saved < 0)
-                saved = access("/etc/initrd-release", F_OK) >= 0;
+        if (saved >= 0)
+                return saved;
+
+        /* We make two checks here:
+         *
+         * 1. the flag file /etc/initrd-release must exist
+         * 2. the root file system must be a memory file system
+         *
+         * The second check is extra paranoia, since misdetecting an
+         * initrd can have bad bad consequences due the initrd
+         * emptying when transititioning to the main systemd.
+         */
+
+        saved = access("/etc/initrd-release", F_OK) >= 0 &&
+                statfs("/", &s) >= 0 &&
+                (s.f_type == TMPFS_MAGIC || s.f_type == RAMFS_MAGIC);
 
         return saved;
 }