chiark / gitweb /
fix hwclock_apply_localtime_delta() to properly handle negative TZ offset
[elogind.git] / src / timedated.c
index daa3d9c821a5dc400339310d2aa29fb96b73da05..4abcf1af73df3a88f0a48b3383cfabd15077ee62 100644 (file)
@@ -33,9 +33,7 @@
 #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
 #define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
 
-#define INTROSPECTION                                                   \
-        DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
-        "<node>\n"                                                      \
+#define INTERFACE                                                       \
         " <interface name=\"org.freedesktop.timedate1\">\n"             \
         "  <property name=\"Timezone\" type=\"s\" access=\"read\"/>\n"  \
         "  <property name=\"LocalRTC\" type=\"b\" access=\"read\"/>\n"  \
         "  </method>\n"                                                 \
         "  <method name=\"SetLocalRTC\">\n"                             \
         "   <arg name=\"local_rtc\" type=\"b\" direction=\"in\"/>\n"    \
-        "   <arg name=\"fix_system\" type=\"b\" direction=\"in\"/>\n" \
+        "   <arg name=\"fix_system\" type=\"b\" direction=\"in\"/>\n"   \
         "   <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
         "  </method>\n"                                                 \
-        " </interface>\n"                                               \
+        " </interface>\n"
+
+#define INTROSPECTION                                                   \
+        DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
+        "<node>\n"                                                      \
+        INTERFACE                                                       \
         BUS_PROPERTIES_INTERFACE                                        \
         BUS_INTROSPECTABLE_INTERFACE                                    \
         BUS_PEER_INTERFACE                                              \
@@ -63,6 +66,8 @@
         BUS_GENERIC_INTERFACES_LIST             \
         "org.freedesktop.locale1\0"
 
+const char timedate_interface[] _introspect_("timedate1") = INTERFACE;
+
 static char *zone = NULL;
 static bool local_rtc = false;
 
@@ -327,7 +332,7 @@ static DBusHandlerResult timedate_message_handler(
                                 struct tm *tm;
 
                                 /* 2. Teach kernel new timezone */
-                                hwclock_apply_localtime_delta();
+                                hwclock_apply_localtime_delta(NULL);
 
                                 /* 3. Sync RTC from system clock, with the new delta */
                                 assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
@@ -377,7 +382,7 @@ static DBusHandlerResult timedate_message_handler(
 
                         /* 2. Teach kernel new timezone */
                         if (local_rtc)
-                                hwclock_apply_localtime_delta();
+                                hwclock_apply_localtime_delta(NULL);
                         else
                                 hwclock_reset_localtime_delta();
 
@@ -527,7 +532,7 @@ static int connect_bus(DBusConnection **_bus) {
 
         bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
         if (!bus) {
-                log_error("Failed to get system D-Bus connection: %s", error.message);
+                log_error("Failed to get system D-Bus connection: %s", bus_error_message(&error));
                 r = -ECONNREFUSED;
                 goto fail;
         }
@@ -538,8 +543,15 @@ static int connect_bus(DBusConnection **_bus) {
                 goto fail;
         }
 
-        if (dbus_bus_request_name(bus, "org.freedesktop.timedate1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
-                log_error("Failed to register name on bus: %s", error.message);
+        r = dbus_bus_request_name(bus, "org.freedesktop.timedate1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to register name on bus: %s", bus_error_message(&error));
+                r = -EEXIST;
+                goto fail;
+        }
+
+        if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)  {
+                log_error("Failed to acquire name.");
                 r = -EEXIST;
                 goto fail;
         }
@@ -566,6 +578,14 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
+        if (argc == 2 && streq(argv[1], "--introspect")) {
+                fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
+                      "<node>\n", stdout);
+                fputs(timedate_interface, stdout);
+                fputs("</node>\n", stdout);
+                return 0;
+        }
+
         if (argc != 1) {
                 log_error("This program takes no arguments.");
                 r = -EINVAL;