[systemd-commits] 4 commits - man/sd_booted.xml src/core src/libsystemd-daemon src/login src/nspawn src/shared
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Mar 15 08:49:15 PDT 2013
man/sd_booted.xml | 9 ++++-----
src/core/mount-setup.c | 6 +++++-
src/libsystemd-daemon/sd-daemon.c | 15 ++++++---------
src/login/logind.c | 10 ++++++++++
src/nspawn/nspawn.c | 2 +-
src/shared/strv.h | 2 +-
6 files changed, 27 insertions(+), 17 deletions(-)
New commits:
commit 9d60cb63d6e38236b2853b7801bb7784762b13ab
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 15 16:48:48 2013 +0100
nspawn: don't make assumptions about the size of pid_t
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 1a3e41f..9268cbc 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1589,7 +1589,7 @@ int main(int argc, char *argv[]) {
_exit(EXIT_FAILURE);
}
- log_info("Init process in the container running as PID %d", pid);
+ log_info("Init process in the container running as PID %lu.", (unsigned long) pid);
close_nointr_nofail(pipefd[0]);
close_nointr_nofail(pipefd[1]);
commit bb27ff6672573727488b5b4826e27ac9cb8a2c94
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 15 16:46:35 2013 +0100
logind: explicitly create state directories during early initialization
Strictly speaking this isn't necessary for the /run/systemd/seats/
directory, since that is created anyway as the first seat is found, and
seat0 is always found. But let's be explicit here, and also create the
sessions/ and users/ directories, so that people can always install
inotify watches from very early on, even when nobody logged in yet.
diff --git a/src/login/logind.c b/src/login/logind.c
index bb34a7f..f72aac5 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -37,6 +37,7 @@
#include "dbus-loop.h"
#include "strv.h"
#include "conf-parser.h"
+#include "mkdir.h"
Manager *manager_new(void) {
Manager *m;
@@ -1727,6 +1728,15 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ /* Always create the directories people can create inotify
+ * watches in. Note that some applications might check for the
+ * existance of /run/systemd/seats/ to determine whether
+ * logind is available, so please always make sure this check
+ * stays in. */
+ mkdir_label("/run/systemd/seats", 0755);
+ mkdir_label("/run/systemd/users", 0755);
+ mkdir_label("/run/systemd/sessions", 0755);
+
m = manager_new();
if (!m) {
r = log_oom();
commit 66e411811b8090d1bfd6620fc84472d83f723fa1
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 15 16:41:40 2013 +0100
sd-booted: update sd_booted() check a bit
Previously we were testing whether /sys/fs/cgroup/systemd/ was a mount
point. This might be problematic however, when the cgroup trees are bind
mounted into a container from the host (which should be absolutely
valid), which might create the impression that the container was running
systemd, but only the host actually is.
Replace this by a check for the existance of the directory
/run/systemd/system/, which should work unconditionally, since /run can
never be a bind mount but *must* be a tmpfs on systemd systems, which is
flushed at boots. This means that data in /run always reflects
information about the current boot, and only of the local container,
which makes it the perfect choice for a check like this.
(As side effect this is nice to Ubuntu people who now use logind with
the systemd cgroup hierarchy, where the old sd_booted() check misdetects
systemd, even though they still run legacy Upstart.)
diff --git a/man/sd_booted.xml b/man/sd_booted.xml
index 34f2cbf..ce5a34d 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 42cdc6d..ce10be9 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 5b92e2e..79d8ca3 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
}
commit 961e4526925b7b1e1d3582f2fc9fb38035e2b5fb
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Mar 15 16:41:13 2013 +0100
strv: fix STRV_FOREACH_PAIR macro definition
diff --git a/src/shared/strv.h b/src/shared/strv.h
index da9fae6..49058f8 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -77,7 +77,7 @@ bool strv_overlap(char **a, char **b);
for (; (l) && ((s) >= (l)); (s)--)
#define STRV_FOREACH_PAIR(x, y, l) \
- for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2)
+ for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
char **strv_sort(char **l);
More information about the systemd-commits
mailing list