[systemd-commits] 13 commits - .gitignore Makefile.am TODO man/systemd.conf.xml src/core src/libudev src/login src/readahead src/shared src/sleep src/systemd src/test src/timedate units/systemd-journald.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Mon Sep 3 18:59:09 PDT 2012


 .gitignore                        |    1 
 Makefile.am                       |   14 ++-
 TODO                              |   55 +++++++++++---
 man/systemd.conf.xml              |    2 
 src/core/dbus.c                   |    6 -
 src/core/job.c                    |  124 ++++++++++++++++++++++++++++++-
 src/core/main.c                   |    7 +
 src/core/manager.c                |   50 ++++++++----
 src/core/swap.c                   |   13 +++
 src/core/system.conf              |    2 
 src/core/umount.c                 |   10 +-
 src/core/unit.c                   |   93 ++++++++++++++++++++++-
 src/libudev/libudev.c             |    2 
 src/login/logind-dbus.c           |   45 +++++++++++
 src/login/logind-seat.c           |   14 +++
 src/login/logind-session.c        |   20 ++++-
 src/readahead/readahead-common.c  |   22 +++--
 src/shared/dbus-common.c          |    2 
 src/shared/log.c                  |  149 ++++++++++++++++++++++++++++++++++----
 src/shared/log.h                  |   66 +++++++++++-----
 src/shared/logs-show.c            |   37 ++++++++-
 src/shared/path-util.c            |   23 ++++-
 src/sleep/sleep.c                 |   26 +++++-
 src/systemd/sd-id128.h            |    1 
 src/systemd/sd-messages.h         |   33 +++++++-
 src/test/test-log.c               |   46 +++++++++++
 src/timedate/timedated.c          |   14 +++
 units/systemd-journald.service.in |    2 
 28 files changed, 752 insertions(+), 127 deletions(-)

New commits:
commit 88f89a9b6d25dfcb89691727c8cdaf01f4090b72
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Sep 3 18:58:18 2012 -0700

    update TODO -- hackfest edition

diff --git a/TODO b/TODO
index fd1d96d..d1a2a59 100644
--- a/TODO
+++ b/TODO
@@ -49,6 +49,39 @@ Bugfixes:
 
 Features:
 
+* journald: check whether it is OK if the client can still modify delivered journal entries
+
+* json: use yajl
+* json: don't add wrapping array, just put entries on one line each
+* json: add -o json-pretty in addition to -o json, make the latter output one line per entry
+* json: properly serialize multiple fields with the same name per entry
+
+* journalctl: make -l the default
+
+* journald: add option to choose between "split up nothing", "split up login user journals", "split up all user journals"
+
+* journal live copy, bsaed on libneon (client) and libmicrohttpd
+
+* document in wiki json serialization
+
+* python-journal merge
+
+* system-wide seccomp filter
+
+* securityfs: don't mount in container
+
+* slave/shared remount root fs in container
+
+* ability to pass fds into systemd
+
+* system.conf should have controls for cgroups
+
+* tmpfiles: skip mknod if CAP_MKNOD is missing
+
+* fake boot id
+
+* bind mount read-only the cgroup tree higher than than nspawn
+
 * currently system services appear not to generate core dumps...
 
 * introduce /run/kmsg in containers?
@@ -202,12 +235,6 @@ Features:
         - implement .d/ auto includes for unit files
         - add syntax to reset ExecStart= lists (and similar)
 
-* manipulate CPU governor during boot, set it to performance
-
-* steal SBF management from the kernel
-
-* delay journal /var writeout to after boot if SBF is clean
-
 * move passno parsing to fstab generator
 
 * improve !/proc/*/loginuid situation: make /proc/*/loginuid less dependent on CONFIG_AUDIT,
@@ -302,6 +329,8 @@ Features:
 
 * dbus: in fedora, make the machine a symlink to /etc/machine-id
 
+* dbus: on fedora, move dbus to early boot
+
 * journald: reuse XZ context
 
 * logind: add equivalent to sd_pid_get_owner_uid() to the D-Bus API
@@ -399,8 +428,6 @@ Features:
 
 * GC unreferenced jobs (such as .device jobs)
 
-* when failing to start a service due to ratelimiting, try again later, if restart=always is set
-
 * write blog stories about:
   - enabling dbus services
   - status update

commit be5412d85493615bc2b027bd7131497e31725190
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Sep 3 18:54:32 2012 -0700

    main: jointly mount more controllers
    
    After talking to the cgroup kernel folks at LPC we came to the
    conclusion that it is probably a good idea to mount all CPU related
    resp. all network related cgroup controllers together, both because they
    are good defaults for admins and because this might prepare
    for eventual kernel cleanups where the ability to mount them separately
    is removed.

diff --git a/man/systemd.conf.xml b/man/systemd.conf.xml
index 7dc5cc1..a550c2c 100644
--- a/man/systemd.conf.xml
+++ b/man/systemd.conf.xml
@@ -118,7 +118,7 @@
                         </varlistentry>
 
                         <varlistentry>
-                                <term><varname>JoinControllers=cpu,cpuacct</varname></term>
+                                <term><varname>JoinControllers=cpu,cpuacct,cpuset net_cls,netprio</varname></term>
 
                                 <listitem><para>Configures controllers
                                 that shall be mounted in a single
diff --git a/src/core/main.c b/src/core/main.c
index 12af3cd..7b5c861 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1305,12 +1305,13 @@ int main(int argc, char *argv[]) {
         }
 
         /* By default, mount "cpu" and "cpuacct" together */
-        arg_join_controllers = new(char**, 2);
+        arg_join_controllers = new(char**, 3);
         if (!arg_join_controllers)
                 goto finish;
 
-        arg_join_controllers[0] = strv_new("cpu", "cpuacct", NULL);
-        arg_join_controllers[1] = NULL;
+        arg_join_controllers[0] = strv_new("cpu", "cpuacct", "cpuset", NULL);
+        arg_join_controllers[1] = strv_new("net_cls", "netprio", NULL);
+        arg_join_controllers[2] = NULL;
 
         if (!arg_join_controllers[0])
                 goto finish;
diff --git a/src/core/system.conf b/src/core/system.conf
index d520818..3989c2e 100644
--- a/src/core/system.conf
+++ b/src/core/system.conf
@@ -20,7 +20,7 @@
 #DefaultControllers=cpu
 #DefaultStandardOutput=journal
 #DefaultStandardError=inherit
-#JoinControllers=cpu,cpuacct
+#JoinControllers=cpu,cpuacct,cpuset net_cls,netprio
 #RuntimeWatchdogSec=0
 #ShutdownWatchdogSec=10min
 #CapabilityBoundingSet=

commit 1946b0bd55b356ea25bd747cb338a4b31fabeecf
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 25 00:55:22 2012 +0200

    journalctl: include logs from PID 1 about services in systemctl status

diff --git a/TODO b/TODO
index 9a888ec..fd1d96d 100644
--- a/TODO
+++ b/TODO
@@ -49,6 +49,8 @@ Bugfixes:
 
 Features:
 
