This commit is contained in:
parent
9dc8fb2640
commit
6fc7f86a89
@ -5,6 +5,7 @@
|
|||||||
<property name="Timezone" type="s" access="read"/>
|
<property name="Timezone" type="s" access="read"/>
|
||||||
<property name="LocalRTC" type="b" access="read"/>
|
<property name="LocalRTC" type="b" access="read"/>
|
||||||
<property name="NTP" type="b" access="read"/>
|
<property name="NTP" type="b" access="read"/>
|
||||||
|
<property name="CanNTP" type="b" access="read"/>
|
||||||
<method name="SetTime">
|
<method name="SetTime">
|
||||||
<arg name="usec_utc" type="x" direction="in"/>
|
<arg name="usec_utc" type="x" direction="in"/>
|
||||||
<arg name="relative" type="b" direction="in"/>
|
<arg name="relative" type="b" direction="in"/>
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "timedate.h"
|
#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());
|
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
|
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);
|
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)
|
void set_time(gint64 seconds_since_epoch, bool relative, bool)
|
||||||
{
|
{
|
||||||
timespec ts;
|
timespec ts;
|
||||||
|
@ -34,9 +34,12 @@ namespace dlackware::timedate
|
|||||||
// Returns if the hardware clock is set to local time or not
|
// Returns if the hardware clock is set to local time or not
|
||||||
bool local_rtc();
|
bool local_rtc();
|
||||||
|
|
||||||
// Returns if NTP is enabled
|
// Returns whether NTP is enabled.
|
||||||
bool ntp();
|
bool ntp();
|
||||||
|
|
||||||
|
// Returns whether NTP is available.
|
||||||
|
bool can_ntp();
|
||||||
|
|
||||||
// Returns the timezones available on the system.
|
// Returns the timezones available on the system.
|
||||||
std::vector<Glib::ustring> list_timezones();
|
std::vector<Glib::ustring> list_timezones();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user