| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "proc-cmdline.h" |
| 5 |
#include "string-table.h" |
| 6 |
#include "volatile-util.h" |
| 7 |
|
| 8 |
int query_volatile_mode(VolatileMode *ret) { |
| 9 |
_cleanup_free_ char *mode = NULL; |
| 10 |
int r; |
| 11 |
|
| 12 |
assert(ret); |
| 13 |
|
| 14 |
r = proc_cmdline_get_key("systemd.volatile", PROC_CMDLINE_VALUE_OPTIONAL, &mode); |
| 15 |
if (r < 0) |
| 16 |
return r; |
| 17 |
if (r == 0) { |
| 18 |
*ret = VOLATILE_NO; |
| 19 |
return 0; |
| 20 |
} |
| 21 |
|
| 22 |
if (mode) { |
| 23 |
VolatileMode m; |
| 24 |
|
| 25 |
m = volatile_mode_from_string(mode); |
| 26 |
if (m < 0) |
| 27 |
return m; |
| 28 |
|
| 29 |
*ret = m; |
| 30 |
} else |
| 31 |
*ret = VOLATILE_YES; |
| 32 |
|
| 33 |
return 1; |
| 34 |
} |
| 35 |
|
| 36 |
static const char* const volatile_mode_table[_VOLATILE_MODE_MAX] = { |
| 37 |
[VOLATILE_NO] = "no", |
| 38 |
[VOLATILE_YES] = "yes", |
| 39 |
[VOLATILE_STATE] = "state", |
| 40 |
[VOLATILE_OVERLAY] = "overlay", |
| 41 |
}; |
| 42 |
|
| 43 |
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(volatile_mode, VolatileMode, VOLATILE_YES); |