]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/volatile-util.c
Update mailmap and contributor list (#7006)
[thirdparty/systemd.git] / src / shared / volatile-util.c
CommitLineData
a4c35b6b
LP
1/***
2 This file is part of systemd.
3
4 Copyright 2015 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
91214a37 20#include "alloc-util.h"
a4c35b6b
LP
21#include "macro.h"
22#include "parse-util.h"
91214a37 23#include "proc-cmdline.h"
a4c35b6b
LP
24#include "string-util.h"
25#include "volatile-util.h"
26
27VolatileMode volatile_mode_from_string(const char *s) {
28 int b;
29
30 if (isempty(s))
31 return _VOLATILE_MODE_INVALID;
32
33 b = parse_boolean(s);
34 if (b > 0)
35 return VOLATILE_YES;
36 if (b == 0)
37 return VOLATILE_NO;
38
39 if (streq(s, "state"))
40 return VOLATILE_STATE;
41
42 return _VOLATILE_MODE_INVALID;
43}
91214a37
LP
44
45int query_volatile_mode(VolatileMode *ret) {
46 _cleanup_free_ char *mode = NULL;
47 VolatileMode m = VOLATILE_NO;
48 int r;
49
50 r = proc_cmdline_get_key("systemd.volatile", PROC_CMDLINE_VALUE_OPTIONAL, &mode);
51 if (r < 0)
52 return r;
53 if (r == 0)
54 goto finish;
55
56 if (mode) {
57 m = volatile_mode_from_string(mode);
58 if (m < 0)
59 return -EINVAL;
60 } else
61 m = VOLATILE_YES;
62
63 r = 1;
64
65finish:
66 *ret = m;
67 return r;
68}