summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-15 18:08:59 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-17 02:26:22 -0500
commit141a79f491fd4bf5ea0d66039065c9f9649bfc0e (patch)
tree9e13ad2015007d047b195661d2945c603770bb98 /src/fstab-generator
parent8fe63cd4f16e1e7cdf528ff053f8eb4da7848455 (diff)
Extract looping over /proc/cmdline into a shared function
In cryptsetup-generator automatic cleanup had to be replaced with manual cleanup, and the code gets a bit longer. But existing code had the issue that it returned negative values from main(), which was wrong, so should be reworked anyway.
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 0336888b0..5521a864d 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -501,47 +501,30 @@ static int parse_new_root_from_proc_cmdline(void) {
return (r < 0) ? r : 0;
}
-static int parse_proc_cmdline(void) {
- _cleanup_free_ char *line = NULL;
- char *w, *state;
- size_t l;
+static int parse_proc_cmdline_word(const char *word) {
int r;
- r = proc_cmdline(&line);
- if (r < 0)
- log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
- if (r <= 0)
- return 0;
-
- FOREACH_WORD_QUOTED(w, l, line, state) {
- _cleanup_free_ char *word = NULL;
+ if (startswith(word, "fstab=")) {
+ r = parse_boolean(word + 6);
+ if (r < 0)
+ log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
+ else
+ arg_enabled = r;
- word = strndup(w, l);
- if (!word)
- return log_oom();
+ } else if (startswith(word, "rd.fstab=")) {
- if (startswith(word, "fstab=")) {
- r = parse_boolean(word + 6);
+ if (in_initrd()) {
+ r = parse_boolean(word + 9);
if (r < 0)
- log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
+ log_warning("Failed to parse fstab switch %s. Ignoring.", word + 9);
else
arg_enabled = r;
+ }
- } else if (startswith(word, "rd.fstab=")) {
-
- if (in_initrd()) {
- r = parse_boolean(word + 9);
- if (r < 0)
- log_warning("Failed to parse fstab switch %s. Ignoring.", word + 9);
- else
- arg_enabled = r;
- }
-
- } else if (startswith(word, "fstab.") ||
- (in_initrd() && startswith(word, "rd.fstab."))) {
+ } else if (startswith(word, "fstab.") ||
+ (in_initrd() && startswith(word, "rd.fstab."))) {
- log_warning("Unknown kernel switch %s. Ignoring.", word);
- }
+ log_warning("Unknown kernel switch %s. Ignoring.", word);
}
return 0;
@@ -564,7 +547,7 @@ int main(int argc, char *argv[]) {
umask(0022);
- if (parse_proc_cmdline() < 0)
+ if (parse_proc_cmdline(parse_proc_cmdline_word) < 0)
return EXIT_FAILURE;
if (in_initrd())