More consistent honoring of --configfile
authorNeil Brown <neilb@suse.de>
Mon, 26 Jun 2006 05:11:01 +0000 (15:11 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 26 Jun 2006 05:11:01 +0000 (15:11 +1000)
 Never use /etc/mdadm.conf if --config file is given (previously
some code used one, some used the other).

Assemble.c
ChangeLog
Create.c
Monitor.c
config.c
mdadm.c
mdadm.h
mdassemble.c
mdopen.c

index 90a9c57..3c00c91 100644 (file)
@@ -51,7 +51,7 @@ static int name_matches(char *found, char *required, char *homehost)
 }
 
 int Assemble(struct supertype *st, char *mddev, int mdfd,
-            mddev_ident_t ident, char *conffile,
+            mddev_ident_t ident,
             mddev_dev_t devlist, char *backup_file,
             int readonly, int runstop,
             char *update, char *homehost,
@@ -181,7 +181,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
                return 1;
        }
        if (devlist == NULL)
-               devlist = conf_get_devs(conffile);
+               devlist = conf_get_devs();
        else if (mdfd >= 0)
                inargv = 1;
 
index 3ff36ce..f413a9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@ Changes Prior to this release
        code was ever in there)
     -   Work better when no 'ftw' is available, and check to see
        if current uclibc provides ftw.
+    -   Never use /etc/mdadm.conf if --config file is given (previously
+       some code used one, some used the other).
 
 Changes Prior to 2.5.1 release
     -   Various fixes for gcc warnings
index 8149d27..75db382 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -215,7 +215,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        ldsize <<= 9;
                }
                if (st == NULL) {
-                       struct createinfo *ci = conf_get_create_info(NULL);
+                       struct createinfo *ci = conf_get_create_info();
                        if (ci)
                                st = ci->supertype;
                }
index 7a8c071..315fee2 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -54,7 +54,7 @@ static char *percentalerts[] = {
 int Monitor(mddev_dev_t devlist,
            char *mailaddr, char *alert_cmd,
            int period, int daemonise, int scan, int oneshot,
-           int dosyslog, char *config, int test, char* pidfile)
+           int dosyslog, int test, char* pidfile)
 {
        /*
         * Every few seconds, scan every md device looking for changes
@@ -116,15 +116,15 @@ int Monitor(mddev_dev_t devlist,
        char *mailfrom = NULL;
 
        if (!mailaddr) {
-               mailaddr = conf_get_mailaddr(config);
+               mailaddr = conf_get_mailaddr();
                if (mailaddr && ! scan)
                        fprintf(stderr, Name ": Monitor using email address \"%s\" from config file\n",
                               mailaddr);
        }
-       mailfrom = conf_get_mailfrom(config);
+       mailfrom = conf_get_mailfrom();
 
        if (!alert_cmd) {
-               alert_cmd = conf_get_program(config);
+               alert_cmd = conf_get_program();
                if (alert_cmd && ! scan)
                        fprintf(stderr, Name ": Monitor using program \"%s\" from config file\n",
                               alert_cmd);
@@ -163,7 +163,7 @@ int Monitor(mddev_dev_t devlist,
        }
 
        if (devlist == NULL) {
-               mddev_ident_t mdlist = conf_get_ident(config, NULL);
+               mddev_ident_t mdlist = conf_get_ident(NULL);
                for (; mdlist; mdlist=mdlist->next) {
                        struct state *st = malloc(sizeof *st);
                        if (st == NULL)
@@ -184,7 +184,7 @@ int Monitor(mddev_dev_t devlist,
        } else {
                mddev_dev_t dv;
                for (dv=devlist ; dv; dv=dv->next) {
-                       mddev_ident_t mdlist = conf_get_ident(config, dv->devname);
+                       mddev_ident_t mdlist = conf_get_ident(dv->devname);
                        struct state *st = malloc(sizeof *st);
                        if (st == NULL)
                                continue;
index 157bdff..b43e79c 100644 (file)
--- a/config.c
+++ b/config.c
@@ -578,7 +578,13 @@ void homehostline(char *line)
 
 int loaded = 0;
 
-void load_conffile(char *conffile)
+static char *conffile = NULL;
+void set_conffile(char *file)
+{
+       conffile = file;
+}
+
+void load_conffile(void)
 {
        FILE *f;
        char *line;
@@ -650,47 +656,47 @@ void load_conffile(char *conffile)
 /*    printf("got file\n"); */
 }
 
