]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
config: support MDADM_CONF_AUTO= env var.
[thirdparty/mdadm.git] / config.c
index edadf02a6859a19e83f176b8f7e6b76d62963625..f1a70c59f971575212a2c4d1937f6c586316b6f1 100644 (file)
--- a/config.c
+++ b/config.c
@@ -602,6 +602,24 @@ void autoline(char *line)
         * been seen gets an appropriate auto= entry.
         */
 
+       /* If environment variable MDADM_CONF_AUTO is defined, then
+        * it is prepended to the auto line.  This allow a script
+        * to easily disable some metadata types.
+        */
+       w = getenv("MDADM_CONF_AUTO");
+       if (w && *w) {
+               char *l = xstrdup(w);
+               char *head = line;
+               w = strtok(l, " \t");
+               while (w) {
+                       char *nw = dl_strdup(w);
+                       dl_insert(head, nw);
+                       head = nw;
+                       w = strtok(NULL, " \t");
+               }
+               free(l);
+       }
+
        for (super_cnt = 0; superlist[super_cnt]; super_cnt++)
                ;
        seen = xcalloc(super_cnt, 1);
@@ -783,6 +801,7 @@ void load_conffile(void)
 {
        FILE *f;
        char *confdir = NULL;
+       char *head;
 
        if (loaded)
                return;
@@ -824,6 +843,14 @@ void load_conffile(void)
                        }
                }
        }
+       /* If there was no AUTO line, process an empty line
+        * now so that the MDADM_CONF_AUTO env var gets processed.
+        */
+       head = dl_strdup("AUTO");
+       dl_init(head);
+       autoline(head);
+       free_line(head);
+
        loaded = 1;
 }