From bf6d6faacbb2f74a9f05a949bd27696b84076dd0 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Fri, 7 Sep 2012 19:41:41 -0400 Subject: Better diagnostics for missing ntp implementation --- src/timedated.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/timedated.c b/src/timedated.c index 4e5939e..70c41b4 100644 --- a/src/timedated.c +++ b/src/timedated.c @@ -52,7 +52,8 @@ G_LOCK_DEFINE_STATIC (clock); gboolean use_ntp = FALSE; static const gchar *ntp_preferred_service = NULL; -static const gchar *ntp_default_services[4] = { "ntpd", "chronyd", "busybox-ntpd", NULL }; +static const gchar *ntp_default_services[] = { "ntpd", "chronyd", "busybox-ntpd", NULL }; +#define NTP_DEFAULT_SERVICES_PACKAGES "ntp, openntpd, chrony, busybox-ntpd" G_LOCK_DEFINE_STATIC (ntp); static gboolean @@ -177,8 +178,6 @@ ntp_service () } free (runlevel); - if (service == NULL) - service = ntp_default_services[0]; return service; } @@ -188,6 +187,8 @@ service_started (const gchar *service, { RC_SERVICE state; + g_assert (service != NULL); + if (!rc_service_exists (service)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service); return FALSE; @@ -207,6 +208,8 @@ service_disable (const gchar *service, gboolean ret = FALSE; gint exit_status = 0; + g_assert (service != NULL); + if (!rc_service_exists (service)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service); goto out; @@ -254,6 +257,8 @@ service_enable (const gchar *service, gboolean ret = FALSE; gint exit_status = 0; + g_assert (service != NULL); + if (!rc_service_exists (service)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s rc service not found", service); goto out; @@ -584,8 +589,14 @@ on_handle_set_ntp_authorized_cb (GObject *source_object, } G_LOCK (ntp); - if ((data->use_ntp && !service_enable (ntp_service(), &err)) || - (!data->use_ntp && !service_disable (ntp_service(), &err))) + if (ntp_service () == NULL) { + g_dbus_method_invocation_return_dbus_error (data->invocation, DBUS_ERROR_FAILED, + "No ntp implementation found. Please install one of the following packages: " + NTP_DEFAULT_SERVICES_PACKAGES); + goto unlock; + } + if ((data->use_ntp && !service_enable (ntp_service (), &err)) || + (!data->use_ntp && !service_disable (ntp_service (), &err))) { g_dbus_method_invocation_return_gerror (data->invocation, err); goto unlock; @@ -702,10 +713,15 @@ timedated_init (gboolean _read_only, g_warning ("%s", err->message); g_clear_error (&err); } - use_ntp = service_started (ntp_service (), &err); - if (err != NULL) { - g_warning ("%s", err->message); - g_clear_error (&err); + if (ntp_service () == NULL) { + g_warning ("No ntp implementation found. Please install one of the following packages: " NTP_DEFAULT_SERVICES_PACKAGES); + use_ntp = FALSE; + } else { + use_ntp = service_started (ntp_service (), &err); + if (err != NULL) { + g_warning ("%s", err->message); + g_clear_error (&err); + } } bus_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, -- cgit v1.2.3-65-gdbad