+* currently system services appear not to generate core dumps...
+
 * introduce /run/kmsg in containers?
 
 * introduce $container_boot_id?
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 60eb896..99407c9 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -577,7 +577,7 @@ int show_journal_by_unit(
                 unsigned how_many,
                 OutputFlags flags) {
 
-        char *m = NULL;
+        char *m1 = NULL, *m2 = NULL, *m3 = NULL;
         sd_journal *j = NULL;
         int r;
         unsigned line = 0;
@@ -597,7 +597,9 @@ int show_journal_by_unit(
         if (how_many <= 0)
                 return 0;
 
-        if (asprintf(&m, "_SYSTEMD_UNIT=%s", unit) < 0) {
+        if (asprintf(&m1, "_SYSTEMD_UNIT=%s", unit) < 0 ||
+            asprintf(&m2, "COREDUMP_UNIT=%s", unit) < 0 ||
+            asprintf(&m3, "UNIT=%s", unit) < 0) {
                 r = -ENOMEM;
                 goto finish;
         }
@@ -606,10 +608,34 @@ int show_journal_by_unit(
         if (r < 0)
                 goto finish;
 
-        r = sd_journal_add_match(j, m, strlen(m));
+        /* Look for messages from the service itself */
+        r = sd_journal_add_match(j, m1, 0);
         if (r < 0)
                 goto finish;
 
+        /* Look for coredumps of the service */
+        r = sd_journal_add_disjunction(j);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, "MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1", 0);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, m2, 0);
+        if (r < 0)
+                goto finish;
+
+        /* Look for messages from PID 1 about this service */
+        r = sd_journal_add_disjunction(j);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, "_PID=1", 0);
+        if (r < 0)
+                goto finish;
+        r = sd_journal_add_match(j, m3, 0);
+        if (r < 0)
+                goto finish;
+
+        /* Seek to end */
         r = sd_journal_seek_tail(j);
         if (r < 0)
                 goto finish;
@@ -692,8 +718,9 @@ int show_journal_by_unit(
                 fputs("\n]\n", stdout);
 
 finish:
-        if (m)
-                free(m);
+        free(m1);
+        free(m2);
+        free(m3);
 
         if (j)
                 sd_journal_close(j);

commit 268ba0ef6095df82966e1f1eda671e43ab1b31ab
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 25 00:16:19 2012 +0200

    readahead: a bit of reformatting

diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index 99dbac2..766b3a1 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -71,14 +71,16 @@ int fs_on_ssd(const char *p) {
         if (major(st.st_dev) == 0)
                 return false;
 
-        if (!(udev = udev_new()))
+        udev = udev_new();
+        if (!udev)
                 return -ENOMEM;
 
-        if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
+        udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev);
+        if (!udev_device)
                 goto finish;
 
-        if ((devtype = udev_device_get_property_value(udev_device, "DEVTYPE")) &&
-            streq(devtype, "partition"))
+        devtype = udev_device_get_property_value(udev_device, "DEVTYPE");
+        if (devtype && streq(devtype, "partition"))
                 look_at = udev_device_get_parent(udev_device);
         else
                 look_at = udev_device;
@@ -87,21 +89,25 @@ int fs_on_ssd(const char *p) {
                 goto finish;
 
         /* First, try high-level property */
-        if ((id = udev_device_get_property_value(look_at, "ID_SSD"))) {
+        id = udev_device_get_property_value(look_at, "ID_SSD");
+        if (id) {
                 b = streq(id, "1");
                 goto finish;
         }
 
         /* Second, try kernel attribute */
-        if ((rotational = udev_device_get_sysattr_value(look_at, "queue/rotational")))
+        rotational = udev_device_get_sysattr_value(look_at, "queue/rotational");
+        if (rotational)
                 if ((b = streq(rotational, "0")))
                         goto finish;
 
         /* Finally, fallback to heuristics */
-        if (!(look_at = udev_device_get_parent(look_at)))
+        look_at = udev_device_get_parent(look_at);
+        if (!look_at)
                 goto finish;
 
-        if ((model = udev_device_get_sysattr_value(look_at, "model")))
+        model = udev_device_get_sysattr_value(look_at, "model");
+        if (model)
                 b = !!strstr(model, "SSD");
 
 finish:

commit cde9cb343ae101660dd36992cae730b63c7cd617
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Aug 25 00:10:17 2012 +0200

    util: make path_is_mount_point() recognize bind mounts, too

diff --git a/TODO b/TODO
index 9fa240c..9a888ec 100644
--- a/TODO
+++ b/TODO
@@ -49,11 +49,11 @@ Bugfixes:
 
 Features:
 
-* introduce $container_boot_id
+* introduce /run/kmsg in containers?
 
-* wall messages for shutdown should move to logind
+* introduce $container_boot_id?
 
-* remove wants from journald.service
+* wall messages for shutdown should move to logind
 
 * allow writing multiple conditions in unit files on one line
 
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 8bc7955..2bdbd22 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -330,15 +330,22 @@ bool path_equal(const char *a, const char *b) {
 }
 
 int path_is_mount_point(const char *t, bool allow_symlink) {
-        struct stat a, b;
         char *parent;
         int r;
+        struct file_handle *h;
+        int mount_id, mount_id_parent;
 
-        if (allow_symlink)
-                r = stat(t, &a);
-        else
-                r = lstat(t, &a);
+        /* We are not actually interested in the file handles, but
+         * name_to_handle_at() also passes us the mount ID, hence use
+         * it but throw the handle away */
+
+        if (path_equal(t, "/"))
+                return 1;
 
+        h = alloca(MAX_HANDLE_SZ);
+        h->handle_bytes = MAX_HANDLE_SZ;
+
+        r = name_to_handle_at(AT_FDCWD, t, h, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0);
         if (r < 0) {
                 if (errno == ENOENT)
                         return 0;
@@ -350,13 +357,15 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
         if (r < 0)
                 return r;
 
-        r = lstat(parent, &b);
+        h->handle_bytes = MAX_HANDLE_SZ;
+        r = name_to_handle_at(AT_FDCWD, parent, h, &mount_id_parent, 0);
         free(parent);
 
         if (r < 0)
                 return -errno;
 
-        return a.st_dev != b.st_dev;
+
+        return mount_id != mount_id_parent;
 }
 
 int path_is_read_only_fs(const char *path) {

commit ddffe892464b95630f2e1c9c6eefd6d30d36dec2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 23:23:08 2012 +0200

    journal: don't pull in flush service from journald service
    
    In the initrd we don't need the flush service hence don't attempt to
    pull it in.

diff --git a/Makefile.am b/Makefile.am
index 927d25f..ae775c8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2575,8 +2575,9 @@ journal-install-data-hook:
 		rm -f systemd-journald.socket && \
 		$(LN_S) ../systemd-journald.socket )
 	( cd $(DESTDIR)$(systemunitdir)/sysinit.target.wants && \
-		rm -f systemd-journald.service && \
-		$(LN_S) ../systemd-journald.service )
+		rm -f systemd-journald.service systemd-journal-flush.service && \
+		$(LN_S) ../systemd-journald.service && \
+		$(LN_S) ../systemd-journal-flush.service )
 
 INSTALL_DATA_HOOKS += \
 	journal-install-data-hook
diff --git a/units/systemd-journald.service.in b/units/systemd-journald.service.in
index cfbcda2..ab2e50c 100644
--- a/units/systemd-journald.service.in
+++ b/units/systemd-journald.service.in
@@ -9,7 +9,6 @@
 Description=Journal Service
 Documentation=man:systemd-journald.service(8) man:journald.conf(5)
 DefaultDependencies=no
-Wants=systemd-journal-flush.service
 Requires=systemd-journald.socket
 After=systemd-journald.socket syslog.socket
 Before=sysinit.target

commit 7e75c5ac2d607bd87818d1a3546ff6ae5c6c3859
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 23:18:35 2012 +0200

    unit: make sure structured logging is available before we enter the main boot phase

diff --git a/TODO b/TODO
index b1d92da..9fa240c 100644
--- a/TODO
+++ b/TODO
@@ -49,6 +49,8 @@ Bugfixes:
 
 Features:
 
+* introduce $container_boot_id
+
 * wall messages for shutdown should move to logind
 
 * remove wants from journald.service
diff --git a/units/systemd-journald.service.in b/units/systemd-journald.service.in
index 366655b..cfbcda2 100644
--- a/units/systemd-journald.service.in
+++ b/units/systemd-journald.service.in
@@ -12,6 +12,7 @@ DefaultDependencies=no
 Wants=systemd-journal-flush.service
 Requires=systemd-journald.socket
 After=systemd-journald.socket syslog.socket
+Before=sysinit.target
 
 [Service]
 ExecStart=@rootlibexecdir@/systemd-journald

commit c0387ebfb672d16e194201e04f8185545e1a5914
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 23:07:03 2012 +0200

    swap: don't try to shutdown swaps on shutdown in a container

diff --git a/src/core/swap.c b/src/core/swap.c
index 41ece27..8ba6055 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -174,7 +174,8 @@ static int swap_add_target_links(Swap *s) {
         if (!s->from_fragment)
                 return 0;
 
-        if ((r = manager_load_unit(UNIT(s)->manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu)) < 0)
+        r = manager_load_unit(UNIT(s)->manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu);
+        if (r < 0)
                 return r;
 
         return unit_add_dependency(UNIT(s), UNIT_BEFORE, tu, true);
@@ -212,6 +213,9 @@ static int swap_add_default_dependencies(Swap *s) {
         if (UNIT(s)->manager->running_as != MANAGER_SYSTEM)
                 return 0;
 
+        if (detect_container(NULL) > 0)
+                return 0;
+
         r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
         if (r < 0)
                 return r;

commit a5c3034fa7089ae680b3b95da33936870f7b493f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 23:00:13 2012 +0200

    swap: refuse start/stop of swaps in container

diff --git a/src/core/swap.c b/src/core/swap.c
index cd4d9ab..41ece27 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -39,6 +39,7 @@
 #include "exit-status.h"
 #include "def.h"
 #include "path-util.h"
+#include "virt.h"
 
 static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
         [SWAP_DEAD] = UNIT_INACTIVE,
@@ -797,6 +798,9 @@ static int swap_start(Unit *u) {
 
         assert(s->state == SWAP_DEAD || s->state == SWAP_FAILED);
 
+        if (detect_container(NULL) > 0)
+                return -EPERM;
+
         s->result = SWAP_SUCCESS;
         swap_enter_activating(s);
         return 0;
@@ -817,6 +821,9 @@ static int swap_stop(Unit *u) {
         assert(s->state == SWAP_ACTIVATING ||
                s->state == SWAP_ACTIVE);
 
+        if (detect_container(NULL) > 0)
+                return -EPERM;
+
         swap_enter_deactivating(s);
         return 0;
 }

commit 024f268d634159849e642e7005871739c428524d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 22:50:16 2012 +0200

    shutdown: don't attempt read-only mounts in a container

diff --git a/src/core/umount.c b/src/core/umount.c
index b9afac7..83c9de3 100644
--- a/src/core/umount.c
+++ b/src/core/umount.c
@@ -34,6 +34,7 @@
 #include "umount.h"
 #include "path-util.h"
 #include "util.h"
+#include "virt.h"
 
 typedef struct MountPoint {
         char *path;
@@ -548,11 +549,9 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {
 int umount_all(bool *changed) {
         int r;
         bool umount_changed;
-
         LIST_HEAD(MountPoint, mp_list_head);
 
         LIST_HEAD_INIT(MountPoint, mp_list_head);
-
         r = mount_points_list_get(&mp_list_head);
         if (r < 0)
                 goto end;
@@ -572,7 +571,12 @@ int umount_all(bool *changed) {
         if (r <= 0)
                 goto end;
 
-        r = mount_points_list_remount_read_only(&mp_list_head, changed);
+        /* If we are in a container, don't attempt to read-only mount
+           anything as that brings no real benefits, but might confuse
+           the host, as we remount the superblock here, not the bind
+           mound. */
+        if (detect_container(NULL) <= 0)
+                r = mount_points_list_remount_read_only(&mp_list_head, changed);
 
   end:
         mount_points_list_free(&mp_list_head);

commit 81270860a5b8c6794f0c7bac8becfdd0c41a9385
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 22:43:33 2012 +0200

    journal: suppress structured messages if they'd go to the console

diff --git a/src/core/job.c b/src/core/job.c
index 9614642..706910b 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -687,6 +687,12 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
         assert(t >= 0);
         assert(t < _JOB_TYPE_MAX);
 
+        /* Skip this if it goes to the console. since we already print
+         * to the console anyway... */
+
+        if (log_on_console())
+                return;
+
         format = job_get_status_message_format_try_harder(u, t, result);
         if (!format)
                 return;
diff --git a/src/core/manager.c b/src/core/manager.c
index da766e6..40b0c50 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -2032,41 +2032,44 @@ void manager_check_finished(Manager *m) {
                         kernel_usec = m->initrd_timestamp.monotonic;
                         initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
 
-                        log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
-                                   "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
-                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                   format_timespan(initrd, sizeof(initrd), initrd_usec),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                   format_timespan(sum, sizeof(sum), total_usec),
-                                   NULL);
+                        if (!log_on_console())
+                                log_struct(LOG_INFO,
+                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                           "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
+                                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                           "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
+                                           format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                           format_timespan(initrd, sizeof(initrd), initrd_usec),
+                                           format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                           format_timespan(sum, sizeof(sum), total_usec),
+                                           NULL);
                 } else {
                         kernel_usec = m->startup_timestamp.monotonic;
                         initrd_usec = 0;
 
-                        log_struct(LOG_INFO,
-                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
-                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                                   "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
-                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                   format_timespan(sum, sizeof(sum), total_usec),
-                                   NULL);
+                        if (!log_on_console())
+                                log_struct(LOG_INFO,
+                                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                           "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                           "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
+                                           format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                           format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                           format_timespan(sum, sizeof(sum), total_usec),
+                                           NULL);
                 }
         } else {
                 initrd_usec = kernel_usec = 0;
                 total_usec = userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
 
-                log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
-                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
-                           "MESSAGE=Startup finished in %s.",
-                           format_timespan(sum, sizeof(sum), total_usec),
-                           NULL);
+                if (!log_on_console())
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                   "MESSAGE=Startup finished in %s.",
+                                   format_timespan(sum, sizeof(sum), total_usec),
+                                   NULL);
         }
 
         bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
diff --git a/src/core/unit.c b/src/core/unit.c
index 8246837..ba4c7d5 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1004,6 +1004,9 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
         if (t != JOB_START && t != JOB_STOP && t != JOB_RELOAD)
                 return;
 
+        if (log_on_console())
+                return;
+
         /* We log status messages for all units and all operations. */
 
         format = unit_get_status_message_format_try_harder(u, t);
diff --git a/src/shared/log.c b/src/shared/log.c
index 67a3e1b..847202d 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -859,6 +859,13 @@ int log_show_location_from_string(const char *e) {
         return 0;
 }
 
+bool log_on_console(void) {
+        if (log_target == LOG_TARGET_CONSOLE)
+                return true;
+
+        return syslog_fd < 0 && kmsg_fd < 0 && journal_fd < 0;
+}
+
 static const char *const log_target_table[] = {
         [LOG_TARGET_CONSOLE] = "console",
         [LOG_TARGET_KMSG] = "kmsg",
diff --git a/src/shared/log.h b/src/shared/log.h
index 0c60b76..c242cc2 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -131,5 +131,7 @@ _noreturn_ void log_assert_failed_unreachable(
 /* This modifies the buffer passed! */
 #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
 
+bool log_on_console(void);
+
 const char *log_target_to_string(LogTarget target);
 LogTarget log_target_from_string(const char *s);

commit 877d54e9b09e093c2102f519a84e2a52637ae035
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Aug 24 22:21:20 2012 +0200

    journal: generate structured journal messages for a number of events

diff --git a/.gitignore b/.gitignore
index 4c8bba8..ca95d7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/test-log
 /test-journal-verify
 /test-journal-match
 /test-journal-stream
diff --git a/Makefile.am b/Makefile.am
index e5ace9b..927d25f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1117,7 +1117,8 @@ noinst_PROGRAMS += \
 	test-strv \
 	test-install \
 	test-watchdog \
-	test-unit-name
+	test-unit-name \
+	test-log
 
 TESTS += \
 	test-job-type \
@@ -1173,6 +1174,12 @@ test_unit_name_SOURCES = \
 test_unit_name_LDADD = \
 	libsystemd-core.la
 
+test_log_SOURCES = \
+	src/test/test-log.c
+
+test_log_LDADD = \
+	libsystemd-core.la
+
 test_daemon_SOURCES = \
 	src/test/test-daemon.c
 
diff --git a/TODO b/TODO
index a4643d7..b1d92da 100644
--- a/TODO
+++ b/TODO
@@ -49,6 +49,10 @@ Bugfixes:
 
 Features:
 
+* wall messages for shutdown should move to logind
+
+* remove wants from journald.service
+
 * allow writing multiple conditions in unit files on one line
 
 * journal: json output needs to be able to deal with multiple assignments of the same field
diff --git a/src/core/job.c b/src/core/job.c
index 8d51aa3..9614642 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -24,6 +24,8 @@
 #include <sys/timerfd.h>
 #include <sys/epoll.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "set.h"
 #include "unit.h"
 #include "macro.h"
@@ -549,17 +551,74 @@ int job_run_and_invalidate(Job *j) {
         return r;
 }
 
-static void job_print_status_message(Unit *u, JobType t, JobResult result) {
+static const char *job_get_status_message_format(Unit *u, JobType t, JobResult result) {
         const UnitStatusMessageFormats *format_table;
-        const char *format;
+
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
 
         format_table = &UNIT_VTABLE(u)->status_message_formats;
         if (!format_table)
-                return;
+                return NULL;
+
+        if (t == JOB_START)
+                return format_table->finished_start_job[result];
+        else if (t == JOB_STOP || t == JOB_RESTART)
+                return format_table->finished_stop_job[result];
+
+        return NULL;
+}
 
+static const char *job_get_status_message_format_try_harder(Unit *u, JobType t, JobResult result) {
+        const char *format;
+
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
+
+        format = job_get_status_message_format(u, t, result);
+        if (format)
+                return format;
+
+        /* Return generic strings */
         if (t == JOB_START) {
+                if (result == JOB_DONE)
+                        return "Started %s.";
+                else if (result == JOB_FAILED)
+                        return "Failed to start %s.";
+                else if (result == JOB_DEPENDENCY)
+                        return "Dependency failed for %s.";
+                else if (result == JOB_TIMEOUT)
+                        return "Timed out starting %s.";
+        } else if (t == JOB_STOP || t == JOB_RESTART) {
+                if (result == JOB_DONE)
+                        return "Stopped %s.";
+                else if (result == JOB_FAILED)
+                        return "Stopped (with error) %s.";
+                else if (result == JOB_TIMEOUT)
+                        return "Timed out stoppping %s.";
+        } else if (t == JOB_RELOAD) {
+                if (result == JOB_DONE)
+                        return "Reloaded %s.";
+                else if (result == JOB_FAILED)
+                        return "Reload failed for %s.";
+                else if (result == JOB_TIMEOUT)
+                        return "Timed out reloading %s.";
+        }
+
+        return NULL;
+}
+
+static void job_print_status_message(Unit *u, JobType t, JobResult result) {
+        const char *format;
 
-                format = format_table->finished_start_job[result];
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
+
+        if (t == JOB_START) {
+                format = job_get_status_message_format(u, t, result);
                 if (!format)
                         return;
 
@@ -572,7 +631,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
 
                 case JOB_FAILED:
                         unit_status_printf(u, ANSI_HIGHLIGHT_RED_ON "FAILED" ANSI_HIGHLIGHT_OFF, format, unit_description(u));
-                        unit_status_printf(u, "", "See 'systemctl status %s' for details.", u->id);
+                        unit_status_printf(u, NULL, "See 'systemctl status %s' for details.", u->id);
                         break;
 
                 case JOB_DEPENDENCY:
@@ -589,7 +648,7 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
 
         } else if (t == JOB_STOP || t == JOB_RESTART) {
 
-                format = format_table->finished_stop_job[result];
+                format = job_get_status_message_format(u, t, result);
                 if (!format)
                         return;
 
@@ -618,6 +677,52 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
         }
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+static void job_log_status_message(Unit *u, JobType t, JobResult result) {
+        const char *format;
+        char buf[LINE_MAX];
+
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
+
+        format = job_get_status_message_format_try_harder(u, t, result);
+        if (!format)
+                return;
+
+        snprintf(buf, sizeof(buf), format, unit_description(u));
+        char_array_0(buf);
+
+        if (t == JOB_START) {
+                sd_id128_t mid;
+
+                mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
+                log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(mid),
+                           "UNIT=%s", u->id,
+                           "RESULT=%s", job_result_to_string(result),
+                           "MESSAGE=%s", buf,
+                           NULL);
+
+        } else if (t == JOB_STOP)
+                log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_UNIT_STOPPED),
+                           "UNIT=%s", u->id,
+                           "RESULT=%s", job_result_to_string(result),
+                           "MESSAGE=%s", buf,
+                           NULL);
+
+        else if (t == JOB_RELOAD)
+                log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR,
+                           "MESSSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_UNIT_RELOADED),
+                           "UNIT=%s", u->id,
+                           "RESULT=%s", job_result_to_string(result),
+                           "MESSAGE=%s", buf,
+                           NULL);
+}
+#pragma GCC diagnostic pop
+
 int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
         Unit *u;
         Unit *other;
@@ -636,6 +741,7 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
         log_debug("Job %s/%s finished, result=%s", u->id, job_type_to_string(t), job_result_to_string(result));
 
         job_print_status_message(u, t, result);
+        job_log_status_message(u, t, result);
 
         job_add_to_dbus_queue(j);
 
diff --git a/src/core/manager.c b/src/core/manager.c
index bcaf913..da766e6 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -41,7 +41,9 @@
 #include <libaudit.h>
 #endif
 
-#include <systemd/sd-daemon.h>
+#include "systemd/sd-daemon.h"
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 
 #include "manager.h"
 #include "transaction.h"
@@ -2030,26 +2032,41 @@ void manager_check_finished(Manager *m) {
                         kernel_usec = m->initrd_timestamp.monotonic;
                         initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
 
-                        log_info("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
-                                 format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                 format_timespan(initrd, sizeof(initrd), initrd_usec),
-                                 format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                 format_timespan(sum, sizeof(sum), total_usec));
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                   "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
+                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                   "MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
+                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                   format_timespan(initrd, sizeof(initrd), initrd_usec),
+                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                   format_timespan(sum, sizeof(sum), total_usec),
+                                   NULL);
                 } else {
                         kernel_usec = m->startup_timestamp.monotonic;
                         initrd_usec = 0;
 
-                        log_info("Startup finished in %s (kernel) + %s (userspace) = %s.",
-                                 format_timespan(kernel, sizeof(kernel), kernel_usec),
-                                 format_timespan(userspace, sizeof(userspace), userspace_usec),
-                                 format_timespan(sum, sizeof(sum), total_usec));
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                                   "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
+                                   "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                                   "MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
+                                   format_timespan(kernel, sizeof(kernel), kernel_usec),
+                                   format_timespan(userspace, sizeof(userspace), userspace_usec),
+                                   format_timespan(sum, sizeof(sum), total_usec),
+                                   NULL);
                 }
         } else {
-                userspace_usec = initrd_usec = kernel_usec = 0;
-                total_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
-
-                log_debug("Startup finished in %s.",
-                          format_timespan(sum, sizeof(sum), total_usec));
+                initrd_usec = kernel_usec = 0;
+                total_usec = userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
+
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_STARTUP_FINISHED),
+                           "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+                           "MESSAGE=Startup finished in %s.",
+                           format_timespan(sum, sizeof(sum), total_usec),
+                           NULL);
         }
 
         bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
diff --git a/src/core/unit.c b/src/core/unit.c
index 0d5d15e..8246837 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -29,6 +29,8 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "set.h"
 #include "unit.h"
 #include "macro.h"
@@ -936,21 +938,93 @@ bool unit_condition_test(Unit *u) {
         return u->condition_result;
 }
 
-static void unit_status_print_starting_stopping(Unit *u, bool stopping) {
+static const char* unit_get_status_message_format(Unit *u, JobType t) {
         const UnitStatusMessageFormats *format_table;
-        const char *format;
+
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
+
+        if (t != JOB_START && t != JOB_STOP)
+                return NULL;
 
         format_table = &UNIT_VTABLE(u)->status_message_formats;
         if (!format_table)
-                return;
+                return NULL;
+
+        return format_table->starting_stopping[t == JOB_STOP];
+}
+
+static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
+        const char *format;
+
+        assert(u);
+        assert(t >= 0);
+        assert(t < _JOB_TYPE_MAX);
+
+        format = unit_get_status_message_format(u, t);
+        if (format)
+                return format;
+
+        /* Return generic strings */
+        if (t == JOB_START)
+                return "Starting %s.";
+        else if (t == JOB_STOP)
+                return "Stopping %s.";
+        else if (t == JOB_RELOAD)
+                return "Reloading %s.";
+
+        return NULL;
+}
+
+static void unit_status_print_starting_stopping(Unit *u, JobType t) {
+        const char *format;
+
+        assert(u);
 
-        format = format_table->starting_stopping[stopping];
+        /* We only print status messages for selected units on
+         * selected operations. */
+
+        format = unit_get_status_message_format(u, t);
         if (!format)
                 return;
 
         unit_status_printf(u, "", format, unit_description(u));
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
+        const char *format;
+        char buf[LINE_MAX];
+        sd_id128_t mid;
+
+        assert(u);
+
+        if (t != JOB_START && t != JOB_STOP && t != JOB_RELOAD)
+                return;
+
+        /* We log status messages for all units and all operations. */
+
+        format = unit_get_status_message_format_try_harder(u, t);
+        if (!format)
+                return;
+
+        snprintf(buf, sizeof(buf), format, unit_description(u));
+        char_array_0(buf);
+
+        mid = t == JOB_START ? SD_MESSAGE_UNIT_STARTING :
+              t == JOB_STOP  ? SD_MESSAGE_UNIT_STOPPING :
+                               SD_MESSAGE_UNIT_RELOADING;
+
+        log_struct(LOG_INFO,
+                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(mid),
+                   "UNIT=%s", u->id,
+                   "MESSAGE=%s", buf,
+                   NULL);
+}
+#pragma GCC diagnostic pop
+
 /* Errors:
  *         -EBADR:     This unit type does not support starting.
  *         -EALREADY:  Unit is already started.
@@ -990,7 +1064,8 @@ int unit_start(Unit *u) {
                 return unit_start(following);
         }
 
-        unit_status_print_starting_stopping(u, false);
+        unit_status_log_starting_stopping_reloading(u, JOB_START);
+        unit_status_print_starting_stopping(u, JOB_START);
 
         /* If it is stopped, but we cannot start it, then fail */
         if (!UNIT_VTABLE(u)->start)
@@ -1040,7 +1115,8 @@ int unit_stop(Unit *u) {
                 return unit_stop(following);
         }
 
-        unit_status_print_starting_stopping(u, true);
+        unit_status_log_starting_stopping_reloading(u, JOB_STOP);
+        unit_status_print_starting_stopping(u, JOB_STOP);
 
         if (!UNIT_VTABLE(u)->stop)
                 return -EBADR;
@@ -1079,6 +1155,8 @@ int unit_reload(Unit *u) {
                 return unit_reload(following);
         }
 
+        unit_status_log_starting_stopping_reloading(u, JOB_RELOAD);
+
         unit_add_to_dbus_queue(u);
         return UNIT_VTABLE(u)->reload(u);
 }
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index ae9671b..af62d87 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -31,6 +31,8 @@
 #include "path-util.h"
 #include "polkit.h"
 #include "special.h"
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 
 #define BUS_MANAGER_INTERFACE                                           \
         " <interface name=\"org.freedesktop.login1.Manager\">\n"        \
@@ -1138,6 +1140,42 @@ finish:
         return 0;
 }
 
