aboutsummaryrefslogtreecommitdiffstats
path: root/managemon.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2008-05-15 16:48:52 +1000
committerNeil Brown <neilb@suse.de>2008-05-15 16:48:52 +1000
commitb109d92863bfa319d140b305132ca41bfb8d1194 (patch)
tree77e038600e1a454443f1ff37d28b21f27ead8336 /managemon.c
parent0af73f61a25904edc7da24e2da9786b48bb8bec6 (diff)
downloadmdadm-b109d92863bfa319d140b305132ca41bfb8d1194.tar.gz
start fleshing out socket code, ping monitor to see if it is alive
From: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'managemon.c')
-rw-r--r--managemon.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/managemon.c b/managemon.c
index 43c731fa..f8123d0e 100644
--- a/managemon.c
+++ b/managemon.c
@@ -74,6 +74,7 @@
#endif
#include "mdadm.h"
#include "mdmon.h"
+#include "msg.h"
#include <sys/socket.h>
@@ -302,12 +303,35 @@ void manage(struct mdstat_ent *mdstat, struct active_array *aa,
void read_sock(int pfd)
{
int fd;
+ struct md_message msg;
+ int terminate = 0;
+ long fl;
+ int tmo = 3; /* 3 second timeout before hanging up the socket */
- // FIXME set non-blocking
fd = accept(pfd, NULL, NULL);
if (fd < 0)
return;
- // FIXME do something useful
+
+ fl = fcntl(fd, F_GETFL, 0);
+ fl |= O_NONBLOCK;
+ fcntl(fd, F_SETFL, fl);
+
+ do {
+ msg.buf = NULL;
+
+ /* read and validate the message */
+ if (receive_message(fd, &msg, tmo) == 0) {
+ // FIXME: handle message contents
+ ack(fd, msg.seq, tmo);
+ } else {
+ terminate = 1;
+ nack(fd, -1, tmo);
+ }
+
+ if (msg.buf)
+ free(msg.buf);
+ } while (!terminate);
+
close(fd);
}
void do_manager(struct supertype *container)