]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/volatile-util.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / shared / volatile-util.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
a4c35b6b 2
dccca82b
LP
3#include <errno.h>
4
91214a37 5#include "alloc-util.h"
a4c35b6b
LP
6#include "macro.h"
7#include "parse-util.h"
91214a37 8#include "proc-cmdline.h"
081a0c72 9#include "string-table.h"
a4c35b6b
LP
10#include "string-util.h"
11#include "volatile-util.h"
12
91214a37
LP
13int query_volatile_mode(VolatileMode *ret) {
14 _cleanup_free_ char *mode = NULL;
15 VolatileMode m = VOLATILE_NO;
16 int r;
17
18 r = proc_cmdline_get_key("systemd.volatile", PROC_CMDLINE_VALUE_OPTIONAL, &mode);
19 if (r < 0)
20 return r;
21 if (r == 0)
22 goto finish;
23
24 if (mode) {
25 m = volatile_mode_from_string(mode);
26 if (m < 0)
27 return -EINVAL;
28 } else
29 m = VOLATILE_YES;
30
31 r = 1;
32
33finish:
34 *ret = m;
35 return r;
36}
081a0c72
LP
37
38static const char* const volatile_mode_table[_VOLATILE_MODE_MAX] = {
39 [VOLATILE_NO] = "no",
40 [VOLATILE_YES] = "yes",
41 [VOLATILE_STATE] = "state",
42};
43
44DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(volatile_mode, VolatileMode, VOLATILE_YES);