+static int bus_manager_log_shutdown(
+                Manager *m,
+                InhibitWhat w,
+                const char *unit_name) {
+
+        const char *p, *q;
+
+        assert(m);
+        assert(unit_name);
+
+        if (w != INHIBIT_SHUTDOWN)
+                return 0;
+
+        if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
+                p = "MESSAGE=System is powering down.";
+                q = "SHUTDOWN=power-off";
+        } else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
+                p = "MESSAGE=System is halting.";
+                q = "SHUTDOWN=halt";
+        } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
+                p = "MESSAGE=System is rebooting.";
+                q = "SHUTDOWN=reboot";
+        } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
+                p = "MESSAGE=System is rebooting with kexec.";
+                q = "SHUTDOWN=kexec";
+        } else {
+                p = "MESSAGE=System is shutting down.";
+                q = NULL;
+        }
+
+        return log_struct(LOG_NOTICE,
+                          "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SHUTDOWN),
+                          p,
+                          q, NULL);
+}
+
 int bus_manager_shutdown_or_sleep_now_or_later(
                 Manager *m,
                 const char *unit_name,
@@ -1160,10 +1198,13 @@ int bus_manager_shutdown_or_sleep_now_or_later(
                 /* Shutdown is delayed, keep in mind what we
                  * want to do, and start a timeout */
                 r = delay_shutdown_or_sleep(m, w, unit_name);
-        else
+        else {
+                bus_manager_log_shutdown(m, w, unit_name);
+
                 /* Shutdown is not delayed, execute it
                  * immediately */
                 r = send_start_unit(m->bus, unit_name, error);
+        }
 
         return r;
 }
@@ -2256,6 +2297,8 @@ int manager_dispatch_delayed(Manager *manager) {
         if (delayed)
                 return 0;
 
+        bus_manager_log_shutdown(manager, manager->delayed_what, manager->delayed_unit);
+
         /* Reset delay data */
         unit_name = manager->delayed_unit;
         manager->delayed_unit = NULL;
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index 0457121..937315e 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -27,6 +27,8 @@
 #include <linux/vt.h>
 #include <string.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "logind-seat.h"
 #include "logind-acl.h"
 #include "util.h"
@@ -337,7 +339,11 @@ int seat_start(Seat *s) {
         if (s->started)
                 return 0;
 
-        log_info("New seat %s.", s->id);
+        log_struct(LOG_INFO,
+                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SEAT_START),
+                   "SEAT_ID=%s", s->id,
+                   "MESSAGE=New seat %s.", s->id,
+                   NULL);
 
         /* Initialize VT magic stuff */
         seat_preallocate_vts(s);
@@ -361,7 +367,11 @@ int seat_stop(Seat *s) {
         assert(s);
 
         if (s->started)
-                log_info("Removed seat %s.", s->id);
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SEAT_STOP),
+                           "SEAT_ID=%s", s->id,
+                           "MESSAGE=Removed seat %s.", s->id,
+                           NULL);
 
         seat_stop_sessions(s);
 
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 16d4955..77462a8 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -25,6 +25,8 @@
 #include <sys/epoll.h>
 #include <fcntl.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "strv.h"
 #include "util.h"
 #include "mkdir.h"
@@ -542,8 +544,13 @@ int session_start(Session *s) {
         if (r < 0)
                 return r;
 
-        log_full(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                 "New session %s of user %s.", s->id, s->user->name);
+        log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
+                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_START),
+                   "SESSION_ID=%s", s->id,
+                   "USER_ID=%s", s->user->name,
+                   "LEADER=%lu", (unsigned long) s->leader,
+                   "MESSAGE=New session %s of user %s.", s->id, s->user->name,
+                   NULL);
 
         /* Create cgroup */
         r = session_create_cgroup(s);
