summaryrefslogtreecommitdiff
path: root/mdstat.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2004-06-04 12:03:19 +0000
committerNeil Brown <neilb@suse.de>2004-06-04 12:03:19 +0000
commitdd0781e50555c32ff2f808ec46f4b03a5693ea47 (patch)
treea423ae6f7033fa5e05dcf60f2b3659e38c9d5cb7 /mdstat.c
parent98c6faba80e6db0693f99faf5c6525ef4f1fb680 (diff)
mdadm-1.6.0
Diffstat (limited to 'mdstat.c')
-rw-r--r--mdstat.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/mdstat.c b/mdstat.c
index 9711e54a..3204d2e4 100644
--- a/mdstat.c
+++ b/mdstat.c
@@ -85,6 +85,7 @@
#include "mdadm.h"
#include "dlink.h"
+#include <sys/select.h>
void free_mdstat(struct mdstat_ent *ms)
{
@@ -99,13 +100,18 @@ void free_mdstat(struct mdstat_ent *ms)
}
}
-struct mdstat_ent *mdstat_read()
+static int mdstat_fd = -1;
+struct mdstat_ent *mdstat_read(int hold)
{
FILE *f;
struct mdstat_ent *all, **end;
char *line;
- f = fopen("/proc/mdstat", "r");
+ if (hold && mdstat_fd != -1) {
+ lseek(mdstat_fd, 0L, 0);
+ f = fdopen(dup(mdstat_fd), "r");
+ } else
+ f = fopen("/proc/mdstat", "r");
if (f == NULL)
return NULL;
@@ -141,8 +147,7 @@ struct mdstat_ent *mdstat_read()
if (!ent) {
fprintf(stderr, Name ": malloc failed reading /proc/mdstat.\n");
free_line(line);
- fclose(f);
- return all;
+ break;
}
ent->dev = ent->level = ent->pattern= NULL;
ent->next = NULL;
@@ -184,6 +189,20 @@ struct mdstat_ent *mdstat_read()
*end = ent;
end = &ent->next;
}
+ if (hold && mdstat_fd == -1)
+ mdstat_fd = dup(fileno(f));
fclose(f);
return all;
}
+
+void mdstat_wait(int seconds)
+{
+ fd_set fds;
+ struct timeval tm;
+ FD_ZERO(&fds);
+ if (mdstat_fd >= 0)
+ FD_SET(mdstat_fd, &fds);
+ tm.tv_sec = seconds;
+ tm.tv_usec = 0;
+ select(mdstat_fd >2 ? mdstat_fd+1:3, NULL, NULL, &fds, &tm);
+}