-char *conf_get_mailaddr(char *conffile)
+char *conf_get_mailaddr(void)
 {
-       load_conffile(conffile);
+       load_conffile();
        return alert_email;
 }
 
-char *conf_get_mailfrom(char *conffile)
+char *conf_get_mailfrom(void)
 {
-       load_conffile(conffile);
+       load_conffile();
        return alert_mail_from;
 }
 
-char *conf_get_program(char *conffile)
+char *conf_get_program(void)
 {
-       load_conffile(conffile);
+       load_conffile();
        return alert_program;
 }
 
-char *conf_get_homehost(char *conffile)
+char *conf_get_homehost(void)
 {
-       load_conffile(conffile);
+       load_conffile();
        return home_host;
 }
 
-struct createinfo *conf_get_create_info(char *conffile)
+struct createinfo *conf_get_create_info(void)
 {
-       load_conffile(conffile);
+       load_conffile();
        return &createinfo;
 }
 
-mddev_ident_t conf_get_ident(char *conffile, char *dev)
+mddev_ident_t conf_get_ident(char *dev)
 {
        mddev_ident_t rv;
-       load_conffile(conffile);
+       load_conffile();
        rv = mddevlist;
        while (dev && rv && strcmp(dev, rv->devname)!=0)
                rv = rv->next;
        return rv;
 }
 
-mddev_dev_t conf_get_devs(char *conffile)
+mddev_dev_t conf_get_devs()
 {
        glob_t globbuf;
        struct conf_dev *cd;
@@ -705,7 +711,7 @@ mddev_dev_t conf_get_devs(char *conffile)
                free(t);
        }
     
-       load_conffile(conffile);
+       load_conffile();
 
        if (cdevlist == NULL)
                /* default to 'partitions */
diff --git a/mdadm.c b/mdadm.c
index c5035b8..e7c53d4 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -605,6 +605,7 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                        configfile = optarg;
+                       set_conffile(configfile);
                        /* FIXME possibly check that config file exists.  Even parse it */
                        continue;
                case O(ASSEMBLE,'s'): /* scan */
@@ -911,7 +912,7 @@ int main(int argc, char *argv[])
        }
 
        if (homehost == NULL)
