]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Monitor.c
More consistent honoring of --configfile
[thirdparty/mdadm.git] / Monitor.c
index d52b418293e34212191322243653bdb25e734201..315fee2548cb03a8b3459b49428dcad7d24bdeed 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -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;
@@ -383,6 +383,7 @@ int Monitor(mddev_dev_t devlist,
                                            ioctl(fd, GET_ARRAY_INFO, &array)< 0) {
                                                /* no such array */
                                                if (fd >=0) close(fd);
+                                               put_md_name(st->devname);
                                                free(st->devname);
                                                free(st);
                                                continue;
@@ -489,9 +490,11 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
        if (mailaddr && 
            (strncmp(event, "Fail", 4)==0 || 
             strncmp(event, "Test", 4)==0 ||
+            strncmp(event, "Spares", 6)==0 ||
             strncmp(event, "Degrade", 7)==0)) {
                FILE *mp = popen(Sendmail, "w");
                if (mp) {
+                       FILE *mdstat;
                        char hname[256];
                        gethostname(hname, sizeof(hname));
                        signal(SIGPIPE, SIG_IGN);
@@ -511,6 +514,16 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
                                fprintf(mp, "It could be related to component device %s.\n\n", disc);
 
                        fprintf(mp, "Faithfully yours, etc.\n");
+
+                       mdstat = fopen("/proc/mdstat", "r");
+                       if (mdstat) {
+                               char buf[8192];
+                               int n;
+                               fprintf(mp, "\nP.S. The /proc/mdstat file currently contains the following:\n\n");
+                               while ( (n=fread(buf, 1, sizeof(buf), mdstat)) > 0)
+                                       n=fwrite(buf, 1, n, mp); /* yes, i don't care about the result */
+                               fclose(mdstat);
+                       }
                        fclose(mp);
                }
 
@@ -527,7 +540,8 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail
                        priority = LOG_CRIT;
                /* Good to know about, but are not failures: */
                else if (strncmp(event, "Rebuild", 7)==0 ||
-                        strncmp(event, "MoveSpare", 9)==0)
+                        strncmp(event, "MoveSpare", 9)==0 ||
+                        strncmp(event, "Spares", 6) != 0)
                        priority = LOG_WARNING;
                /* Everything else: */
                else