1ff636
From 467145adad739b0426501d2fd7ce1c0afe977e67 Mon Sep 17 00:00:00 2001
1ff636
From: Lukas Nykryn <lnykryn@redhat.com>
1ff636
Date: Thu, 16 Apr 2015 15:22:57 +0200
1ff636
Subject: [PATCH] timedated: fix enable/disable reversal
1ff636
1ff636
The state was flipped later,
1ff636
but the enable/disable routine made use of the state to decide
1ff636
what to do.
1ff636
1ff636
context_enable_ntp() and context_start_ntp() now get the desired
1ff636
state directly, so the Context parameter can be removed.
1ff636
1ff636
(based on 81b843990297ad8c813c531fccd8da30bb715bd6)
1ff636
---
23b3cf
 src/timedate/timedated.c | 50 +++++++++++++++-------------------------
1ff636
 1 file changed, 18 insertions(+), 32 deletions(-)
1ff636
1ff636
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
Pablo Greco 48fc63
index c3113b081e..f875149364 100644
1ff636
--- a/src/timedate/timedated.c
1ff636
+++ b/src/timedate/timedated.c
1ff636
@@ -280,39 +280,26 @@ static int context_read_ntp(Context *c, sd_bus *bus) {
1ff636
         return 0;
1ff636
 }
1ff636
 
1ff636
-static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
1ff636
+static int context_start_ntp(sd_bus *bus, sd_bus_error *error, bool enabled) {
1ff636
         _cleanup_strv_free_ char **l = NULL;
1ff636
         char **i;
1ff636
         int r;
1ff636
 
1ff636
-        assert(c);
1ff636
         assert(bus);
1ff636
         assert(error);
1ff636
 
1ff636
         l = get_ntp_services();
1ff636
         STRV_FOREACH(i, l) {
1ff636
 
1ff636
-                if (c->use_ntp)
1ff636
-                        r = sd_bus_call_method(
1ff636
-                                        bus,
1ff636
-                                        "org.freedesktop.systemd1",
1ff636
-                                        "/org/freedesktop/systemd1",
1ff636
-                                        "org.freedesktop.systemd1.Manager",
1ff636
-                                        "StartUnit",
1ff636
-                                        error,
1ff636
-                                        NULL,
1ff636
-                                        "ss", *i, "replace");
1ff636
-                else
1ff636
-                        r = sd_bus_call_method(
1ff636
-                                        bus,
1ff636
-                                        "org.freedesktop.systemd1",
1ff636
-                                        "/org/freedesktop/systemd1",
1ff636
-                                        "org.freedesktop.systemd1.Manager",
1ff636
-                                        "StopUnit",
1ff636
-                                        error,
1ff636
-                                        NULL,
1ff636
-                                        "ss", *i, "replace");
1ff636
-
1ff636
+                r = sd_bus_call_method(
1ff636
+                                bus,
1ff636
+                                "org.freedesktop.systemd1",
1ff636
+                                "/org/freedesktop/systemd1",
1ff636
+                                "org.freedesktop.systemd1.Manager",
1ff636
+                                enabled ? "StartUnit" : "StopUnit",
1ff636
+                                error,
1ff636
+                                NULL,
1ff636
+                                "ss", *i, "replace");
1ff636
                 if (r < 0) {
1ff636
                         if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND) ||
1ff636
                             sd_bus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed") ||
1ff636
@@ -332,18 +319,17 @@ static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
1ff636
         return -ENOTSUP;
1ff636
 }
1ff636
 
1ff636
-static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
1ff636
+static int context_enable_ntp(sd_bus *bus, sd_bus_error *error, bool enabled) {
1ff636
         _cleanup_strv_free_ char **l = NULL;
1ff636
         char **i;
1ff636
         int r;
1ff636
 
1ff636
-        assert(c);
1ff636
         assert(bus);
1ff636
         assert(error);
1ff636
 
1ff636
         l = get_ntp_services();
1ff636
         STRV_FOREACH(i, l) {
1ff636
-                if (c->use_ntp)
1ff636
+                if (enabled)
1ff636
                         r = sd_bus_call_method(
1ff636
                                         bus,
1ff636
                                         "org.freedesktop.systemd1",
1ff636
@@ -662,15 +648,15 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
1ff636
 }
1ff636
 
1ff636
 static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
1ff636
-        int ntp, interactive;
1ff636
+        int enabled, interactive;
1ff636
         Context *c = userdata;
1ff636
         int r;
1ff636
 
1ff636
-        r = sd_bus_message_read(m, "bb", &ntp, &interactive);
1ff636
+        r = sd_bus_message_read(m, "bb", &enabled, &interactive);
1ff636
         if (r < 0)
1ff636
                 return r;
1ff636
 
1ff636
-        if ((bool)ntp == c->use_ntp)
1ff636
+        if ((bool)enabled == c->use_ntp)
1ff636
                 return sd_bus_reply_method_return(m, NULL);
1ff636
 
1ff636
         r = bus_verify_polkit_async(m, CAP_SYS_TIME, "org.freedesktop.timedate1.set-ntp", interactive, &c->polkit_registry, error);
1ff636
@@ -679,15 +665,15 @@ static int method_set_ntp(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus
1ff636
         if (r == 0)
1ff636
                 return 1;
1ff636
 
1ff636
-        r = context_enable_ntp(c, bus, error);
1ff636
+        r = context_enable_ntp(bus, error, enabled);
1ff636
         if (r < 0)
1ff636
                 return r;
1ff636
 
1ff636
-        r = context_start_ntp(c, bus, error);
1ff636
+        r = context_start_ntp(bus, error, enabled);
1ff636
         if (r < 0)
1ff636
                 return r;
1ff636
 
1ff636
-        c->use_ntp = ntp;
1ff636
+        c->use_ntp = enabled;
1ff636
 
1ff636
         log_info("Set NTP to %s", c->use_ntp ? "enabled" : "disabled");
1ff636