-               homehost = conf_get_homehost(configfile);
+               homehost = conf_get_homehost();
        if (homehost && strcmp(homehost, "<system>")==0) {
                if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
                        sys_hostname[sizeof(sys_hostname)-1] = 0;
@@ -937,7 +938,7 @@ int main(int argc, char *argv[])
                if (devs_found == 1 && ident.uuid_set == 0 &&
                    ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) {
                        /* Only a device has been given, so get details from config file */
-                       mddev_ident_t array_ident = conf_get_ident(configfile, devlist->devname);
+                       mddev_ident_t array_ident = conf_get_ident(devlist->devname);
                        if (array_ident == NULL) {
                                fprintf(stderr, Name ": %s not identified in config file.\n",
                                        devlist->devname);
@@ -948,14 +949,14 @@ int main(int argc, char *argv[])
                                if (mdfd < 0)
                                        rv |= 1;
                                else {
-                                       rv |= Assemble(ss, devlist->devname, mdfd, array_ident, configfile,
+                                       rv |= Assemble(ss, devlist->devname, mdfd, array_ident,
                                                       NULL, backup_file,
                                                       readonly, runstop, update, homehost, verbose-quiet, force);
                                        close(mdfd);
                                }
                        }
                } else if (!scan)
-                       rv = Assemble(ss, devlist->devname, mdfd, &ident, configfile,
+                       rv = Assemble(ss, devlist->devname, mdfd, &ident,
                                      devlist->next, backup_file,
                                      readonly, runstop, update, homehost, verbose-quiet, force);
                else if (devs_found>0) {
@@ -968,7 +969,7 @@ int main(int argc, char *argv[])
                                exit(1);
                        }
                        for (dv = devlist ; dv ; dv=dv->next) {
-                               mddev_ident_t array_ident = conf_get_ident(configfile, dv->devname);
+                               mddev_ident_t array_ident = conf_get_ident(dv->devname);
                                if (array_ident == NULL) {
                                        fprintf(stderr, Name ": %s not identified in config file.\n",
                                                dv->devname);
@@ -981,14 +982,14 @@ int main(int argc, char *argv[])
                                        rv |= 1;
                                        continue;
                                }
-                               rv |= Assemble(ss, dv->devname, mdfd, array_ident, configfile,
+                               rv |= Assemble(ss, dv->devname, mdfd, array_ident,
                                               NULL, backup_file,
                                               readonly, runstop, update, homehost, verbose-quiet, force);
                                close(mdfd);
                        }
                } else {
-                       mddev_ident_t array_list =  conf_get_ident(configfile, NULL);
-                       mddev_dev_t devlist = conf_get_devs(configfile);
+                       mddev_ident_t array_list =  conf_get_ident(NULL);
+                       mddev_dev_t devlist = conf_get_devs();
                        int cnt = 0;
                        if (devlist == NULL) {
                                fprintf(stderr, Name ": No devices listed in conf file were found.\n");
@@ -1015,7 +1016,7 @@ int main(int argc, char *argv[])
                                        ;
                                else {
                                        rv |= Assemble(ss, array_list->devname, mdfd,
-                                                      array_list, configfile,
+                                                      array_list,
                                                       devlist, NULL,
                                                       readonly, runstop, NULL, homehost, verbose-quiet, force);
                                        if (rv == 0) cnt++;
@@ -1034,7 +1035,7 @@ int main(int argc, char *argv[])
                                        acnt = 0;
                                        do {
                                                rv2 = Assemble(ss, NULL, -1,
-                                                              &ident, configfile,
+                                                              &ident,
                                                               devlist, NULL,
                                                               readonly, runstop, NULL, homehost, verbose-quiet, force);
                                                if (rv2==0) {
@@ -1048,7 +1049,7 @@ int main(int argc, char *argv[])
                                                        auto_update_home = 0;
                                        } while (rv2!=2);
                                        /* Incase there are stacked devices, we need to go around again */
-                                       devlist = conf_get_devs(configfile);
+                                       devlist = conf_get_devs();
                                } while (acnt);
                                if (cnt == 0 && auto_update_home && homehost) {
                                        /* Nothing found, maybe we need to bootstrap homehost info */
@@ -1056,7 +1057,7 @@ int main(int argc, char *argv[])
                                                acnt = 0;
                                                do {
                                                        rv2 = Assemble(ss, NULL, -1,
-                                                                      &ident, configfile,
+                                                                      &ident,
                                                                       devlist, NULL,
                                                                       readonly, runstop, "homehost", homehost, verbose-quiet, force);
                                                        if (rv2==0) {
@@ -1065,7 +1066,7 @@ int main(int argc, char *argv[])
                                                        }
                                                } while (rv2!=2);
                                                /* Incase there are stacked devices, we need to go around again */
-                                               devlist = conf_get_devs(configfile);
+                                               devlist = conf_get_devs();
                                        } while (acnt);
                                }
                                if (cnt == 0 && rv == 0) {
@@ -1118,7 +1119,7 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                        if (devlist == NULL)
-                               devlist = conf_get_devs(configfile);
+                               devlist = conf_get_devs();
                        if (devlist == NULL) {
                                fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile);
                                exit(1);
@@ -1222,7 +1223,7 @@ int main(int argc, char *argv[])
                }
                rv= Monitor(devlist, mailaddr, program,
                            delay?delay:60, daemonise, scan, oneshot,
-                           dosyslog, configfile, test, pidfile);
+                           dosyslog, test, pidfile);
                break;
 
        case GROW:
diff --git a/mdadm.h b/mdadm.h
index 6afdf86..420e6a3 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -389,7 +389,6 @@ extern int Grow_restart(struct supertype *st, struct mdinfo *info,
 
 extern int Assemble(struct supertype *st, char *mddev, int mdfd,
                    mddev_ident_t ident,
-                   char *conffile,
                    mddev_dev_t devlist, char *backup_file,
                    int readonly, int runstop,
                    char *update, char *homehost,
@@ -415,7 +414,7 @@ extern int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust,
 extern int Monitor(mddev_dev_t devlist,
                   char *mailaddr, char *alert_cmd,
                   int period, int daemonise, int scan, int oneshot,
-                  int dosyslog, char *config, int test, char *pidfile);
+                  int dosyslog, int test, char *pidfile);
 
 extern int Kill(char *dev, int force, int quiet);
 
@@ -439,13 +438,14 @@ extern int dev_open(char *dev, int flags);
 extern int is_standard(char *dev, int *nump);
 
 extern int parse_auto(char *str, char *msg, int config);
-extern mddev_ident_t conf_get_ident(char *conffile, char *dev);
-extern mddev_dev_t conf_get_devs(char *conffile);
-extern struct createinfo *conf_get_create_info(char *conffile);
-extern char *conf_get_mailaddr(char *conffile);
-extern char *conf_get_mailfrom(char *conffile);
-extern char *conf_get_program(char *conffile);
-extern char *conf_get_homehost(char *conffile);
+extern mddev_ident_t conf_get_ident(char *dev);
+extern mddev_dev_t conf_get_devs(void);
+extern struct createinfo *conf_get_create_info(void);
+extern void set_conffile(char *file);
+extern char *conf_get_mailaddr(void);
+extern char *conf_get_mailfrom(void);
+extern char *conf_get_program(void);
+extern char *conf_get_homehost(void);
 extern char *conf_line(FILE *file);
 extern char *conf_word(FILE *file, int allow_key);
 extern void free_line(char *line);
index 85b695c..1de5688 100644 (file)
@@ -71,7 +71,6 @@ int open_mddev(char *dev, int autof/*unused */)
 }
 #endif
 
-char *configfile = NULL;
 int rv;
 int mdfd = -1;
 int runstop = 0;
@@ -80,7 +79,7 @@ int verbose = 0;
 int force = 0;
 
 int main(int argc, char *argv[]) {
-       mddev_ident_t array_list =  conf_get_ident(configfile, NULL);
+       mddev_ident_t array_list =  conf_get_ident(NULL);
        if (!array_list) {
                fprintf(stderr, Name ": No arrays found in config file\n");
                rv = 1;
@@ -96,7 +95,7 @@ int main(int argc, char *argv[]) {
                                /* already assembled, skip */
                                continue;
                        rv |= Assemble(array_list->st, array_list->devname, mdfd,
-                                          array_list, configfile,
+                                          array_list,
                                           NULL, NULL,
                                           readonly, runstop, NULL, NULL, verbose, force);
                }
index 534a509..3004d4a 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -94,7 +94,7 @@ int open_mddev(char *dev, int autof)
        int must_remove = 0;
        struct mdstat_ent *mdlist;
        int num;
-       struct createinfo *ci = conf_get_create_info(NULL);
+       struct createinfo *ci = conf_get_create_info();
        int parts;
 
        if (autof == 0)