diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-08-24 22:21:20 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-09-03 18:59:04 -0700 |
commit | 877d54e9b09e093c2102f519a84e2a52637ae035 (patch) | |
tree | ff7926d33cd29b9e2930cb401a7be412c7724241 /src/login | |
parent | 88fae6e0441d4195e089434f07d3e7fd811d6297 (diff) |
journal: generate structured journal messages for a number of events
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/logind-dbus.c | 45 | ||||
-rw-r--r-- | src/login/logind-seat.c | 14 | ||||
-rw-r--r-- | src/login/logind-session.c | 20 |
3 files changed, 72 insertions, 7 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index ae9671bb1e..af62d87821 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 045712192a..937315ebf1 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 16d4955d5d..77462a8d15 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); |