teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
Blob Blame History Raw
From 29b5cd796981c42666189501b8bc41f9da2d0f52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 21 Mar 2015 19:21:17 -0400
Subject: [PATCH] timedated: fix enable/disable reversal

Bug introduced in 984f1b1d1b. The state was flipped later,
but the enable/disable routine made use of the state to decide
what to do.

context_enable_ntp() and context_start_ntp() now get the desired
state directly, so the Context parameter can be removed.

(cherry picked from commit 81b843990297ad8c813c531fccd8da30bb715bd6)
---
 src/timedate/timedated.c | 59 +++++++++++++++++-------------------------------
 1 file changed, 21 insertions(+), 38 deletions(-)

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index bee66af24a..f2d23f34b1 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -225,38 +225,23 @@ static int context_read_ntp(Context *c, sd_bus *bus) {
         return 0;
 }
 
-static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
+static int context_start_ntp(sd_bus *bus, sd_bus_error *error, bool enabled) {
         int r;
 
-        assert(c);
         assert(bus);
         assert(error);
 
-        if (c->use_ntp)
-                r = sd_bus_call_method(
-                                bus,
-                                "org.freedesktop.systemd1",
-                                "/org/freedesktop/systemd1",
-                                "org.freedesktop.systemd1.Manager",
-                                "StartUnit",
-                                error,
-                                NULL,
-                                "ss",
-                                "systemd-timesyncd.service",
-                                "replace");
-        else
-                r = sd_bus_call_method(
-                                bus,
-                                "org.freedesktop.systemd1",
-                                "/org/freedesktop/systemd1",
-                                "org.freedesktop.systemd1.Manager",
-                                "StopUnit",
-                                error,
-                                NULL,
-                                "ss",
-                                "systemd-timesyncd.service",
-                                "replace");
-
+        r = sd_bus_call_method(
+                bus,
+                "org.freedesktop.systemd1",
+                "/org/freedesktop/systemd1",
+                "org.freedesktop.systemd1.Manager",
+                enabled ? "StartUnit" : "StopUnit",
+                error,
+                NULL,
+                "ss",
+                "systemd-timesyncd.service",
+                "replace");
         if (r < 0) {
                 if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND) ||
                     sd_bus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed") ||
@@ -269,14 +254,13 @@ static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
         return 0;
 }
 
-static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
+static int context_enable_ntp(sd_bus *bus, sd_bus_error *error, bool enabled) {
         int r;
 
-        assert(c);
         assert(bus);
         assert(error);
 
-        if (c->use_ntp)
+        if (enabled)
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.systemd1",
@@ -592,15 +576,15 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
 }
 
 static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
-        int ntp, interactive;
+        int enabled, interactive;
         Context *c = userdata;
         int r;
 
-        r = sd_bus_message_read(m, "bb", &ntp, &interactive);
+        r = sd_bus_message_read(m, "bb", &enabled, &interactive);
         if (r < 0)
                 return r;
 
-        if ((bool)ntp == c->use_ntp)
+        if ((bool)enabled == c->use_ntp)
                 return sd_bus_reply_method_return(m, NULL);
 
         r = bus_verify_polkit_async(m, CAP_SYS_TIME, "org.freedesktop.timedate1.set-ntp", interactive, &c->polkit_registry, error);
@@ -609,17 +593,16 @@ static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus
         if (r == 0)
                 return 1;
 
-        r = context_enable_ntp(c, bus, error);
+        r = context_enable_ntp(bus, error, enabled);
         if (r < 0)
                 return r;
 
-        r = context_start_ntp(c, bus, error);
+        r = context_start_ntp(bus, error, enabled);
         if (r < 0)
                 return r;
 
-        c->use_ntp = ntp;
-
-        log_info("Set NTP to %s", c->use_ntp ? "enabled" : "disabled");
+        c->use_ntp = enabled;
+        log_info("Set NTP to %s", enabled ? "enabled" : "disabled");
 
         sd_bus_emit_properties_changed(bus, "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "NTP", NULL);