summaryrefslogtreecommitdiff
path: root/monitor.c
diff options
context:
space:
mode:
authormwilck@arcor.de <mwilck@arcor.de>2013-10-25 12:07:36 +0200
committerNeilBrown <neilb@suse.de>2013-04-23 14:55:32 +1000
commit2b60d2890faa8b3dc361a163ea745380c1305c96 (patch)
tree78771c931256f0504edd29252140fa1c3cfa2b41 /monitor.c
parent7d5a7ff3dad7195072a198d229d671a747c97304 (diff)
monitor: don't call pselect() on deleted sysfs files
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>
Diffstat (limited to 'monitor.c')
-rw-r--r--monitor.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/monitor.c b/monitor.c
index e034a6a0..3cb42140 100644
--- 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);