teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0130-timedated-fix-enable-disable-reversal.patch

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