@@ -679,8 +686,13 @@ int session_stop(Session *s) {
         assert(s);
 
         if (s->started)
-                log_full(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
-                         "Removed session %s.", s->id);
+                log_struct(s->type == SESSION_TTY || s->type == SESSION_X11 ? LOG_INFO : LOG_DEBUG,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SESSION_STOP),
+                           "SESSION_ID=%s", s->id,
+                           "USER_ID=%s", s->user->name,
+                           "LEADER=%lu", (unsigned long) s->leader,
+                           "MESSAGE=Removed session %s.", s->id,
+                           NULL);
 
         /* Kill cgroup */
         k = session_terminate_cgroup(s);
diff --git a/src/shared/log.c b/src/shared/log.c
index 4fc430e..67a3e1b 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -658,11 +658,127 @@ _noreturn_ void log_assert_failed_unreachable(const char *text, const char *file
         log_assert(text, file, line, func, "Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
 }
 
-int __log_oom(const char *file, int line, const char *func) {
+int log_oom_internal(const char *file, int line, const char *func) {
         log_meta(LOG_ERR, file, line, func, "Out of memory.");
         return -ENOMEM;
 }
 
+int log_struct_internal(
+                int level,
+                const char *file,
+                int line,
+                const char *func,
+                const char *format, ...) {
+
+        int saved_errno;
+        va_list ap;
+        int r;
+
+        if (_likely_(LOG_PRI(level) > log_max_level))
+                return 0;
+
+        if (log_target == LOG_TARGET_NULL)
+                return 0;
+
+        if ((level & LOG_FACMASK) == 0)
+                level = log_facility | LOG_PRI(level);
+
+        saved_errno = errno;
+
+        if ((log_target == LOG_TARGET_AUTO ||
+             log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+             log_target == LOG_TARGET_JOURNAL) &&
+            journal_fd >= 0) {
+
+                char header[LINE_MAX];
+                struct iovec iovec[17];
+                unsigned n = 0, i;
+                struct msghdr mh;
+                const char nl = '\n';
+
+                /* If the journal is available do structured logging */
+
+                snprintf(header, sizeof(header),
+                        "PRIORITY=%i\n"
+                        "SYSLOG_FACILITY=%i\n"
+                        "CODE_FILE=%s\n"
+                        "CODE_LINE=%i\n"
+                        "CODE_FUNCTION=%s\n"
+                        "SYSLOG_IDENTIFIER=%s\n",
+                        LOG_PRI(level),
+                        LOG_FAC(level),
+                        file,
+                        line,
+                        func,
+                        program_invocation_short_name);
+                char_array_0(header);
+
+                zero(iovec);
+                IOVEC_SET_STRING(iovec[n++], header);
+
+                va_start(ap, format);
+                while (format && n + 1 < ELEMENTSOF(iovec)) {
+                        char *buf;
+
+                        if (vasprintf(&buf, format, ap) < 0) {
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+
+                        IOVEC_SET_STRING(iovec[n++], buf);
+
+                        iovec[n].iov_base = (char*) &nl;
+                        iovec[n].iov_len = 1;
+                        n++;
+
+                        format = va_arg(ap, char *);
+                }
+                va_end(ap);
+
+                zero(mh);
+                mh.msg_iov = iovec;
+                mh.msg_iovlen = n;
+
+                if (sendmsg(journal_fd, &mh, MSG_NOSIGNAL) < 0)
+                        r = -errno;
+                else
+                        r = 1;
+
+        finish:
+                for (i = 1; i < n; i += 2)
+                        free(iovec[i].iov_base);
+
+        } else {
+                char buf[LINE_MAX];
+                bool found = false;
+
+                /* Fallback if journal logging is not available */
+
+                va_start(ap, format);
+                while (format) {
+
+                        vsnprintf(buf, sizeof(buf), format, ap);
+                        char_array_0(buf);
+
+                        if (startswith(buf, "MESSAGE=")) {
+                                found = true;
+                                break;
+                        }
+
+                        format = va_arg(ap, char *);
+                }
+                va_end(ap);
+
+                if (found)
+                        r = log_dispatch(level, file, line, func, buf + 8);
+                else
+                        r = -EINVAL;
+        }
+
+        errno = saved_errno;
+        return r;
+}
+
 int log_set_target_from_string(const char *e) {
         LogTarget t;
 
diff --git a/src/shared/log.h b/src/shared/log.h
index ab894df..0c60b76 100644
--- a/src/shared/log.h
+++ b/src/shared/log.h
@@ -70,30 +70,51 @@ void log_close_console(void);
 void log_parse_environment(void);
 
 int log_meta(
-        int level,
-        const char*file,
-        int line,
-        const char *func,
-        const char *format, ...) _printf_attr_(5,6);
+                int level,
+                const char*file,
+                int line,
+                const char *func,
+                const char *format, ...) _printf_attr_(5,6);
 
 int log_metav(
-        int level,
-        const char*file,
-        int line,
-        const char *func,
-        const char *format,
-        va_list ap);
-
-_noreturn_ void log_assert_failed(const char *text, const char *file, int line, const char *func);
-_noreturn_ void log_assert_failed_unreachable(const char *text, const char *file, int line, const char *func);
+                int level,
+                const char*file,
+                int line,
+                const char *func,
+                const char *format,
+                va_list ap);
+
+int log_struct_internal(
+                int level,
+                const char *file,
+                int line,
+                const char *func,
+                const char *format, ...) _sentinel_;
+
+int log_oom_internal(
+                const char *file,
+                int line,
+                const char *func);
 
 /* This modifies the buffer passed! */
 int log_dump_internal(
-        int level,
-        const char*file,
-        int line,
-        const char *func,
-        char *buffer);
+                int level,
+                const char*file,
+                int line,
+                const char *func,
+                char *buffer);
+
+_noreturn_ void log_assert_failed(
+                const char *text,
+                const char *file,
+                int line,
+                const char *func);
+
+_noreturn_ void log_assert_failed_unreachable(
+                const char *text,
+                const char *file,
+                int line,
+                const char *func);
 
 #define log_full(level, ...) log_meta(level,   __FILE__, __LINE__, __func__, __VA_ARGS__)
 
@@ -103,8 +124,9 @@ int log_dump_internal(
 #define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
 #define log_error(...)   log_meta(LOG_ERR,     __FILE__, __LINE__, __func__, __VA_ARGS__)
 
-int __log_oom(const char *file, int line, const char *func);
-#define log_oom() __log_oom(__FILE__, __LINE__, __func__)
+#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__)
+
+#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__)
 
 /* This modifies the buffer passed! */
 #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index c86f69c..71c7518 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -25,6 +25,8 @@
 
 #include "log.h"
 #include "util.h"
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 
 int main(int argc, char *argv[]) {
         const char *verb;
@@ -66,9 +68,17 @@ int main(int argc, char *argv[]) {
         execute_directory(SYSTEM_SLEEP_PATH, NULL, arguments);
 
         if (streq(argv[1], "suspend"))
-                log_info("Suspending system...");
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_START),
+                           "MESSAGE=Suspending system...",
+                           "SLEEP=suspend",
+                           NULL);
         else
-                log_info("Hibernating system...");
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_START),
+                           "MESSAGE=Hibernating system...",
+                           "SLEEP=hibernate",
+                           NULL);
 
         fputs(verb, f);
         fputc('\n', f);
