From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 40E1D138010 for ; Sat, 8 Sep 2012 00:21:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E6178E06F7; Sat, 8 Sep 2012 00:21:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 9C363E06F7 for ; Sat, 8 Sep 2012 00:21:03 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B82FA33CEF7 for ; Sat, 8 Sep 2012 00:21:02 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id CB08FE5445 for ; Sat, 8 Sep 2012 00:20:59 +0000 (UTC) From: "Alexandre Restovtsev" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Alexandre Restovtsev" Message-ID: <1347062584.bf6d6faacbb2f74a9f05a949bd27696b84076dd0.tetromino@gentoo> Subject: [gentoo-commits] proj/openrc-settingsd:master commit in: src/ X-VCS-Repository: proj/openrc-settingsd X-VCS-Files: src/timedated.c X-VCS-Directories: src/ X-VCS-Committer: tetromino X-VCS-Committer-Name: Alexandre Restovtsev X-VCS-Revision: bf6d6faacbb2f74a9f05a949bd27696b84076dd0 X-VCS-Branch: master Date: Sat, 8 Sep 2012 00:20:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 95a5f7a6-a9e6-4ce3-b4fb-c1cf7c9c38cb X-Archives-Hash: 31b3f6885e47dd0022d66d510c696c3e commit: bf6d6faacbb2f74a9f05a949bd27696b84076dd0 Author: Alexandre Rostovtsev gentoo org> AuthorDate: Fri Sep 7 23:41:41 2012 +0000 Commit: Alexandre Restovtsev gmail com> CommitDate: Sat Sep 8 00:03:04 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc-settingsd.git;a=commit;h=bf6d6faa Better diagnostics for missing ntp implementation --- src/timedated.c | 34 +++++++++++++++++++++++++--------- 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,