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