aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Rostovtsev <tetromino@gentoo.org>2012-09-07 19:41:41 -0400
committerAlexandre Rostovtsev <tetromino@gentoo.org>2012-09-07 20:03:04 -0400
commitbf6d6faacbb2f74a9f05a949bd27696b84076dd0 (patch)
tree7629d48a8cf7ecf4507746c6a285766c944aef4b
parentUpdate man page to match --help output (diff)
downloadopenrc-settingsd-bf6d6faacbb2f74a9f05a949bd27696b84076dd0.tar.gz
openrc-settingsd-bf6d6faacbb2f74a9f05a949bd27696b84076dd0.tar.bz2
openrc-settingsd-bf6d6faacbb2f74a9f05a949bd27696b84076dd0.zip
Better diagnostics for missing ntp implementation
-rw-r--r--src/timedated.c34
1 files 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,