mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
basic: split out update_reboot_parameter_and_warn() into its own .c/.h files
This is primarily preparation for a follow-up commit that adds a common implementation of the other side of the reboot parameter file, i.e. the code that reads the file and issues reboot() for it.
This commit is contained in:
parent
118cf9523b
commit
e3631d1c80
@ -158,6 +158,8 @@ basic_sources = files('''
|
||||
ratelimit.h
|
||||
raw-clone.h
|
||||
raw-reboot.h
|
||||
reboot-util.c
|
||||
reboot-util.h
|
||||
refcnt.h
|
||||
replace-var.c
|
||||
replace-var.h
|
||||
|
34
src/basic/reboot-util.c
Normal file
34
src/basic/reboot-util.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "reboot-util.h"
|
||||
#include "string-util.h"
|
||||
#include "umask-util.h"
|
||||
|
||||
int update_reboot_parameter_and_warn(const char *parameter) {
|
||||
int r;
|
||||
|
||||
if (isempty(parameter)) {
|
||||
if (unlink("/run/systemd/reboot-param") < 0) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
return log_warning_errno(errno, "Failed to unlink reboot parameter file: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_WITH_UMASK(0022) {
|
||||
r = write_string_file("/run/systemd/reboot-param", parameter,
|
||||
WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to write reboot parameter file: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
4
src/basic/reboot-util.h
Normal file
4
src/basic/reboot-util.h
Normal file
@ -0,0 +1,4 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
int update_reboot_parameter_and_warn(const char *parameter);
|
@ -518,29 +518,6 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
|
||||
return m / max;
|
||||
}
|
||||
|
||||
int update_reboot_parameter_and_warn(const char *param) {
|
||||
int r;
|
||||
|
||||
if (isempty(param)) {
|
||||
if (unlink("/run/systemd/reboot-param") < 0) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
|
||||
return log_warning_errno(errno, "Failed to unlink reboot parameter file: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_WITH_UMASK(0022) {
|
||||
r = write_string_file("/run/systemd/reboot-param", param, WRITE_STRING_FILE_CREATE);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to write reboot parameter file: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int version(void) {
|
||||
puts(PACKAGE_STRING "\n"
|
||||
SYSTEMD_FEATURES);
|
||||
|
@ -186,8 +186,6 @@ uint64_t physical_memory_scale(uint64_t v, uint64_t max);
|
||||
uint64_t system_tasks_max(void);
|
||||
uint64_t system_tasks_max_scale(uint64_t v, uint64_t max);
|
||||
|
||||
int update_reboot_parameter_and_warn(const char *param);
|
||||
|
||||
int version(void);
|
||||
|
||||
int str_verscmp(const char *s1, const char *s2);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "bus-util.h"
|
||||
#include "emergency-action.h"
|
||||
#include "raw-reboot.h"
|
||||
#include "reboot-util.h"
|
||||
#include "special.h"
|
||||
#include "string-table.h"
|
||||
#include "terminal-util.h"
|
||||
|
@ -73,6 +73,7 @@
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "raw-reboot.h"
|
||||
#include "reboot-util.h"
|
||||
#include "rlimit-util.h"
|
||||
#include "set.h"
|
||||
#include "sigbus.h"
|
||||
|
Loading…
Reference in New Issue
Block a user