]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
monitor: don't call pselect() on deleted sysfs files
authormwilck@arcor.de <mwilck@arcor.de>
Fri, 25 Oct 2013 10:07:36 +0000 (12:07 +0200)
committerNeilBrown <neilb@suse.de>
Tue, 23 Apr 2013 04:55:32 +0000 (14:55 +1000)
It makes no sense to listen for events on files that have
been deleted. This happens when arrays are stopped and the
kernel removes the associated sysfs structures.

Calling pselect() on the deleted attributes may cause a storm
of wake events.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
monitor.c

index e034a6a069923d498184edafceaf084814e4b3c5..3cb421409ffd0105e550865f2287941c9577a797 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -38,8 +38,17 @@ static int write_attr(char *attr, int fd)
 
 static void add_fd(fd_set *fds, int *maxfd, int fd)
 {
+       struct stat st;
        if (fd < 0)
                return;
+       if (fstat(fd, &st) == -1) {
+               dprintf("%s: Invalid fd %d\n", __func__, fd);
+               return;
+       }
+       if (st.st_nlink == 0) {
+               dprintf("%s: fd %d was deleted\n", __func__, fd);
+               return;
+       }
        if (fd > *maxfd)
                *maxfd = fd;
        FD_SET(fd, fds);