[gnome-settings-daemon] datetime: Simplify NTP handling for distros



commit 9c65d9bfcbc506329f412074a83ae84fb9c4b675
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Apr 28 15:42:28 2011 +0100

    datetime: Simplify NTP handling for distros
    
    No more silent bugs on unsupported distros.

 plugins/datetime/Makefile.am                     |    6 +-
 plugins/datetime/gsd-datetime-mechanism-debian.c |   89 ++++++++++
 plugins/datetime/gsd-datetime-mechanism-debian.h |   27 +++
 plugins/datetime/gsd-datetime-mechanism-fedora.c |  186 ++++++++++++++++++++++
 plugins/datetime/gsd-datetime-mechanism-fedora.h |   31 ++++
 plugins/datetime/gsd-datetime-mechanism.c        |  185 +++-------------------
 6 files changed, 363 insertions(+), 161 deletions(-)
---
diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am
index ea973e0..990eeb6 100644
--- a/plugins/datetime/Makefile.am
+++ b/plugins/datetime/Makefile.am
@@ -22,7 +22,11 @@ endif
 gsd_datetime_mechanism_SOURCES =		\
 	gsd-datetime-mechanism.c		\
 	gsd-datetime-mechanism.h		\
-	gsd-datetime-mechanism-main.c	\
+	gsd-datetime-mechanism-fedora.c		\
+	gsd-datetime-mechanism-fedora.h		\
+	gsd-datetime-mechanism-debian.c		\
+	gsd-datetime-mechanism-debian.h		\
+	gsd-datetime-mechanism-main.c		\
 	system-timezone.c			\
 	system-timezone.h
 
