From 41f3ab780280476d9c3adf4369ca9d57635fe31a Mon Sep 17 00:00:00 2001 From: Nathaniel Russell Date: Tue, 20 Feb 2024 02:40:00 +0000 Subject: [PATCH] Implement Slackware specific information --- meson.build | 9 +++++++++ meson_options.txt | 5 +++-- src/hostnamed.c | 13 +++++++++++++ src/localed.c | 4 ++++ src/timedated.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index f975f8f..bf2b70e 100644 --- a/meson.build +++ b/meson.build @@ -57,6 +57,15 @@ endif if get_option('locale-style') == 'gentoo' conf_data.set('LOCALE_STYLE_GENTOO', 1) endif +if get_option('hostname-style') == 'slackware' + conf_data.set('HOSTNAME_STYLE_SLACKWARE', 1) +endif +if get_option('locale-style') == 'slackware' + conf_data.set('LOCALE_STYLE_SLACKWARE', 1) +endif +if get_option('time-style') == 'slackware' + conf_data.set('TIME_STYLE_SLACKWARE', 1) +endif conf_data.set('PACKAGE_STRING', '"' + meson.project_name() + ' ' + meson.project_version() + '"') conf_data.set10('HAVE_OPENRC', openrc_dep.found()) diff --git a/meson_options.txt b/meson_options.txt index 306e633..e7e586e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ option('openrc', type : 'feature', value : 'enabled') option('env-update', type : 'string', value : '/usr/sbin/env-update', description : 'path to env-update executable') -option('hostname-style', type : 'combo', choices : ['default', 'gentoo'], value : 'default') -option('locale-style', type : 'combo', choices : ['default', 'gentoo'], value : 'default') +option('hostname-style', type : 'combo', choices : ['default', 'gentoo', 'slackware'], value : 'default') +option('locale-style', type : 'combo', choices : ['default', 'gentoo', 'slackware'], value : 'default') +option('time-style', type : 'combo', choices : ['slackware'], value : 'slackware') diff --git a/src/hostnamed.c b/src/hostnamed.c index 81327f3..e08be44 100644 --- a/src/hostnamed.c +++ b/src/hostnamed.c @@ -733,6 +733,15 @@ hostnamed_init (gboolean _read_only) g_error_free (err); err = NULL; } +#elif HOSTNAME_STYLE_SLACKWARE + static_hostname_file = g_file_new_for_path (SYSCONFDIR "/HOSTNAME"); + + if (!g_file_load_contents (static_hostname_file, NULL, &static_hostname, NULL, NULL, &err)) { + g_debug ("%s", err->message); + g_error_free (err); + err = NULL; + static_hostname = NULL; + } #else static_hostname_file = g_file_new_for_path (SYSCONFDIR "/hostname"); @@ -749,7 +758,11 @@ hostnamed_init (gboolean _read_only) g_strstrip (static_hostname); #endif +#if HOSTNAME_STYLE_SLACKWARE + machine_info_file = g_file_new_for_path (SYSCONFDIR "/os-release"); +#else machine_info_file = g_file_new_for_path (SYSCONFDIR "/machine-info"); +#endif pretty_hostname = shell_source_var (machine_info_file, "${PRETTY_HOSTNAME}", &err); if (pretty_hostname == NULL) diff --git a/src/localed.c b/src/localed.c index ed07dba..2739875 100644 --- a/src/localed.c +++ b/src/localed.c @@ -1288,6 +1288,10 @@ localed_init (gboolean _read_only) kbd_model_map_file = g_file_new_for_path (PKGDATADIR "/kbd-model-map"); locale_file = g_file_new_for_path (SYSCONFDIR "/env.d/02locale"); keymaps_file = g_file_new_for_path (SYSCONFDIR "/conf.d/keymaps"); +#elif LOCALE_STYLE_SLACKWARE + kbd_model_map_file = g_file_new_for_path (PKGDATADIR "/openrc-settingsd/kbd-model-map"); + locale_file = g_file_new_for_path (SYSCONFDIR "/locale.conf"); + keymaps_file = g_file_new_for_path (SYSCONFDIR "/conf.d/keymaps"); #else kbd_model_map_file = g_file_new_for_path (PKGDATADIR "/openrc-settingsd/kbd-model-map"); locale_file = g_file_new_for_path (SYSCONFDIR "/profile.d/locale.sh"); diff --git a/src/timedated.c b/src/timedated.c index 54636e6..5f7eb3c 100644 --- a/src/timedated.c +++ b/src/timedated.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -69,10 +71,23 @@ get_local_rtc (GError **error) gchar *clock = NULL; gboolean ret = FALSE; +#if TIME_STYLE_SLACKWARE + gsize length = 0; + gchar *fileContent = NULL; + + if (g_file_load_contents (hwclock_file, NULL, &fileContent, &length, NULL, error)) { + if (fileContent != NULL && strstr(fileContent, "localtime") != NULL) { + ret = TRUE; + } + g_free(fileContent); + } +#else clock = shell_source_var (hwclock_file, "${clock}", error); if (!g_strcmp0 (clock, "local")) ret = TRUE; g_free (clock); +#endif + return ret; } @@ -171,6 +186,26 @@ set_timezone (const gchar *identifier, return TRUE; } +#if TIME_STYLE_SLACKWARE +// Function to check if the NTP service is running +bool ntp_is_running() { + FILE* fp = popen("pgrep ntpd", "r"); // Check if the ntpd process is running + if (fp == NULL) { + perror("popen"); + return false; // Assume NTP is not running if an error occurs + } + + char buf[128]; + if (fgets(buf, sizeof(buf), fp) != NULL) { + pclose(fp); + return true; // NTP process found, so it is running + } + + pclose(fp); + return false; // NTP process not found, so it is not running +} +#endif + /* Return the ntp rc service we will use; return value should NOT be freed */ static const gchar * ntp_service () @@ -197,6 +232,13 @@ ntp_service () free (runlevel); return service; +#elif TIME_STYLE_SLACKWARE + // Check if NTP service is already running + // Add your logic here to check if the NTP program is running + if (ntp_is_running()) { + return "ntpd"; // Assuming "ntp" is the default service name when NTP is running + } + return NULL; #else return NULL; #endif @@ -732,9 +774,15 @@ timedated_init (gboolean _read_only, read_only = _read_only; ntp_preferred_service = _ntp_preferred_service; +#if TIME_STYLE_SLACKWARE + hwclock_file = g_file_new_for_path (SYSCONFDIR "/hardwareclock"); + timezone_file = g_file_new_for_path (SYSCONFDIR "/timezone"); + localtime_file = g_file_new_for_path (SYSCONFDIR "/localtime"); +#else hwclock_file = g_file_new_for_path (SYSCONFDIR "/conf.d/hwclock"); timezone_file = g_file_new_for_path (SYSCONFDIR "/timezone"); localtime_file = g_file_new_for_path (SYSCONFDIR "/localtime"); +#endif local_rtc = get_local_rtc (&err); if (err != NULL) { -- GitLab diff --git a/src/hostnamed.c b/src/hostnamed.c index e08be44..9e628b1 100644 --- a/src/hostnamed.c +++ b/src/hostnamed.c @@ -733,15 +733,6 @@ hostnamed_init (gboolean _read_only) g_error_free (err); err = NULL; } -#elif HOSTNAME_STYLE_SLACKWARE - static_hostname_file = g_file_new_for_path (SYSCONFDIR "/HOSTNAME"); - - if (!g_file_load_contents (static_hostname_file, NULL, &static_hostname, NULL, NULL, &err)) { - g_debug ("%s", err->message); - g_error_free (err); - err = NULL; - static_hostname = NULL; - } #else static_hostname_file = g_file_new_for_path (SYSCONFDIR "/hostname"); @@ -758,6 +749,48 @@ hostnamed_init (gboolean _read_only) g_strstrip (static_hostname); #endif +#ifdef HOSTNAME_STYLE_SLACKWARE + #include + #include + + sd_bus *bus = NULL; + int ret = sd_bus_open_system(&bus); + if (ret >= 0) { + const char *dbus_hostname = NULL; + sd_bus_error error = SD_BUS_ERROR_NULL; + ret = sd_bus_get_property_string(bus, + "org.freedesktop.hostname1", + "/org/freedesktop/hostname1", + "org.freedesktop.hostname1", + "Hostname", + &error, + (char **)&dbus_hostname); // Cast to char ** + if (ret >= 0) { + // Update hostname if D-Bus retrieval is successful + g_free(hostname); + hostname = g_strdup(dbus_hostname); + sd_bus_error_free(&error); + } else { + fprintf(stderr, "Failed to get hostname property: %s\n", error.message); + sd_bus_error_free(&error); + } + sd_bus_unref(bus); + } else { + fprintf(stderr, "Failed to open system D-Bus connection: %s\n", strerror(-ret)); + + // Attempt to retrieve hostname from static file if D-Bus fails + GFile *static_hostname_file = g_file_new_for_path(SYSCONFDIR "/HOSTNAME"); + if (!g_file_load_contents(static_hostname_file, NULL, &hostname, NULL, NULL, &err)) { + g_debug("%s", err->message); + g_error_free(err); + err = NULL; + hostname = NULL; + } + + g_object_unref(static_hostname_file); + } +#endif + #if HOSTNAME_STYLE_SLACKWARE machine_info_file = g_file_new_for_path (SYSCONFDIR "/os-release"); #else -- GitLab From 51c8bbf296056686f786a80f0e0f7e83cffad695 Mon Sep 17 00:00:00 2001 From: Nathaniel Russell Date: Sun, 24 Mar 2024 00:32:09 +0000 Subject: [PATCH] Update 2 files - /meson.build - /meson_options.txt --- meson.build | 6 ++++++ meson_options.txt | 1 + 2 files changed, 7 insertions(+) diff --git a/meson.build b/meson.build index bf2b70e..2a538de 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,11 @@ dbus_dep = dependency('dbus-1') polkit_dep = dependency('polkit-gobject-1') openrc_dep = dependency('openrc', required : get_option('openrc')) +enable_elogind = get_option('elogind') +if enable_elogind + elogind_dep = dependency('libelogind', version: '>= 209') +endif + sources = files([ 'src/bus-utils.c', 'src/hostnamed.c', @@ -85,6 +85,7 @@ executable( glib_dep, openrc_dep, polkit_dep, + elogind_dep, ], install : true, install_dir : get_option('libexecdir'), diff --git a/meson_options.txt b/meson_options.txt index e7e586e..2b04e76 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -3,3 +3,4 @@ option('env-update', type : 'string', value : '/usr/sbin/env-update', descriptio option('hostname-style', type : 'combo', choices : ['default', 'gentoo', 'slackware'], value : 'default') option('locale-style', type : 'combo', choices : ['default', 'gentoo', 'slackware'], value : 'default') option('time-style', type : 'combo', choices : ['slackware'], value : 'slackware') +option('elogind', type: 'boolean', value: false, description: 'Use elogind') \ No newline at end of file -- GitLab