This commit is contained in:
parent
9dc8fb2640
commit
6fc7f86a89
@ -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"/>
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user