diff --git a/plugins/datetime/gsd-datetime-mechanism-debian.c b/plugins/datetime/gsd-datetime-mechanism-debian.c
new file mode 100644
index 0000000..4fb0e36
--- /dev/null
+++ b/plugins/datetime/gsd-datetime-mechanism-debian.c
@@ -0,0 +1,89 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ * Copyright (C) 2011 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "gsd-datetime-mechanism-debian.h"
+#include "gsd-datetime-mechanism.h"
+
+gboolean
+_get_using_ntp_debian (DBusGMethodInvocation   *context)
+{
+        gboolean can_use_ntp;
+        gboolean is_using_ntp;
+
+        can_use_ntp = FALSE;
+        is_using_ntp = FALSE;
+
+        dbus_g_method_return (context, can_use_ntp, is_using_ntp);
+        return TRUE;
+}
+
+gboolean
+_set_using_ntp_debian  (DBusGMethodInvocation   *context,
+                        gboolean                 using_ntp)
+{
+        GError *error;
+        int exit_status;
+        char *cmd;
+
+        error = NULL;
+
+        cmd = g_strconcat ("/usr/sbin/update-rc.d ntp ", using_ntp ? "enable" : "disable", NULL);
+
+        if (!g_spawn_command_line_sync (cmd,
+                                        NULL, NULL, &exit_status, &error)) {
+                GError *error2;
+                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error spawning '%s': %s", cmd, error->message);
+                g_error_free (error);
+                dbus_g_method_return_error (context, error2);
+                g_error_free (error2);
+                g_free (cmd);
+                return FALSE;
+        }
+
+        g_free (cmd);
+
+        cmd = g_strconcat ("/usr/sbin/service ntp ", using_ntp ? "restart" : "stop", NULL);;
+
+        if (!g_spawn_command_line_sync (cmd,
+                                        NULL, NULL, &exit_status, &error)) {
+                GError *error2;
+                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error spawning '%s': %s", cmd, error->message);
+                g_error_free (error);
+                dbus_g_method_return_error (context, error2);
+                g_error_free (error2);
+                g_free (cmd);
+                return FALSE;
+        }
+
+        g_free (cmd);
+
+        dbus_g_method_return (context);
+        return TRUE;
+}
+
diff --git a/plugins/datetime/gsd-datetime-mechanism-debian.h b/plugins/datetime/gsd-datetime-mechanism-debian.h
new file mode 100644
index 0000000..ca2ad60
--- /dev/null
+++ b/plugins/datetime/gsd-datetime-mechanism-debian.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ * Copyright (C) 2011 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+gboolean _get_using_ntp_debian (DBusGMethodInvocation   *context);
+gboolean _set_using_ntp_debian  (DBusGMethodInvocation   *context,
+                                 gboolean                 using_ntp);
diff --git a/plugins/datetime/gsd-datetime-mechanism-fedora.c b/plugins/datetime/gsd-datetime-mechanism-fedora.c
new file mode 100644
index 0000000..2b9221f
--- /dev/null
+++ b/plugins/datetime/gsd-datetime-mechanism-fedora.c
@@ -0,0 +1,186 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ * Copyright (C) 2011 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <string.h>
+
+#include "gsd-datetime-mechanism-fedora.h"
+#include "gsd-datetime-mechanism.h"
+
+gboolean
+_get_using_ntp_fedora  (DBusGMethodInvocation   *context)
+{
+        int exit_status;
+        GError *error = NULL;
+        gboolean can_use_ntp;
+        gboolean is_using_ntp;
+
+        if (g_file_test ("/etc/ntp.conf", G_FILE_TEST_EXISTS)) {
+                can_use_ntp = TRUE;
+                if (!g_spawn_command_line_sync ("/sbin/service ntpd status",
+                                                NULL, NULL, &exit_status, &error)) {
+                        GError *error2;
+                        error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                              GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                              "Error spawning /sbin/service: %s", error->message);
+                        g_error_free (error);
+                        dbus_g_method_return_error (context, error2);
+                        g_error_free (error2);
+                        return FALSE;
+                }
+                if (exit_status == 0)
+                        is_using_ntp = TRUE;
+                else
+                        is_using_ntp = FALSE;
+        }
+        else {
+                can_use_ntp = FALSE;
+                is_using_ntp = FALSE;
+        }
+
+        dbus_g_method_return (context, can_use_ntp, is_using_ntp);
+        return TRUE;
+}
+
+gboolean
+_set_using_ntp_fedora  (DBusGMethodInvocation   *context,
+                        gboolean                 using_ntp)
+{
+        GError *error;
+        int exit_status;
+        char *cmd;
+
+        error = NULL;
+
+        cmd = g_strconcat ("/sbin/chkconfig ntpd --level 2345", using_ntp ? "on" : "off", NULL);
+
+        if (!g_spawn_command_line_sync (cmd,
+                                        NULL, NULL, &exit_status, &error)) {
+                GError *error2;
+                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error spawning '%s': %s", cmd, error->message);
+                g_error_free (error);
+                dbus_g_method_return_error (context, error2);
+                g_error_free (error2);
+                g_free (cmd);
+                return FALSE;
+        }
+
+        g_free (cmd);
+
+        cmd = g_strconcat ("/sbin/service ntpd ", using_ntp ? "restart" : "stop", NULL);;
+
+        if (!g_spawn_command_line_sync (cmd,
+                                        NULL, NULL, &exit_status, &error)) {
+                GError *error2;
+                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error spawning '%s': %s", cmd, error->message);
+                g_error_free (error);
+                dbus_g_method_return_error (context, error2);
+                g_error_free (error2);
+                g_free (cmd);
+                return FALSE;
+        }
+
+        g_free (cmd);
+
+        dbus_g_method_return (context);
+        return TRUE;
+}
+
+gboolean
+_update_etc_sysconfig_clock_fedora (DBusGMethodInvocation *context, const char *key, const char *value)
+{
+        char **lines;
+        int n;
+        gboolean replaced;
+        char *data;
+        gsize len;
+        GError *error;
+
+        /* On Red Hat / Fedora, the /etc/sysconfig/clock file needs to be kept in sync */
+        if (!g_file_test ("/etc/sysconfig/clock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
+                error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error reading /etc/sysconfig/clock file: %s", "No such file");
+                dbus_g_method_return_error (context, error);
+                g_error_free (error);
+                return FALSE;
+	}
+
+        error = NULL;
+
+        if (!g_file_get_contents ("/etc/sysconfig/clock", &data, &len, &error)) {
+                GError *error2;
+                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                      "Error reading /etc/sysconfig/clock file: %s", error->message);
+                g_error_free (error);
+                dbus_g_method_return_error (context, error2);
+                g_error_free (error2);
+                return FALSE;
+        }
+        replaced = FALSE;
+        lines = g_strsplit (data, "\n", 0);
+        g_free (data);
+
+        for (n = 0; lines[n] != NULL; n++) {
+                if (g_str_has_prefix (lines[n], key)) {
+                        g_free (lines[n]);
+                        lines[n] = g_strdup_printf ("%s%s", key, value);
+                        replaced = TRUE;
+                }
+        }
+        if (replaced) {
+                GString *str;
+
+                str = g_string_new (NULL);
+                for (n = 0; lines[n] != NULL; n++) {
+                        g_string_append (str, lines[n]);
+                        if (lines[n + 1] != NULL)
+                                g_string_append_c (str, '\n');
+                }
+                data = g_string_free (str, FALSE);
+                len = strlen (data);
+                if (!g_file_set_contents ("/etc/sysconfig/clock", data, len, &error)) {
+                        GError *error2;
+                        error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                              GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                              "Error updating /etc/sysconfig/clock: %s", error->message);
+                        g_error_free (error);
+                        dbus_g_method_return_error (context, error2);
+                        g_error_free (error2);
+                        g_free (data);
+                        return FALSE;
+                }
+                g_free (data);
+        }
+        g_strfreev (lines);
+
+        return TRUE;
+}
+
+
diff --git a/plugins/datetime/gsd-datetime-mechanism-fedora.h b/plugins/datetime/gsd-datetime-mechanism-fedora.h
new file mode 100644
index 0000000..0e30581
--- /dev/null
+++ b/plugins/datetime/gsd-datetime-mechanism-fedora.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ * Copyright (C) 2011 Bastien Nocera <hadess hadess net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+gboolean _get_using_ntp_fedora  (DBusGMethodInvocation   *context);
+gboolean _set_using_ntp_fedora  (DBusGMethodInvocation   *context,
+                                 gboolean                 using_ntp);
+gboolean _update_etc_sysconfig_clock_fedora
+                                (DBusGMethodInvocation *context,
+                                 const char            *key,
+                                 const char            *value);
diff --git a/plugins/datetime/gsd-datetime-mechanism.c b/plugins/datetime/gsd-datetime-mechanism.c
index 2c43a4a..c46c7f2 100644
--- a/plugins/datetime/gsd-datetime-mechanism.c
+++ b/plugins/datetime/gsd-datetime-mechanism.c
@@ -44,6 +44,10 @@
 #include "gsd-datetime-mechanism.h"
 #include "gsd-datetime-mechanism-glue.h"
 