@@ -77,9 +87,17 @@ int main(int argc, char *argv[]) {
         r = ferror(f) ? -errno : 0;
 
         if (streq(argv[1], "suspend"))
-                log_info("System resumed.");
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_STOP),
+                           "MESSAGE=System resumed.",
+                           "SLEEP=suspend",
+                           NULL);
         else
-                log_info("System thawed.");
+                log_struct(LOG_INFO,
+                           "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_SLEEP_STOP),
+                           "MESSAGE=System thawed.",
+                           "SLEEP=hibernate",
+                           NULL);
 
         arguments[1] = (char*) "post";
         execute_directory(SYSTEM_SLEEP_PATH, NULL, arguments);
diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 27fa479..126d83c 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -56,6 +56,7 @@ int sd_id128_get_boot(sd_id128_t *ret);
  * times. It is hence not a good idea to call this macro with an
  * expensive function as paramater or an expression with side
  * effects */
+
 #define SD_ID128_FORMAT_STR "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
 #define SD_ID128_FORMAT_VAL(x) (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15]
 
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
index 9b485b9..01616c8 100644
--- a/src/systemd/sd-messages.h
+++ b/src/systemd/sd-messages.h
@@ -28,12 +28,35 @@
 extern "C" {
 #endif
 
-#define SD_MESSAGE_JOURNAL_START   SD_ID128_MAKE(f7,73,79,a8,49,0b,40,8b,be,5f,69,40,50,5a,77,7b)
-#define SD_MESSAGE_JOURNAL_STOP    SD_ID128_MAKE(d9,3f,b3,c9,c2,4d,45,1a,97,ce,a6,15,ce,59,c0,0b)
-#define SD_MESSAGE_JOURNAL_DROPPED SD_ID128_MAKE(a5,96,d6,fe,7b,fa,49,94,82,8e,72,30,9e,95,d6,1e)
-#define SD_MESSAGE_JOURNAL_MISSED  SD_ID128_MAKE(e9,bf,28,e6,e8,34,48,1b,b6,f4,8f,54,8a,d1,36,06)
+#define SD_MESSAGE_JOURNAL_START    SD_ID128_MAKE(f7,73,79,a8,49,0b,40,8b,be,5f,69,40,50,5a,77,7b)
+#define SD_MESSAGE_JOURNAL_STOP     SD_ID128_MAKE(d9,3f,b3,c9,c2,4d,45,1a,97,ce,a6,15,ce,59,c0,0b)
+#define SD_MESSAGE_JOURNAL_DROPPED  SD_ID128_MAKE(a5,96,d6,fe,7b,fa,49,94,82,8e,72,30,9e,95,d6,1e)
+#define SD_MESSAGE_JOURNAL_MISSED   SD_ID128_MAKE(e9,bf,28,e6,e8,34,48,1b,b6,f4,8f,54,8a,d1,36,06)
 
-#define SD_MESSAGE_COREDUMP        SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
+#define SD_MESSAGE_COREDUMP         SD_ID128_MAKE(fc,2e,22,bc,6e,e6,47,b6,b9,07,29,ab,34,a2,50,b1)
+
+#define SD_MESSAGE_SESSION_START    SD_ID128_MAKE(8d,45,62,0c,1a,43,48,db,b1,74,10,da,57,c6,0c,66)
+#define SD_MESSAGE_SESSION_STOP     SD_ID128_MAKE(33,54,93,94,24,b4,45,6d,98,02,ca,83,33,ed,42,4a)
+#define SD_MESSAGE_SEAT_START       SD_ID128_MAKE(fc,be,fc,5d,a2,3d,42,80,93,f9,7c,82,a9,29,0f,7b)
+#define SD_MESSAGE_SEAT_STOP        SD_ID128_MAKE(e7,85,2b,fe,46,78,4e,d0,ac,cd,e0,4b,c8,64,c2,d5)
+
+#define SD_MESSAGE_TIME_CHANGE      SD_ID128_MAKE(c7,a7,87,07,9b,35,4e,aa,a9,e7,7b,37,18,93,cd,27)
+#define SD_MESSAGE_TIMEZONE_CHANGE  SD_ID128_MAKE(45,f8,2f,4a,ef,7a,4b,bf,94,2c,e8,61,d1,f2,09,90)
+
+#define SD_MESSAGE_STARTUP_FINISHED SD_ID128_MAKE(b0,7a,24,9c,d0,24,41,4a,82,dd,00,cd,18,13,78,ff)
+
+#define SD_MESSAGE_SLEEP_START      SD_ID128_MAKE(6b,bd,95,ee,97,79,41,e4,97,c4,8b,e2,7c,25,41,28)
+#define SD_MESSAGE_SLEEP_STOP       SD_ID128_MAKE(88,11,e6,df,2a,8e,40,f5,8a,94,ce,a2,6f,8e,bf,14)
+
+#define SD_MESSAGE_SHUTDOWN         SD_ID128_MAKE(98,26,88,66,d1,d5,4a,49,9c,4e,98,92,1d,93,bc,40)
+
+#define SD_MESSAGE_UNIT_STARTING    SD_ID128_MAKE(7d,49,58,e8,42,da,4a,75,8f,6c,1c,dc,7b,36,dc,c5)
+#define SD_MESSAGE_UNIT_STARTED     SD_ID128_MAKE(39,f5,34,79,d3,a0,45,ac,8e,11,78,62,48,23,1f,bf)
+#define SD_MESSAGE_UNIT_STOPPING    SD_ID128_MAKE(de,5b,42,6a,63,be,47,a7,b6,ac,3e,aa,c8,2e,2f,6f)
+#define SD_MESSAGE_UNIT_STOPPED     SD_ID128_MAKE(9d,1a,aa,27,d6,01,40,bd,96,36,54,38,aa,d2,02,86)
+#define SD_MESSAGE_UNIT_FAILED      SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d)
+#define SD_MESSAGE_UNIT_RELOADING   SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d)
+#define SD_MESSAGE_UNIT_RELOADED    SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d)
 
 #ifdef __cplusplus
 }
