chiark / gitweb /
Extract looping over /proc/cmdline into a shared function
[elogind.git] / src / fstab-generator / fstab-generator.c
index 1227f0895dbe4915ee395f89731974d8d7be51c0..5521a864df478ee139b6a27c7fc5a89630ba2882 100644 (file)
@@ -152,6 +152,11 @@ static int add_fsck(FILE *f, const char *what, const char *where, const char *ty
         if (passno == 0)
                 return 0;
 
+        if (!is_device_path(what)) {
+                log_warning("Checking was requested for \"%s\", but it is not a device.", what);
+                return 0;
+        }
+
         if (type && !streq(type, "auto")) {
                 int r;
                 const char *checker;
@@ -171,7 +176,7 @@ static int add_fsck(FILE *f, const char *what, const char *where, const char *ty
 
                 lnk = strappenda(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
                 mkdir_parents_label(lnk, 0755);
-                if (symlink("systemd-fsck-root.service", lnk) < 0) {
+                if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
                         log_error("Failed to create symlink %s: %m", lnk);
                         return -errno;
                 }
@@ -496,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;
@@ -559,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())