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 "/profile.d/locale.sh"); + 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