chiark / gitweb /
journal: when watching directories actually watch the directories asked for
[elogind.git] / src / fstab-generator / fstab-generator.c
index 8419a0c5b45a8e0c1e975847dc120a6d06e4211c..3a59b85d665b5884cbcabc801c91e4bde7e9243c 100644 (file)
 #include "mount-setup.h"
 #include "special.h"
 #include "mkdir.h"
+#include "virt.h"
 
 static const char *arg_dest = "/tmp";
+static bool arg_enabled = true;
 
 static int device_name(const char *path, char **unit) {
         char *p;
@@ -101,7 +103,7 @@ static int add_swap(const char *what, struct mntent *me) {
                 goto finish;
         }
 
-        unit = join(arg_dest, "/", name, NULL);
+        unit = strjoin(arg_dest, "/", name, NULL);
         if (!unit) {
                 log_error("Out of memory");
                 r = -ENOMEM;
@@ -144,7 +146,7 @@ static int add_swap(const char *what, struct mntent *me) {
         }
 
         if (!noauto) {
-                lnk = join(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
+                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
                 if (!lnk) {
                         log_error("Out of memory");
                         r = -ENOMEM;
@@ -167,7 +169,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
                 if (r > 0) {
                         free(lnk);
-                        lnk = join(arg_dest, "/", device, ".wants/", name, NULL);
+                        lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
                         if (!lnk) {
                                 log_error("Out of memory");
                                 r = -ENOMEM;
@@ -259,7 +261,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 goto finish;
         }
 
-        unit = join(arg_dest, "/", name, NULL);
+        unit = strjoin(arg_dest, "/", name, NULL);
         if (!unit) {
                 log_error("Out of memory");
                 r = -ENOMEM;
@@ -319,7 +321,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
         }
 
         if (!noauto) {
-                lnk = join(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
+                lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
                 if (!lnk) {
                         log_error("Out of memory");
                         r = -ENOMEM;
@@ -345,7 +347,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
                         if (r > 0) {
                                 free(lnk);
-                                lnk = join(arg_dest, "/", device, ".wants/", name, NULL);
+                                lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
                                 if (!lnk) {
                                         log_error("Out of memory");
                                         r = -ENOMEM;
@@ -370,7 +372,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                         goto finish;
                 }
 
-                automount_unit = join(arg_dest, "/", automount_name, NULL);
+                automount_unit = strjoin(arg_dest, "/", automount_name, NULL);
                 if (!automount_unit) {
                         log_error("Out of memory");
                         r = -ENOMEM;
@@ -406,7 +408,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 }
 
                 free(lnk);
-                lnk = join(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
+                lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
                 if (!lnk) {
                         log_error("Out of memory");
                         r = -ENOMEM;
@@ -470,9 +472,6 @@ static int parse_fstab(void) {
                         goto finish;
                 }
 
-                if (is_path(what))
-                        path_kill_slashes(what);
-
                 if (is_path(where))
                         path_kill_slashes(where);
 
@@ -495,6 +494,62 @@ finish:
         return r;
 }
 
+static int parse_proc_cmdline(void) {
+        char *line, *w, *state;
+        int r;
+        size_t l;
+
+        if (detect_container(NULL) > 0)
+                return 0;
+
+        r = read_one_line_file("/proc/cmdline", &line);
+        if (r < 0) {
+                log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
+                return 0;
+        }
+
+        FOREACH_WORD_QUOTED(w, l, line, state) {
+                char *word;
+
+                word = strndup(w, l);
+                if (!word) {
+                        r = -ENOMEM;
+                        goto finish;
+                }
+
+                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;
+
+                } else if (startswith(word, "rd.fstab=")) {
+
+                        if (in_initrd()) {
+                                r = parse_boolean(word + 6);
+                                if (r < 0)
+                                        log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
+                                else
+                                        arg_enabled = r;
+                        }
+
+                } else if (startswith(word, "fstab.") ||
+                           (in_initrd() && startswith(word, "rd.fstab."))) {
+
+                        log_warning("Unknown kernel switch %s. Ignoring.", word);
+                }
+
+                free(word);
+        }
+
+        r = 0;
+
+finish:
+        free(line);
+        return r;
+}
+
 int main(int argc, char *argv[]) {
         int r;
 
@@ -512,6 +567,12 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
+        if (parse_proc_cmdline() < 0)
+                return EXIT_FAILURE;
+
+        if (!arg_enabled)
+                return EXIT_SUCCESS;
+
         r = parse_fstab();
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;