From: Lennart Poettering Date: Tue, 22 Oct 2024 08:25:26 +0000 (+0200) Subject: shared: get rid of fileio-label.[ch] X-Git-Tag: v257-rc1~161^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a7ae4ba62baf0ccccc90d4f95055609124677b1;p=thirdparty%2Fsystemd.git shared: get rid of fileio-label.[ch] Move the renaming function to reboot-util.h (since it writes out /run/nologin at shutdown), and let's get rid of fileio-label.[ch] now that it serves no purpose anymore. --- diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 9582fb47dfa..5de882e42bc 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -30,7 +30,6 @@ #include "event-util.h" #include "fd-util.h" #include "fileio.h" -#include "fileio-label.h" #include "format-util.h" #include "fs-util.h" #include "logind-action.h" diff --git a/src/shared/fileio-label.c b/src/shared/fileio-label.c deleted file mode 100644 index 69ea82cf032..00000000000 --- a/src/shared/fileio-label.c +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#include - -#include "fileio-label.h" -#include "fileio.h" -#include "selinux-util.h" - -int create_shutdown_run_nologin_or_warn(void) { - int r; - - /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we - * actually go down, and once in systemd-logind.service when shutdowns are scheduled, and logins are - * to be turned off a bit in advance. We use the same wording of the message in both cases. - * - * Traditionally, there was only /etc/nologin, and we managed that. Then, in PAM 1.1 - * support for /run/nologin was added as alternative - * (https://github.com/linux-pam/linux-pam/commit/e9e593f6ddeaf975b7fe8446d184e6bc387d450b). - * 13 years later we stopped managing /etc/nologin, leaving it for the administrator to manage. - */ - - r = write_string_file("/run/nologin", - "System is going down. Unprivileged users are not permitted to log in anymore. " - "For technical details, see pam_nologin(8).", - WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_LABEL); - if (r < 0) - return log_error_errno(r, "Failed to create /run/nologin: %m"); - - return 0; -} diff --git a/src/shared/fileio-label.h b/src/shared/fileio-label.h deleted file mode 100644 index 9fbe0f42e56..00000000000 --- a/src/shared/fileio-label.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -/* These functions are split out of fileio.h (and not for example just flags to the functions they wrap) in order to - * optimize linking: This way, -lselinux is needed only for the callers of these functions that need selinux, but not - * for all */ - -#include "fileio.h" - -int create_shutdown_run_nologin_or_warn(void); diff --git a/src/shared/meson.build b/src/shared/meson.build index 1141efa4538..af9ef74b329 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -72,7 +72,6 @@ shared_sources = files( 'extension-util.c', 'fdset.c', 'fido2-util.c', - 'fileio-label.c', 'find-esp.c', 'firewall-util-nft.c', 'firewall-util.c', diff --git a/src/shared/reboot-util.c b/src/shared/reboot-util.c index b1c1aa75e62..903e19efae2 100644 --- a/src/shared/reboot-util.c +++ b/src/shared/reboot-util.c @@ -204,3 +204,26 @@ bool kexec_loaded(void) { return s[0] == '1'; } + +int create_shutdown_run_nologin_or_warn(void) { + int r; + + /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we + * actually go down, and once in systemd-logind.service when shutdowns are scheduled, and logins are + * to be turned off a bit in advance. We use the same wording of the message in both cases. + * + * Traditionally, there was only /etc/nologin, and we managed that. Then, in PAM 1.1 + * support for /run/nologin was added as alternative + * (https://github.com/linux-pam/linux-pam/commit/e9e593f6ddeaf975b7fe8446d184e6bc387d450b). + * 13 years later we stopped managing /etc/nologin, leaving it for the administrator to manage. + */ + + r = write_string_file("/run/nologin", + "System is going down. Unprivileged users are not permitted to log in anymore. " + "For technical details, see pam_nologin(8).", + WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_LABEL); + if (r < 0) + return log_error_errno(r, "Failed to create /run/nologin: %m"); + + return 0; +} diff --git a/src/shared/reboot-util.h b/src/shared/reboot-util.h index 2ac478f7840..92189bee881 100644 --- a/src/shared/reboot-util.h +++ b/src/shared/reboot-util.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include + bool reboot_parameter_is_valid(const char *parameter); int update_reboot_parameter_and_warn(const char *parameter, bool keep); @@ -16,3 +18,5 @@ int reboot_with_parameter(RebootFlags flags); bool shall_restore_state(void); bool kexec_loaded(void); + +int create_shutdown_run_nologin_or_warn(void); diff --git a/src/user-sessions/user-sessions.c b/src/user-sessions/user-sessions.c index 58054f89fb3..7d84d6b5406 100644 --- a/src/user-sessions/user-sessions.c +++ b/src/user-sessions/user-sessions.c @@ -6,11 +6,10 @@ #include #include -#include "fileio.h" -#include "fileio-label.h" #include "fs-util.h" -#include "main-func.h" #include "log.h" +#include "main-func.h" +#include "reboot-util.h" #include "selinux-util.h" #include "string-util.h"