+/* NTP helper functions for various distributions */
+#include "gsd-datetime-mechanism-fedora.h"
+#include "gsd-datetime-mechanism-debian.h"
+
 static gboolean
 do_exit (gpointer user_data)
 {
@@ -386,71 +390,6 @@ _set_date (GsdDatetimeMechanism  *mechanism,
         return TRUE;
 }
 
-static gboolean
-_rh_update_etc_sysconfig_clock (DBusGMethodInvocation *context, const char *key, const char *value)
-{
-        /* On Red Hat / Fedora, the /etc/sysconfig/clock file needs to be kept in sync */
-        if (g_file_test ("/etc/sysconfig/clock", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
-                char **lines;
-                int n;
-                gboolean replaced;
-                char *data;
-                gsize len;
-                GError *error;
-
-                error = NULL;
-
-                if (!g_file_get_contents ("/etc/sysconfig/clock", &data, &len, &error)) {
-                        GError *error2;
-                        error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                              GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                              "Error reading /etc/sysconfig/clock file: %s", error->message);
-                        g_error_free (error);
-                        dbus_g_method_return_error (context, error2);
-                        g_error_free (error2);
-                        return FALSE;
-                }
-                replaced = FALSE;
-                lines = g_strsplit (data, "\n", 0);
-                g_free (data);
-
-                for (n = 0; lines[n] != NULL; n++) {
-                        if (g_str_has_prefix (lines[n], key)) {
-                                g_free (lines[n]);
-                                lines[n] = g_strdup_printf ("%s%s", key, value);
-                                replaced = TRUE;
-                        }
-                }
-                if (replaced) {
-                        GString *str;
-
-                        str = g_string_new (NULL);
-                        for (n = 0; lines[n] != NULL; n++) {
-                                g_string_append (str, lines[n]);
-                                if (lines[n + 1] != NULL)
-                                        g_string_append_c (str, '\n');
-                        }
-                        data = g_string_free (str, FALSE);
-                        len = strlen (data);
-                        if (!g_file_set_contents ("/etc/sysconfig/clock", data, len, &error)) {
-                                GError *error2;
-                                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                                      "Error updating /etc/sysconfig/clock: %s", error->message);
-                                g_error_free (error);
-                                dbus_g_method_return_error (context, error2);
-                                g_error_free (error2);
-                                g_free (data);
-                                return FALSE;
-                        }
-                        g_free (data);
-                }
-                g_strfreev (lines);
-        }
-
-        return TRUE;
-}
-
 /* exported methods */
 
 gboolean
