locale,firstboot: add headers to vconsole.conf

Closes #29717.
Replaces #29760.

Co-authored-by: cunshunxia <cunshunxia@tencent.com>
This commit is contained in:
Yu Watanabe
2023-10-30 20:30:12 +09:00
parent f155cb6d75
commit 0e7a7cd4e9
6 changed files with 28 additions and 2 deletions

View File

@@ -637,3 +637,11 @@ int write_env_file(int dir_fd, const char *fname, char **headers, char **l) {
(void) unlinkat(dir_fd, p, 0);
return r;
}
int write_vconsole_conf(int dir_fd, const char *fname, char **l) {
char **headers = STRV_MAKE(
"# Written by systemd-localed(8) or systemd-firstboot(1), read by systemd-localed",
"# and systemd-vconsole-setup(8). Use localectl(1) to update this file.");
return write_env_file(dir_fd, fname, headers, l);
}

View File

@@ -20,3 +20,5 @@ int load_env_file_pairs_fd(int fd, const char *fname, char ***ret);
int merge_env_file(char ***env, FILE *f, const char *fname);
int write_env_file(int dir_fd, const char *fname, char **headers, char **l);
int write_vconsole_conf(int dir_fd, const char *fname, char **l);

View File

@@ -534,7 +534,7 @@ static int process_keymap(int rfd) {
keymap = STRV_MAKE(strjoina("KEYMAP=", arg_keymap));
r = write_env_file(pfd, f, NULL, keymap);
r = write_vconsole_conf(pfd, f, keymap);
if (r < 0)
return log_error_errno(r, "Failed to write /etc/vconsole.conf: %m");

View File

@@ -532,7 +532,7 @@ int vconsole_write_data(Context *c) {
return 0;
}
r = write_env_file_label(AT_FDCWD, "/etc/vconsole.conf", NULL, l);
r = write_vconsole_conf_label(l);
if (r < 0)
return r;

View File

@@ -19,3 +19,17 @@ int write_env_file_label(int dir_fd, const char *fname, char **headers, char **l
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;
}

View File

@@ -6,3 +6,5 @@
* for all */
int write_env_file_label(int dir_fd, const char *fname, char **headers, char **l);
int write_vconsole_conf_label(char **l);