summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-12 18:29:15 +0100
committerLennart Poettering <lennart@poettering.net>2016-12-21 19:09:08 +0100
commit1d84ad944520fc3e062ef518c4db4e1d3a1866af (patch)
treef1761716cb0471e4ceb54df72c2d1eb9e4430487 /src/fstab-generator
parent2467cc55f139cf540dc1ed6da5f3774fcbab4475 (diff)
util-lib: various improvements to kernel command line parsing
This improves kernel command line parsing in a number of ways: a) An kernel option "foo_bar=xyz" is now considered equivalent to "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and "_" are now considered equivalent (this only applies to the option names though, not the option values!). Most of our kernel options used "-" as word separator in kernel command line options so far, but some used "_". With this change, which was a source of confusion for users (well, at least of one user: myself, I just couldn't remember that it's systemd.debug-shell, not systemd.debug_shell). Considering both as equivalent is inspired how modern kernel module loading normalizes all kernel module names to use underscores now too. b) All options previously using a dash for separating words in kernel command line options now use an underscore instead, in all documentation and in code. Since a) has been implemented this should not create any compatibility problems, but normalizes our documentation and our code. c) All kernel command line options which take booleans (or are boolean-like) have been reworked so that "foobar" (without argument) is now equivalent to "foobar=1" (but not "foobar=0"), thus normalizing the handling of our boolean arguments. Specifically this means systemd.debug-shell and systemd_debug_shell=1 are now entirely equivalent. d) All kernel command line options which take an argument, and where no argument is specified will now result in a log message. e.g. passing just "systemd.unit" will no result in a complain that it needs an argument. This is implemented in the proc_cmdline_missing_value() function. e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key() that parses booleans (following the logic explained in c). f) The proc_cmdline_parse() call's boolean argument has been replaced by a new flags argument that takes a common set of bits with proc_cmdline_get_key(). g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix. h) There are now tests for much of this. Yay!
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index f6a912ae06..84163abbc5 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -612,27 +612,36 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
* instance should take precedence. In the case of multiple rootflags=
* or usrflags= the arguments should be concatenated */
- if (STR_IN_SET(key, "fstab", "rd.fstab") && value) {
+ if (STR_IN_SET(key, "fstab", "rd.fstab")) {
- r = parse_boolean(value);
+ r = value ? parse_boolean(value) : 1;
if (r < 0)
log_warning("Failed to parse fstab switch %s. Ignoring.", value);
else
arg_fstab_enabled = r;
- } else if (streq(key, "root") && value) {
+ } else if (streq(key, "root")) {
+
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
if (free_and_strdup(&arg_root_what, value) < 0)
return log_oom();
- } else if (streq(key, "rootfstype") && value) {
+ } else if (streq(key, "rootfstype")) {
+
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
if (free_and_strdup(&arg_root_fstype, value) < 0)
return log_oom();
- } else if (streq(key, "rootflags") && value) {
+ } else if (streq(key, "rootflags")) {
char *o;
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
+
o = arg_root_options ?
strjoin(arg_root_options, ",", value) :
strdup(value);
@@ -642,19 +651,28 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
free(arg_root_options);
arg_root_options = o;
- } else if (streq(key, "mount.usr") && value) {
+ } else if (streq(key, "mount.usr")) {
+
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
if (free_and_strdup(&arg_usr_what, value) < 0)
return log_oom();
- } else if (streq(key, "mount.usrfstype") && value) {
+ } else if (streq(key, "mount.usrfstype")) {
+
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
if (free_and_strdup(&arg_usr_fstype, value) < 0)
return log_oom();
- } else if (streq(key, "mount.usrflags") && value) {
+ } else if (streq(key, "mount.usrflags")) {
char *o;
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
+
o = arg_usr_options ?
strjoin(arg_usr_options, ",", value) :
strdup(value);
@@ -689,7 +707,7 @@ int main(int argc, char *argv[]) {
umask(0022);
- r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, false);
+ r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
if (r < 0)
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");