@@ -686,9 +625,9 @@ gsd_datetime_mechanism_set_hardware_clock_using_utc (GsdDatetimeMechanism  *mech
                         return FALSE;
                 }
 
-                if (!_rh_update_etc_sysconfig_clock (context, "UTC=", using_utc ? "true" : "false"))
-                        return FALSE;
-
+                if (g_file_test ("/etc/fedora-release", G_FILE_TEST_EXISTS)) /* Fedora */
+                        if (!_update_etc_sysconfig_clock_fedora (context, "UTC=", using_utc ? "true" : "false"))
+                                return FALSE;
         }
         dbus_g_method_return (context);
         return TRUE;
@@ -698,36 +637,23 @@ gboolean
 gsd_datetime_mechanism_get_using_ntp  (GsdDatetimeMechanism    *mechanism,
                                        DBusGMethodInvocation   *context)
 {
-        int exit_status;
         GError *error = NULL;
-        gboolean can_use_ntp;
-        gboolean is_using_ntp;
+        gboolean ret;
 
-        if (g_file_test ("/etc/ntp.conf", G_FILE_TEST_EXISTS)) {
-                can_use_ntp = TRUE;
-                if (!g_spawn_command_line_sync ("/sbin/service ntpd status",
-                                                NULL, NULL, &exit_status, &error)) {
-                        GError *error2;
-                        error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                              GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                              "Error spawning /sbin/service: %s", error->message);
-                        g_error_free (error);
-                        dbus_g_method_return_error (context, error2);
-                        g_error_free (error2);
-                        return FALSE;
-                }
-                if (exit_status == 0)
-                        is_using_ntp = TRUE;
-                else
-                        is_using_ntp = FALSE;
-        }
+        if (g_file_test ("/etc/fedora-release", G_FILE_TEST_EXISTS)) /* Fedora */
+                ret = _get_using_ntp_fedora (context);
+        else if (g_file_test ("/usr/sbin/update-rc.d", G_FILE_TEST_EXISTS)) /* Debian */
+                ret = _get_using_ntp_debian (context);
         else {
-                can_use_ntp = FALSE;
-                is_using_ntp = FALSE;
+                error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
+                                     GSD_DATETIME_MECHANISM_ERROR_GENERAL,
+                                     "Error enabling NTP: OS variant not supported");
+                dbus_g_method_return_error (context, error);
+                g_error_free (error);
+                return FALSE;
         }
 
