env-file: port write_env_file() to label_ops_pre()

Let's make more use of label_ops_pre()/label_ops_post(), and replace
write_env_file_label() by a flag to write_env_file().

This simplifies and normalizes the code.

This also makes one relevant change: it sets the new
WRITE_ENV_FILE_LABEL flag in firstboot.c when we write locale.conf,
where we previously did not (but should have). This should address one
detail of #37857.
This commit is contained in:
Lennart Poettering
2025-06-18 10:21:26 +02:00
parent 9ea5a6e7d6
commit 3e5320e27d
11 changed files with 42 additions and 61 deletions
-35
View File
@@ -1,35 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <sys/stat.h>
#include "env-file.h"
#include "env-file-label.h"
#include "selinux-util.h"
int write_env_file_label(int dir_fd, const char *fname, char **headers, char **l) {
int r;
r = mac_selinux_create_file_prepare(fname, S_IFREG);
if (r < 0)
return r;
r = write_env_file(dir_fd, fname, headers, l);
mac_selinux_create_file_clear();
return r;
}
int write_vconsole_conf_label(char **l) {
int r;
r = mac_selinux_create_file_prepare("/etc/vconsole.conf", S_IFREG);
if (r < 0)
return r;
r = write_vconsole_conf(AT_FDCWD, "/etc/vconsole.conf", l);
mac_selinux_create_file_clear();
return r;
}
-12
View File
@@ -1,12 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include "forward.h"
/* 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 */
int write_env_file_label(int dir_fd, const char *fname, char **headers, char **l);
int write_vconsole_conf_label(char **l);
+6 -2
View File
@@ -6,7 +6,6 @@
#include "alloc-util.h"
#include "env-file.h"
#include "env-file-label.h"
#include "env-util.h"
#include "errno-util.h"
#include "fd-util.h"
@@ -212,7 +211,12 @@ int locale_context_save(LocaleContext *c, char ***ret_set, char ***ret_unset) {
return 0;
}
r = write_env_file_label(AT_FDCWD, "/etc/locale.conf", NULL, set);
r = write_env_file(
AT_FDCWD,
"/etc/locale.conf",
/* headers= */ NULL,
set,
WRITE_ENV_FILE_LABEL);
if (r < 0)
return r;
-1
View File
@@ -68,7 +68,6 @@ shared_sources = files(
'efi-loader.c',
'elf-util.c',
'enable-mempool.c',
'env-file-label.c',
'ethtool-util.c',
'exec-util.c',
'exit-status.c',