summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/org.freedesktop.timedate1.xml1
-rw-r--r--src/timedate.cpp23
-rw-r--r--src/timedate.h5
3 files changed, 28 insertions, 1 deletions
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 @@
<property name="Timezone" type="s" access="read"/>
<property name="LocalRTC" type="b" access="read"/>
<property name="NTP" type="b" access="read"/>
+ <property name="CanNTP" type="b" access="read"/>
<method name="SetTime">
<arg name="usec_utc" type="x" direction="in"/>
<arg name="relative" type="b" direction="in"/>
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 <cstring>
#include <filesystem>
#include <fstream>
+#include <iostream>
#include <string>
#include "timedate.h"
@@ -116,6 +117,10 @@ static void slack_get_property(Glib::VariantBase& result, const Glib::RefPtr<Gio
{
result = Glib::Variant<bool>::create(dlackware::timedate::ntp());
}
+ else if (prop_name == "CanNTP")
+ {
+ result = Glib::Variant<bool>::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<std::string>{ "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<Glib::ustring> list_timezones();