-        dbus_g_method_return (context, can_use_ntp, is_using_ntp);
-        return TRUE;
+        return ret;
 }
 
 gboolean
@@ -736,88 +662,27 @@ gsd_datetime_mechanism_set_using_ntp  (GsdDatetimeMechanism    *mechanism,
                                        DBusGMethodInvocation   *context)
 {
         GError *error;
-        int exit_status;
-        char *cmd;
+        gboolean ret;
 
         error = NULL;
 
         if (!_check_polkit_for_action (mechanism, context))
                 return FALSE;
 
-        if (g_file_test ("/sbin/chkconfig", G_FILE_TEST_EXISTS)) /* Fedora */
-                cmd = g_strconcat ("/sbin/chkconfig --level 2345 ntpd ", using_ntp ? "on" : "off", NULL);
+        if (g_file_test ("/etc/fedora-release", G_FILE_TEST_EXISTS)) /* Fedora */
+                ret = _set_using_ntp_fedora (context, using_ntp);
         else if (g_file_test ("/usr/sbin/update-rc.d", G_FILE_TEST_EXISTS)) /* Debian */
-                cmd = g_strconcat ("/usr/sbin/update-rc.d ntp ", using_ntp ? "enable" : "disable", NULL);
-        else {
-                error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                     GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                     "Error enabling NTP init script: "
-                                     "neither /sbin/chkconfig nor /usr/sbin/update-rc.d are present");
-                dbus_g_method_return_error (context, error);
-                g_error_free (error);
-                return FALSE;
-        }
-
-        if (!g_spawn_command_line_sync (cmd,
-                                        NULL, NULL, &exit_status, &error)) {
-                GError *error2;
-                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                      "Error spawning '%s': %s", cmd, error->message);
-                g_error_free (error);
-                dbus_g_method_return_error (context, error2);
-                g_error_free (error2);
-                g_free (cmd);
-                return FALSE;
-        }
-
-        g_free (cmd);
-
-        if (g_file_test ("/sbin/service", G_FILE_TEST_EXISTS))
-                cmd = "/sbin/service";
-        else if (g_file_test ("/usr/sbin/service", G_FILE_TEST_EXISTS))
-                cmd = "/usr/sbin/service";
+                ret = _set_using_ntp_debian (context, using_ntp);
         else {
                 error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                     "Error spawning 'service': "
-                                     "command was not found in /sbin/ nor /usr/sbin/");
+                                     "Error enabling NTP: OS variant not supported");
                 dbus_g_method_return_error (context, error);
                 g_error_free (error);
                 return FALSE;
         }
 
-        if (g_file_test ("/etc/init.d/ntpd", G_FILE_TEST_EXISTS)) /* Fedora */
-                g_strconcat (cmd, " ntpd ", using_ntp ? "restart" : "stop", NULL);
-        else if (g_file_test ("/etc/init.d/ntp", G_FILE_TEST_EXISTS)) /* Debian */
-                cmd = g_strconcat (cmd, " ntp ", using_ntp ? "restart" : "stop", NULL);
-        else {
-                 error = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                     GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                     "Error spawning 'service': "
-                                     "NTP init script not found at /etc/init.d/ntpd nor /etc/init.d/ntp");
-                dbus_g_method_return_error (context, error);
-                g_error_free (error);
-                return FALSE;
-        }
-
-        if (!g_spawn_command_line_sync (cmd,
-                                        NULL, NULL, &exit_status, &error)) {
-                GError *error2;
-                error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR,
-                                      GSD_DATETIME_MECHANISM_ERROR_GENERAL,
-                                      "Error spawning '%s': %s", cmd, error->message);
-                g_error_free (error);
-                dbus_g_method_return_error (context, error2);
-                g_error_free (error2);
-                g_free (cmd);
-                return FALSE;
-        }
-
-        g_free (cmd);
-
-        dbus_g_method_return (context);
-        return TRUE;
+        return ret;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]