]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Grow: ensure clean abort if we cannot read the 'completed' file.
authorNeilBrown <neilb@suse.de>
Wed, 27 Jul 2011 07:26:12 +0000 (17:26 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 27 Jul 2011 07:26:12 +0000 (17:26 +1000)
If a read of 'completed' returns an error, select will never fail, so
this loop would never exit.

Signed-off-by: NeilBrown <neilb@suse.de>
Grow.c
sysfs.c

diff --git a/Grow.c b/Grow.c
index e4fc2221ad782337e0550f7720a220c9129763f2..1aab1132f2374b0ff741def3f26b94e989c17c8a 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -2725,15 +2725,21 @@ check_progress:
                int rv = -2;
                tv.tv_sec = 10;
                tv.tv_usec = 0;
-               while (fd >= 0 && rv < 0) {
+               while (fd >= 0 && rv < 0 && tv.tv_sec > 0) {
                        fd_set rfds;
                        FD_ZERO(&rfds);
                        FD_SET(fd, &rfds);
                        if (select(fd+1, NULL, NULL, &rfds, &tv) != 1)
                                break;
-                       if (sysfs_fd_get_ll(fd, &completed) >= 0)
+                       switch (sysfs_fd_get_ll(fd, &completed)) {
+                       case 0:
                                /* all good again */
                                rv = 1;
+                               break;
+                       case -2: /* read error - abort */
+                               tv.tv_sec = 0;
+                               break;
+                       }
                }
                if (fd >= 0)
                        close(fd);
diff --git a/sysfs.c b/sysfs.c
index 44314baf59334943f3e551583a4d498005e1fa38..56813b7d6ae0811dd5289fdbd5da7a8337932667 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -470,7 +470,7 @@ int sysfs_fd_get_ll(int fd, unsigned long long *val)
        lseek(fd, 0, 0);
        n = read(fd, buf, sizeof(buf));
        if (n <= 0)
-               return -1;
+               return -2;
        buf[n] = 0;
        *val = strtoull(buf, &ep, 0);
        if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))