diff options
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 87 |
1 files changed, 56 insertions, 31 deletions
@@ -23,8 +23,5 @@ open_listener () if (listen_sockaddr.sa == NULL) - { - logmsg (LOG_CRIT, _("listener address is not configured")); - exit (EX_CONFIG); - } + return -1; fd = socket (listen_sockaddr.sa->sa_family, SOCK_STREAM, 0); @@ -100,5 +97,5 @@ handle_connection (FILE *in, FILE *out) char *buf = NULL; size_t buflen = 0; - const struct spool *spool; + struct spool *spool; char *p; struct passwd *pw; @@ -175,5 +172,20 @@ 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 (); signal (SIGHUP, sig_hup); @@ -183,19 +195,14 @@ wydawca_listener () while (!terminate) { - int fd; - FILE *in, *out; int rc; fd_set rset; struct timeval to, *pto; - union { - struct sockaddr sa; - struct sockaddr_in s_in; - struct sockaddr_un s_un; - } addr; - socklen_t len; job_queue_runner (); FD_ZERO (&rset); - FD_SET (ctlfd, &rset); + if (ctlfd != -1) + FD_SET (ctlfd, &rset); + if (wfd != -1) + FD_SET (wfd, &rset); if (wakeup_interval) @@ -208,5 +215,5 @@ wydawca_listener () pto = NULL; - rc = select (ctlfd + 1, &rset, NULL, NULL, pto); + rc = select (maxfd + 1, &rset, NULL, NULL, pto); if (rc == 0) continue; @@ -219,24 +226,42 @@ 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); + } } } |