summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-06-19 12:11:56 +0200
committerEugen Wissner <belka@caraus.de>2024-06-19 12:11:56 +0200
commit6fc7f86a89dbcbe1e36ade37c61d4a974be81596 (patch)
tree369c812aca2144dcb13201199a4cc05d1a868d64 /src
parent9dc8fb26405938834b13971c3188f4f52bb8b90d (diff)
downloadslack-timedate-6fc7f86a89dbcbe1e36ade37c61d4a974be81596.tar.gz
Implement CanNTP property
Diffstat (limited to 'src')
-rw-r--r--src/timedate.cpp23
-rw-r--r--src/timedate.h5
2 files changed, 27 insertions, 1 deletions
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();