summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-06-29 16:01:57 +0200
committerEugen Wissner <belka@caraus.de>2024-06-29 16:01:57 +0200
commit8bf3a92cbc3aea9ae47177d877420f966bc9acf5 (patch)
tree5f8c0963480e11d3d21156d418f35a1c70b83b00 /src
parentd75053b2439ab30d45aaa55365e7586498cd3299 (diff)
downloadslack-timedate-8bf3a92cbc3aea9ae47177d877420f966bc9acf5.tar.gz
Implement SetLocalRTC
Diffstat (limited to 'src')
-rw-r--r--src/timedate.cpp55
-rw-r--r--src/timedate.h3
2 files changed, 58 insertions, 0 deletions
diff --git a/src/timedate.cpp b/src/timedate.cpp
index e6ec83f..c7c2406 100644
--- a/src/timedate.cpp
+++ b/src/timedate.cpp
@@ -45,6 +45,30 @@ static void slack_method_call(const Glib::RefPtr<Gio::DBus::Connection>& connect
invocation->return_error(Gio::DBus::Error{ Gio::DBus::Error::FAILED, filesystem_error.what() });
}
}
+ else if (method_name == "SetLocalRTC")
+ {
+ Glib::Variant<bool> local_rtc;
+ Glib::Variant<bool> fix_system;
+ Glib::Variant<bool> user_interaction;
+
+ parameters.get_child(local_rtc, 0);
+ parameters.get_child(fix_system, 1);
+ parameters.get_child(user_interaction, 2);
+
+ try
+ {
+ dlackware::timedate::set_local_rtc(local_rtc.get(), fix_system.get(), user_interaction.get());
+ invocation->return_value(Glib::VariantContainerBase());
+ }
+ catch (const std::system_error& error)
+ {
+ invocation->return_error(Gio::DBus::Error{ Gio::DBus::Error::FAILED, error.what() });
+ }
+ catch (const Glib::SpawnError& spawn_error)
+ {
+ invocation->return_error(Gio::DBus::Error{ Gio::DBus::Error::FAILED, spawn_error.what() });
+ }
+ }
else if (method_name == "SetTime")
{
Glib::Variant<gint64> usec_utc;
@@ -285,6 +309,37 @@ namespace dlackware::timedate
}
}
+ void set_local_rtc(bool local_rtc, bool fix_system, bool)
+ {
+ std::ofstream hardwareclock{ "/etc/hardwareclock", std::ios::trunc };
+ std::string hwclock_argument;
+
+ hardwareclock << "# /etc/hardwareclock" << std::endl
+ << "#" << std::endl
+ << "# Tells how the hardware clock time is stored." << std::endl
+ << "# You should run timeconfig to edit this file." << std::endl
+ << std::endl;
+
+ if (local_rtc)
+ {
+ hwclock_argument = "--localtime";
+ hardwareclock << "localtime";
+ }
+ else
+ {
+ hwclock_argument = "--utc";
+ hardwareclock << "UTC";
+ }
+ hardwareclock << std::endl;
+
+ if (!fix_system)
+ {
+ Glib::spawn_sync("", std::vector<std::string>{ "/sbin/hwclock", hwclock_argument, "--hctosys" },
+ Glib::SpawnFlags::SPAWN_STDOUT_TO_DEV_NULL | Glib::SpawnFlags::SPAWN_STDERR_TO_DEV_NULL,
+ {}, nullptr, nullptr, static_cast<int *>(nullptr));
+ }
+ }
+
bool local_rtc()
{
std::ifstream fh{ "/etc/hardwareclock", std::ios::in };
diff --git a/src/timedate.h b/src/timedate.h
index 1c33594..a1b2852 100644
--- a/src/timedate.h
+++ b/src/timedate.h
@@ -65,6 +65,9 @@ namespace dlackware::timedate
// Throws std::system_error.
void set_time(std::int64_t seconds_since_epoch, bool relative, bool user_interaction);
+ // Controls whether the RTC is local time or UTC.
+ void set_local_rtc(bool local_rtc, bool fix_system, bool user_interaction);
+
class timedate1
{
const Gio::DBus::InterfaceVTable interface_vtable;