diff --git a/data/org.freedesktop.timedate1.xml b/data/org.freedesktop.timedate1.xml index e9010dd..b64f9e5 100644 --- a/data/org.freedesktop.timedate1.xml +++ b/data/org.freedesktop.timedate1.xml @@ -5,6 +5,7 @@ + diff --git a/src/timedate.cpp b/src/timedate.cpp index b06cbcc..101a925 100644 --- a/src/timedate.cpp +++ b/src/timedate.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "timedate.h" @@ -116,6 +117,10 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr::create(dlackware::timedate::ntp()); } + else if (prop_name == "CanNTP") + { + result = Glib::Variant::create(dlackware::timedate::can_ntp()); + } } namespace dlackware::timedate @@ -265,6 +270,24 @@ namespace dlackware::timedate return Glib::file_test("/etc/rc.d/rc.ntpd", Glib::FileTest::FILE_TEST_IS_EXECUTABLE); } + bool can_ntp() + { + std::string standard_output; + int wait_status{-1}; + + try + { + Glib::spawn_sync("", std::vector{ "s6-rc-db", "type", "ntpd" }, + Glib::SpawnFlags::SPAWN_SEARCH_PATH | Glib::SpawnFlags::SPAWN_STDERR_TO_DEV_NULL, + {}, &standard_output, nullptr, &wait_status); + } + catch (const Glib::SpawnError& spawn_error) + { + return std::filesystem::exists("/etc/rc.d/rc.ntpd"); + } + return wait_status == 0 && standard_output == "bundle\n"; + } + void set_time(gint64 seconds_since_epoch, bool relative, bool) { timespec ts; diff --git a/src/timedate.h b/src/timedate.h index 49883f9..40f149a 100644 --- a/src/timedate.h +++ b/src/timedate.h @@ -34,9 +34,12 @@ namespace dlackware::timedate // Returns if the hardware clock is set to local time or not bool local_rtc(); - // Returns if NTP is enabled + // Returns whether NTP is enabled. bool ntp(); + // Returns whether NTP is available. + bool can_ntp(); + // Returns the timezones available on the system. std::vector list_timezones();