]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
config: refactor load_conffile() to have a single exit.
[thirdparty/mdadm.git] / config.c
index f0b013886ca45923a89b91a6ce2ba1e2af0e32f5..edadf02a6859a19e83f176b8f7e6b76d62963625 100644 (file)
--- a/config.c
+++ b/config.c
@@ -784,52 +784,47 @@ void load_conffile(void)
        FILE *f;
        char *confdir = NULL;
 
-       if (loaded) return;
+       if (loaded)
+               return;
        if (conffile == NULL) {
                conffile = DefaultConfFile;
                confdir = DefaultConfDir;
        }
 
-       if (strcmp(conffile, "none") == 0) {
-               loaded = 1;
-               return;
-       }
        if (strcmp(conffile, "partitions")==0) {
                char *list = dl_strdup("DEV");
                dl_init(list);
                dl_add(list, dl_strdup("partitions"));
                devline(list);
                free_line(list);
-               loaded = 1;
-               return;
-       }
-       f = fopen(conffile, "r");
-       /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
-        * To allow Debian users to compile from clean source and still
-        * have a working mdadm, we read /etc/mdadm/mdadm.conf
-        * if /etc/mdadm.conf doesn't exist
-        */
-       if (f == NULL &&
-           conffile == DefaultConfFile) {
-               f = fopen(DefaultAltConfFile, "r");
-               if (f) {
-                       conffile = DefaultAltConfFile;
-                       confdir = DefaultAltConfDir;
+       } else if (strcmp(conffile, "none") != 0) {
+               f = fopen(conffile, "r");
+               /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
+                * To allow Debian users to compile from clean source and still
+                * have a working mdadm, we read /etc/mdadm/mdadm.conf
+                * if /etc/mdadm.conf doesn't exist
+                */
+               if (f == NULL &&
+                   conffile == DefaultConfFile) {
+                       f = fopen(DefaultAltConfFile, "r");
+                       if (f) {
+                               conffile = DefaultAltConfFile;
+                               confdir = DefaultAltConfDir;
+                       }
                }
-       }
-       if (f) {
-               loaded = 1;
-               conf_file_or_dir(f);
-               fclose(f);
-       }
-       if (confdir) {
-               f = fopen(confdir, "r");
                if (f) {
-                       loaded = 1;
                        conf_file_or_dir(f);
                        fclose(f);
                }
+               if (confdir) {
+                       f = fopen(confdir, "r");
+                       if (f) {
+                               conf_file_or_dir(f);
+                               fclose(f);
+                       }
+               }
        }
+       loaded = 1;
 }
 
 char *conf_get_mailaddr(void)