chiark / gitweb /
journal: generate structured journal messages for a number of events
[elogind.git] / src / timedate / timedated.c
index 5387699bf316b1d1830fe1f7989b281f40cb6df1..34d287b2a14c6f85328db0f805e4315fdf7bd009 100644 (file)
@@ -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"
@@ -153,7 +155,7 @@ static void verify_timezone(void) {
 
         p = strappend("/usr/share/zoneinfo/", tz.zone);
         if (!p) {
-                log_error("Out of memory");
+                log_oom();
                 return;
         }
 
@@ -219,10 +221,8 @@ static int write_data_timezone(void) {
         }
 
         p = strappend("/usr/share/zoneinfo/", tz.zone);
-        if (!p) {
-                log_error("Out of memory");
-                return -ENOMEM;
-        }
+        if (!p)
+                return log_oom();
 
         r = symlink_or_copy_atomic(p, "/etc/localtime");
         free(p);
@@ -341,7 +341,7 @@ static char** get_ntp_services(void) {
 
                         q = strv_append(r, l);
                         if (!q) {
-                                log_error("Out of memory");
+                                log_oom();
                                 break;
                         }
 
@@ -354,7 +354,7 @@ static char** get_ntp_services(void) {
 
         strv_free(files);
 
-        return r;
+        return strv_uniq(r);
 }
 
 static int read_ntp(DBusConnection *bus) {
@@ -379,16 +379,14 @@ static int read_ntp(DBusConnection *bus) {
                                 "org.freedesktop.systemd1.Manager",
                                 "GetUnitFileState");
                 if (!m) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
+                        r = log_oom();
                         goto finish;
                 }
 
                 if (!dbus_message_append_args(m,
                                               DBUS_TYPE_STRING, i,
                                               DBUS_TYPE_INVALID)) {
-                        log_error("Could not append arguments to message.");
-                        r = -ENOMEM;
+                        r = log_oom();
                         goto finish;
                 }
 
@@ -705,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",
@@ -846,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;
@@ -943,8 +949,7 @@ static int connect_bus(DBusConnection **_bus) {
 
         if (!dbus_connection_register_object_path(bus, "/org/freedesktop/timedate1", &timedate_vtable, NULL) ||
             !dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
-                log_error("Not enough memory");
-                r = -ENOMEM;
+                r = log_oom();
                 goto fail;
         }