summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/sd_booted.xml9
-rw-r--r--src/core/mount-setup.c6
-rw-r--r--src/libsystemd-daemon/sd-daemon.c15
3 files changed, 15 insertions, 15 deletions
diff --git a/man/sd_booted.xml b/man/sd_booted.xml
index 34f2cbfbc8..ce5a34dc86 100644
--- a/man/sd_booted.xml
+++ b/man/sd_booted.xml
@@ -85,11 +85,10 @@
implementation.</para>
<para>Internally, this function checks whether the
- <filename>/sys/fs/cgroup/systemd</filename> virtual file
- system is mounted, by comparing the st_dev value of
- the <function>stat()</function> data of
- <filename>/sys/fs/cgroup</filename> and
- <filename>/sys/fs/cgroup/systemd</filename>.</para>
+ directory <filename>/run/systemd/system/</filename>
+ exists. A simple check like this can also be
+ implemented trivially in shell or any other
+ language.</para>
<para>For details about the algorithm check the
liberally licensed reference implementation sources:
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index 42cdc6dc52..ce10be944a 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -440,7 +440,11 @@ int mount_setup(bool loaded_policy) {
if (mount(NULL, "/", NULL, MS_REC|MS_SHARED, NULL) < 0)
log_warning("Failed to set up the root directory for shared mount propagation: %m");
- /* Create a few directories we always want around */
+ /* Create a few directories we always want around, Note that
+ * sd_booted() checks for /run/systemd/system, so this mkdir
+ * really needs to stay for good, otherwise software that
+ * copied sd-daemon.c into their sources will misdetect
+ * systemd. */
mkdir_label("/run/systemd", 0755);
mkdir_label("/run/systemd/system", 0755);
diff --git a/src/libsystemd-daemon/sd-daemon.c b/src/libsystemd-daemon/sd-daemon.c
index 5b92e2e3db..79d8ca3709 100644
--- a/src/libsystemd-daemon/sd-daemon.c
+++ b/src/libsystemd-daemon/sd-daemon.c
@@ -519,18 +519,15 @@ _sd_export_ int sd_booted(void) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
return 0;
#else
+ struct stat st;
- struct stat a, b;
+ /* We test whether the runtime unit file directory has been
+ * created. This takes place in mount-setup.c, so is
+ * guaranteed to happen very early during boot. */
- /* We simply test whether the systemd cgroup hierarchy is
- * mounted */
-
- if (lstat("/sys/fs/cgroup", &a) < 0)
- return 0;
-
- if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
+ if (lstat("/run/systemd/system/", &st) < 0)
return 0;
- return a.st_dev != b.st_dev;
+ return !!S_ISDIR(st.st_mode);
#endif
}