summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-22 10:09:20 +0200
committerLennart Poettering <lennart@poettering.net>2024-10-22 17:51:26 +0200
commit8eeb870971b86f1d7f39b3cb4cc18c8bf594320f (patch)
treeeabaa25814121d1992ae598e040a535b8716eb8f /src/shared
parentfs-util: tweak how openat_report_new() operates when O_CREAT is used on a dan... (diff)
downloadsystemd-8eeb870971b86f1d7f39b3cb4cc18c8bf594320f.tar.xz
systemd-8eeb870971b86f1d7f39b3cb4cc18c8bf594320f.zip
fileio: port write_string_file() to LabelOps, and thus add WRITE_STRING_FILE_LABEL flag
Given that we have the LabelOps abstraction these days, we can teach write_string_file() to use it, which means we can get rid of fileio-label.[ch] as a separate concept. (The only reason that fileio-label.[ch] exists independently of fileio.[ch] was that the former linekd to libselinux potentially, and thus had to be in src/shared/ while the other always was in src/basic/. But the LabelOps vtable provides us with a nice work-around)
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dropin.c4
-rw-r--r--src/shared/fileio-label.c21
-rw-r--r--src/shared/fileio-label.h8
3 files changed, 6 insertions, 27 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 3e1eaa6623..2e285f8eb6 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -12,7 +12,7 @@
#include "dropin.h"
#include "escape.h"
#include "fd-util.h"
-#include "fileio-label.h"
+#include "fileio.h"
#include "hashmap.h"
#include "log.h"
#include "macro.h"
@@ -87,7 +87,7 @@ int write_drop_in(
if (r < 0)
return r;
- return write_string_file_at_label(AT_FDCWD, p, data, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_MKDIR_0755);
+ return write_string_file(p, data, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC|WRITE_STRING_FILE_MKDIR_0755|WRITE_STRING_FILE_LABEL);
}
int write_drop_in_format(
diff --git a/src/shared/fileio-label.c b/src/shared/fileio-label.c
index 39de54fa25..69ea82cf03 100644
--- a/src/shared/fileio-label.c
+++ b/src/shared/fileio-label.c
@@ -6,20 +6,6 @@
#include "fileio.h"
#include "selinux-util.h"
-int write_string_file_full_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts) {
- int r;
-
- r = mac_selinux_create_file_prepare_at(atfd, fn, S_IFREG);
- if (r < 0)
- return r;
-
- r = write_string_file_full(atfd, fn, line, flags, ts);
-
- mac_selinux_create_file_clear();
-
- return r;
-}
-
int create_shutdown_run_nologin_or_warn(void) {
int r;
@@ -33,9 +19,10 @@ int create_shutdown_run_nologin_or_warn(void) {
* 13 years later we stopped managing /etc/nologin, leaving it for the administrator to manage.
*/
- r = write_string_file_atomic_label("/run/nologin",
- "System is going down. Unprivileged users are not permitted to log in anymore. "
- "For technical details, see pam_nologin(8).");
+ 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");
diff --git a/src/shared/fileio-label.h b/src/shared/fileio-label.h
index 5aa5c40224..9fbe0f42e5 100644
--- a/src/shared/fileio-label.h
+++ b/src/shared/fileio-label.h
@@ -9,12 +9,4 @@
#include "fileio.h"
-int write_string_file_full_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags, struct timespec *ts);
-static inline int write_string_file_at_label(int atfd, const char *fn, const char *line, WriteStringFileFlags flags) {
- return write_string_file_full_label(atfd, fn, line, flags, /* ts= */ NULL);
-}
-static inline int write_string_file_atomic_label(const char *fn, const char *line) {
- return write_string_file_at_label(AT_FDCWD, fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
-}
-
int create_shutdown_run_nologin_or_warn(void);