Remove deprecated g_type_init

This commit is contained in:
Eugen Wissner 2024-04-19 10:14:53 +02:00
parent 75fd7cf0cc
commit 33819d2eb9
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 45 additions and 42 deletions

View File

@ -7,7 +7,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
find_package(PkgConfig) find_package(PkgConfig)
pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1) pkg_check_modules(GDBUS REQUIRED gio-2.0 dbus-1 glibmm-2.4)
find_program(SED sed) find_program(SED sed)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/org.freedesktop.timedate1.service

View File

@ -16,6 +16,7 @@
* *
*/ */
#include <filesystem>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -117,18 +118,14 @@ static void on_timedate_lost (GDBusConnection *connection, const gchar *name, gp
exit (1); exit (1);
} }
gboolean timeout_callback (gpointer loop2quit) { gboolean timeout_callback (Glib::RefPtr<Glib::MainLoop> loop2quit) {
g_main_loop_quit ((GMainLoop *)loop2quit); loop2quit->quit();
return FALSE; return false;
} }
int main (int argc, char **argv) { int main(int argc, char **argv)
guint owner_id; {
GMainLoop *loop; guint owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
g_type_init ();
owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
BUS_NAME, BUS_NAME,
static_cast<GBusNameOwnerFlags>(G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE), static_cast<GBusNameOwnerFlags>(G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE),
on_timedate_acquired, on_timedate_acquired,
@ -136,10 +133,10 @@ int main (int argc, char **argv) {
on_timedate_lost, on_timedate_lost,
NULL, NULL,
NULL); NULL);
Glib::RefPtr<Glib::MainLoop> loop = Glib::MainLoop::create(false);
loop = g_main_loop_new (NULL, FALSE); Glib::signal_timeout().connect_seconds(sigc::bind(&timeout_callback, loop), DEFAULT_EXIT_SEC);
g_timeout_add_seconds (DEFAULT_EXIT_SEC, timeout_callback , loop); loop->run();
g_main_loop_run (loop);
g_bus_unown_name (owner_id); g_bus_unown_name (owner_id);
@ -164,7 +161,8 @@ gboolean slack_set_timezone (gchar *zone) {
GFile *etc_localtime, *localtime_link, *g_zone_file; GFile *etc_localtime, *localtime_link, *g_zone_file;
zone_file = g_strconcat ("/usr/share/zoneinfo/", zone, NULL); zone_file = g_strconcat ("/usr/share/zoneinfo/", zone, NULL);
if (g_file_test (zone_file, G_FILE_TEST_IS_REGULAR)) { if (Glib::file_test(zone_file, Glib::FILE_TEST_IS_REGULAR))
{
etc_localtime = g_file_new_for_path ("/etc/localtime"); etc_localtime = g_file_new_for_path ("/etc/localtime");
localtime_link = g_file_new_for_path ("/etc/localtime-copied-from"); localtime_link = g_file_new_for_path ("/etc/localtime-copied-from");
g_zone_file = g_file_new_for_path (zone_file); g_zone_file = g_file_new_for_path (zone_file);
@ -184,10 +182,10 @@ gboolean slack_set_timezone (gchar *zone) {
g_object_unref (etc_localtime); g_object_unref (etc_localtime);
g_object_unref (localtime_link); g_object_unref (localtime_link);
g_object_unref (g_zone_file); g_object_unref (g_zone_file);
} else {
return FALSE; return true;
} }
return TRUE; return false;
} }
gboolean slack_set_time(gint64 seconds_since_epoch, gboolean relative) gboolean slack_set_time(gint64 seconds_since_epoch, gboolean relative)
@ -237,19 +235,20 @@ gboolean slack_get_is_localtime () {
return is_localtime; return is_localtime;
} }
gboolean slack_get_ntp () { gboolean slack_get_ntp()
if (g_file_test ("/etc/rc.d/rc.ntpd", G_FILE_TEST_IS_EXECUTABLE)) {
return TRUE; return Glib::file_test("/etc/rc.d/rc.ntpd", Glib::FileTest::FILE_TEST_IS_EXECUTABLE);
else return FALSE;
} }
gboolean slack_set_ntp (gboolean xntp) { gboolean slack_set_ntp(gboolean xntp)
mode_t rc_mode; {
std::filesystem::perms rc_mode = std::filesystem::perms::owner_read | std::filesystem::perms::owner_write
| std::filesystem::perms::group_read | std::filesystem::perms::others_read;
rc_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; if (xntp)
{
if (xntp) { rc_mode |= std::filesystem::perms::owner_exec
rc_mode |= S_IXUSR | S_IXGRP | S_IXOTH; | std::filesystem::perms::group_exec | std::filesystem::perms::others_exec;
g_message("Please don't forget to configure the NTP daemon"); g_message("Please don't forget to configure the NTP daemon");
/* It doesn't matter if fails. /* It doesn't matter if fails.
@ -257,12 +256,15 @@ gboolean slack_set_ntp (gboolean xntp) {
* will fail if your system clock is off for more than half an hour. */ * will fail if your system clock is off for more than half an hour. */
g_spawn_command_line_async("/usr/sbin/ntpdate pool.ntp.org", NULL); g_spawn_command_line_async("/usr/sbin/ntpdate pool.ntp.org", NULL);
} }
if (Glib::file_test("/etc/rc.d/rc.ntpd", Glib::FileTest::FILE_TEST_IS_REGULAR))
if (g_file_test ("/etc/rc.d/rc.ntpd", G_FILE_TEST_IS_REGULAR)) { {
if (chmod ("/etc/rc.d/rc.ntpd", rc_mode)) return FALSE; std::error_code ec;
else return TRUE; std::filesystem::permissions("/etc/rc.d/rc.ntpd", rc_mode, ec);
} else { return !ec;
}
else
{
g_error("The NTP daemon isn't installed"); g_error("The NTP daemon isn't installed");
return FALSE; return false;
} }
} }

View File

@ -17,6 +17,7 @@
*/ */
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <glibmm.h>
#include <gio/gio.h> #include <gio/gio.h>
#define BUS_NAME "org.freedesktop.timedate1" #define BUS_NAME "org.freedesktop.timedate1"