diff --git a/src/test/test-log.c b/src/test/test-log.c
new file mode 100644
index 0000000..cc924fa
--- /dev/null
+++ b/src/test/test-log.c
@@ -0,0 +1,46 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2012 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stddef.h>
+#include <unistd.h>
+
+#include "log.h"
+
+int main(int argc, char* argv[]) {
+
+        log_set_target(LOG_TARGET_CONSOLE);
+        log_open();
+
+        log_struct(LOG_INFO,
+                   "MESSAGE=Waldo PID=%lu", (unsigned long) getpid(),
+                   "SERVICE=piepapo",
+                   NULL);
+
+        log_set_target(LOG_TARGET_JOURNAL);
+        log_open();
+
+        log_struct(LOG_INFO,
+                   "MESSAGE=Foobar PID=%lu", (unsigned long) getpid(),
+                   "SERVICE=foobar",
+                   NULL);
+
+        return 0;
+}
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 09fd808..34d287b 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -25,6 +25,8 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "systemd/sd-id128.h"
+#include "systemd/sd-messages.h"
 #include "util.h"
 #include "strv.h"
 #include "dbus-common.h"
@@ -701,7 +703,11 @@ static DBusHandlerResult timedate_message_handler(
                                 hwclock_set_time(tm);
                         }
 
