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