1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2010 Harald Hoyer
8 #include "fileio-label.h"
10 #include "selinux-util.h"
12 int write_string_file_atomic_label_ts(const char *fn, const char *line, struct timespec *ts) {
15 r = mac_selinux_create_file_prepare(fn, S_IFREG);
19 r = write_string_file_ts(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC, ts);
21 mac_selinux_create_file_clear();
26 #if 0 /// UNNEEDED by elogind
27 int write_env_file_label(const char *fname, char **l) {
30 r = mac_selinux_create_file_prepare(fname, S_IFREG);
34 r = write_env_file(fname, l);
36 mac_selinux_create_file_clear();
41 int fopen_temporary_label(const char *target,
42 const char *path, FILE **f, char **temp_path) {
45 r = mac_selinux_create_file_prepare(target, S_IFREG);
49 r = fopen_temporary(path, f, temp_path);
51 mac_selinux_create_file_clear();
57 int create_shutdown_run_nologin_or_warn(void) {
60 /* This is used twice: once in systemd-user-sessions.service, in order to block logins when we actually go
61 * down, and once in systemd-logind.service when shutdowns are scheduled, and logins are to be turned off a bit
62 * in advance. We use the same wording of the message in both cases. */
64 r = write_string_file_atomic_label("/run/nologin",
65 "System is going down. Unprivileged users are not permitted to log in anymore. "
66 "For technical details, see pam_nologin(8).");
68 return log_error_errno(r, "Failed to create /run/nologin: %m");