-                        log_info("Changed timezone to '%s'.", tz.zone);
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_TIMEZONE_CHANGE),
+                                   "TIMEZONE=%s", tz.zone,
+                                   "MESSAGE=Changed timezone to '%s'.", tz.zone,
+                                   NULL);
 
                         changed = bus_properties_changed_new(
                                         "/org/freedesktop/timedate1",
@@ -842,7 +848,11 @@ static DBusHandlerResult timedate_message_handler(
 
                         hwclock_set_time(tm);
 
-                        log_info("Changed local time to %s", ctime(&ts.tv_sec));
+                        log_struct(LOG_INFO,
+                                   "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(SD_MESSAGE_TIME_CHANGE),
+                                   "REALTIME=%llu", (unsigned long long) timespec_load(&ts),
+                                   "MESSAGE=Changed local time to %s", ctime(&ts.tv_sec),
+                                   NULL);
                 }
         } else if (dbus_message_is_method_call(message, "org.freedesktop.timedate1", "SetNTP")) {
                 dbus_bool_t ntp;

commit 88fae6e0441d4195e089434f07d3e7fd811d6297
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Aug 23 18:47:01 2012 +0200

    shared: in code that might get called from suid programs use __secure_getenv() rather than getenv()
    
    It's better to be safe than sorry.

diff --git a/TODO b/TODO
index b1b57d6..a4643d7 100644
--- a/TODO
+++ b/TODO
@@ -65,8 +65,6 @@ Features:
 
 * maybe make systemd-detect-virt suid? or use fscaps?
 
-* consider using __secure_getenv() instead of getenv() in libs
-
 * man: document in ExecStart= explicitly that we don't take shell command lines, only executable names with arguments
 
 * shutdown: don't read-only mount anything when running in container
@@ -505,6 +503,8 @@ Regularly:
 
 * set_put(), hashmap_put() return values check. i.e. == 0 doesn't free()!
 
+* use __secure_getenv() instead of getenv() where appropriate
+
 Scheduled for removal (or fixing):
 
 * xxxOverridable dependencies
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 9db172b..1fc7148 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -955,12 +955,12 @@ static DBusConnection* manager_bus_connect_private(Manager *m, DBusBusType type)
 
         switch (type) {
         case DBUS_BUS_SYSTEM:
-                address = getenv("DBUS_SYSTEM_BUS_ADDRESS");
+                address = __secure_getenv("DBUS_SYSTEM_BUS_ADDRESS");
                 if (!address || !address[0])
                         address = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS;
                 break;
         case DBUS_BUS_SESSION:
-                address = getenv("DBUS_SESSION_BUS_ADDRESS");
+                address = __secure_getenv("DBUS_SESSION_BUS_ADDRESS");
                 if (!address || !address[0])
                         address = DBUS_SESSION_BUS_DEFAULT_ADDRESS;
                 break;
@@ -1077,7 +1077,7 @@ static int bus_init_private(Manager *m) {
                 const char *e;
                 char *p;
 
-                e = getenv("XDG_RUNTIME_DIR");
+                e = __secure_getenv("XDG_RUNTIME_DIR");
                 if (!e)
                         return 0;
 
diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c
index 07a24d5..1a74808 100644
--- a/src/libudev/libudev.c
+++ b/src/libudev/libudev.c
@@ -191,7 +191,7 @@ _public_ struct udev *udev_new(void)
         }
 
         /* environment overrides config */
-        env = getenv("UDEV_LOG");
+        env = __secure_getenv("UDEV_LOG");
         if (env != NULL)
                 udev_set_log_priority(udev, util_log_priority(env));
 
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c
index da2dc2e..8d7c462 100644
--- a/src/shared/dbus-common.c
+++ b/src/shared/dbus-common.c
@@ -121,7 +121,7 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, bool *_private, DBusError
                          * try via XDG_RUNTIME_DIR first, then
                          * fallback to normal bus access */
 
-                        e = getenv("XDG_RUNTIME_DIR");
+                        e = __secure_getenv("XDG_RUNTIME_DIR");
                         if (e) {
                                 char *p;
 
diff --git a/src/shared/log.c b/src/shared/log.c
index 1cbc9d6..4fc430e 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -688,21 +688,21 @@ int log_set_max_level_from_string(const char *e) {
 void log_parse_environment(void) {
         const char *e;
 
-        if ((e = getenv("SYSTEMD_LOG_TARGET")))
-                if (log_set_target_from_string(e) < 0)
-                        log_warning("Failed to parse log target %s. Ignoring.", e);
+        e = __secure_getenv("SYSTEMD_LOG_TARGET");
+        if (e && log_set_target_from_string(e) < 0)
+                log_warning("Failed to parse log target %s. Ignoring.", e);
 
-        if ((e = getenv("SYSTEMD_LOG_LEVEL")))
-                if (log_set_max_level_from_string(e) < 0)
-                        log_warning("Failed to parse log level %s. Ignoring.", e);
+        e = __secure_getenv("SYSTEMD_LOG_LEVEL");
+        if (e && log_set_max_level_from_string(e) < 0)
+                log_warning("Failed to parse log level %s. Ignoring.", e);
 
-        if ((e = getenv("SYSTEMD_LOG_COLOR")))
-                if (log_show_color_from_string(e) < 0)
-                        log_warning("Failed to parse bool %s. Ignoring.", e);
+        e = __secure_getenv("SYSTEMD_LOG_COLOR");
+        if (e && log_show_color_from_string(e) < 0)
+                log_warning("Failed to parse bool %s. Ignoring.", e);
 
-        if ((e = getenv("SYSTEMD_LOG_LOCATION")))
-                if (log_show_location_from_string(e) < 0)
-                        log_warning("Failed to parse bool %s. Ignoring.", e);
+        e = __secure_getenv("SYSTEMD_LOG_LOCATION");
+        if (e && log_show_location_from_string(e) < 0)
+                log_warning("Failed to parse bool %s. Ignoring.", e);
 }
 
 LogTarget log_get_target(void) {



More information about the systemd-commits mailing list