diff options
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 53 |
1 files changed, 39 insertions, 14 deletions
@@ -19,16 +19,13 @@ static int open_listener () { int fd; 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); if (fd == -1) { logmsg (LOG_CRIT, _("cannot create socket: %s"), strerror(errno)); @@ -96,13 +93,13 @@ trim_crlf (char *s) void 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; if (grecs_getline (&buf, &buflen, in) <= 0) return; trim_crlf (buf); @@ -171,56 +168,83 @@ sig_term (int sig) } void 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); signal (SIGTERM, sig_term); signal (SIGQUIT, sig_term); signal (SIGINT, sig_term); 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); + if (ctlfd != -1) FD_SET (ctlfd, &rset); + if (wfd != -1) + FD_SET (wfd, &rset); if (wakeup_interval) { to.tv_sec = wakeup_interval; to.tv_usec = 0; *pto = to; } else pto = NULL; - rc = select (ctlfd + 1, &rset, NULL, NULL, pto); + rc = select (maxfd + 1, &rset, NULL, NULL, pto); if (rc == 0) continue; else if (rc < 0) { if (errno == EINTR) continue; logmsg (LOG_ERR, "select: %s", strerror (errno)); break; } + if (wfd != -1 && FD_ISSET (wfd, &rset)) + { + 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 @@ -237,8 +261,9 @@ wydawca_listener () setlinebuf (out); handle_connection (in, out); fclose (in); fclose (out); } } +} |