summaryrefslogtreecommitdiff
path: root/src/basic/reboot-util.c
blob: 2528d9bbef5cd04488dea0e0a4495b13036672e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}