]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdstat.c
Release 3.2.6 - stability release
[thirdparty/mdadm.git] / mdstat.c
index 3d2edadb494dcad1a7db3528e493e60414741d8a..17405601bd650ba251cd5de65c27352961a5aebd 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -131,10 +131,15 @@ struct mdstat_ent *mdstat_read(int hold, int start)
        FILE *f;
        struct mdstat_ent *all, *rv, **end, **insert_here;
        char *line;
+       int fd;
 
        if (hold && mdstat_fd != -1) {
                lseek(mdstat_fd, 0L, 0);
-               f = fdopen(dup(mdstat_fd), "r");
+               fd = dup(mdstat_fd);
+               if (fd >= 0)
+                       f = fdopen(fd, "r");
+               else
+                       return NULL;
        } else
                f = fopen("/proc/mdstat", "r");
        if (f == NULL)
@@ -180,7 +185,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                }
                ent->dev = ent->level = ent->pattern= NULL;
                ent->next = NULL;
-               ent->percent = -1;
+               ent->percent = RESYNC_NONE;
                ent->active = -1;
                ent->resync = 0;
                ent->metadata_version = NULL;
@@ -235,7 +240,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                                ent->pattern = strdup(w+1);
                                if (ent->pattern[l-2]==']')
                                        ent->pattern[l-2] = '\0';
-                       } else if (ent->percent == -1 &&
+                       } else if (ent->percent == RESYNC_NONE &&
                                   strncmp(w, "re", 2)== 0 &&
                                   w[l-1] == '%' &&
                                   (eq=strchr(w, '=')) != NULL ) {
@@ -246,7 +251,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                                        ent->resync = 2;
                                else
                                        ent->resync = 0;
-                       } else if (ent->percent == -1 &&
+                       } else if (ent->percent == RESYNC_NONE &&
                                   (w[0] == 'r' || w[0] == 'c')) {
                                if (strncmp(w, "resync", 4)==0)
                                        ent->resync = 1;
@@ -257,11 +262,11 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                                if (strncmp(w, "check", 5)==0)
                                        ent->resync = 3;
 
-                               if (l > 8 && strcmp(w+l-8, "=DELAYED"))
-                                       ent->percent = 0;
-                               if (l > 8 && strcmp(w+l-8, "=PENDING"))
-                                       ent->percent = 0;
-                       } else if (ent->percent == -1 &&
+                               if (l > 8 && strcmp(w+l-8, "=DELAYED") == 0)
+                                       ent->percent = RESYNC_DELAYED;
+                               if (l > 8 && strcmp(w+l-8, "=PENDING") == 0)
+                                       ent->percent = RESYNC_PENDING;
+                       } else if (ent->percent == RESYNC_NONE &&
                                   w[0] >= '0' &&
                                   w[0] <= '9' &&
                                   w[l-1] == '%') {