diff options
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 87 |
1 files changed, 56 insertions, 31 deletions
@@ -24,6 +24,3 @@ open_listener () if (listen_sockaddr.sa == NULL) - { - logmsg (LOG_CRIT, _("listener address is not configured")); - exit (EX_CONFIG); - } + return -1; @@ -101,3 +98,3 @@ handle_connection (FILE *in, FILE *out) size_t buflen = 0; - const struct spool *spool; + struct spool *spool; char *p; @@ -176,3 +173,18 @@ wydawca_listener () int ctlfd = open_listener (); + int wfd = watcher_init (); + int maxfd = 0; + + if (ctlfd != -1) + maxfd = ctlfd; + + if (wfd != -1 && wfd > maxfd) + maxfd = wfd; + if (maxfd == 0) + { + logmsg (LOG_CRIT, + _("listener address is not configured and inotify is not available")); + exit (EX_CONFIG); + } + job_init (); @@ -184,4 +196,2 @@ wydawca_listener () { - int fd; - FILE *in, *out; int rc; @@ -189,8 +199,2 @@ wydawca_listener () struct timeval to, *pto; - union { - struct sockaddr sa; - struct sockaddr_in s_in; - struct sockaddr_un s_un; - } addr; - socklen_t len; @@ -198,3 +202,6 @@ wydawca_listener () FD_ZERO (&rset); - FD_SET (ctlfd, &rset); + if (ctlfd != -1) + FD_SET (ctlfd, &rset); + if (wfd != -1) + FD_SET (wfd, &rset); @@ -209,3 +216,3 @@ wydawca_listener () - rc = select (ctlfd + 1, &rset, NULL, NULL, pto); + rc = select (maxfd + 1, &rset, NULL, NULL, pto); if (rc == 0) @@ -220,22 +227,40 @@ wydawca_listener () - len = sizeof (addr); - fd = accept (ctlfd, (struct sockaddr*) &addr, &len); - if (fd == -1) - continue; - /* FIXME: Use Mailutils ACLs? */ -#ifdef WITH_LIBWRAP - if (!tcpwrap_access(fd)) + if (wfd != -1 && FD_ISSET (wfd, &rset)) { - close(fd); - continue; + watcher_run (wfd); } + + if (ctlfd != -1 && FD_ISSET (ctlfd, &rset)) + { + int fd; + FILE *in, *out; + union + { + struct sockaddr sa; + struct sockaddr_in s_in; + struct sockaddr_un s_un; + } addr; + socklen_t len; + + len = sizeof (addr); + fd = accept (ctlfd, (struct sockaddr*) &addr, &len); + if (fd == -1) + continue; + /* FIXME: Use Mailutils ACLs? */ +#ifdef WITH_LIBWRAP + if (!tcpwrap_access(fd)) + { + close(fd); + continue; + } #endif - in = fdopen (fd, "r"); - setlinebuf (in); - out = fdopen (fd, "w"); - setlinebuf (out); - handle_connection (in, out); - fclose (in); - fclose (out); + in = fdopen (fd, "r"); + setlinebuf (in); + out = fdopen (fd, "w"); + setlinebuf (out); + handle_connection (in, out); + fclose (in); + fclose (out); + } } |