lib: Don't close children on mere EAGAINs, but fail and wait for them.
[ashd.git] / lib / cf.c
index 38d9808..86658f8 100644 (file)
--- a/lib/cf.c
+++ b/lib/cf.c
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <glob.h>
 #include <libgen.h>
+#include <sys/socket.h>
 #include <errno.h>
 
 #ifdef HAVE_CONFIG_H
@@ -309,17 +310,19 @@ static int stdhandle(struct child *ch, struct hthead *req, int fd, void (*chinit
     if(i->type == CH_SOCKET) {
        if(i->fd < 0)
            i->fd = stdmkchild(i->argv, chinit, idata);
-       if(sendreq(i->fd, req, fd)) {
+       if(sendreq2(i->fd, req, fd, MSG_NOSIGNAL | MSG_DONTWAIT)) {
            if((errno == EPIPE) || (errno == ECONNRESET)) {
                /* Assume that the child has crashed and restart it. */
                close(i->fd);
                i->fd = stdmkchild(i->argv, chinit, idata);
-               if(!sendreq(i->fd, req, fd))
+               if(!sendreq2(i->fd, req, fd, MSG_NOSIGNAL | MSG_DONTWAIT))
                    return(0);
            }
            flog(LOG_ERR, "could not pass on request to child %s: %s", ch->name, strerror(errno));
-           close(i->fd);
-           i->fd = -1;
+           if(errno != EAGAIN) {
+               close(i->fd);
+               i->fd = -1;
+           }
            return(-1);
        }
     } else if(i->type == CH_FORK) {