summaryrefslogtreecommitdiffabout
path: root/src/net.c
Side-by-side diff
Diffstat (limited to 'src/net.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/net.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/src/net.c b/src/net.c
index 4857fa2..3157fe8 100644
--- a/src/net.c
+++ b/src/net.c
@@ -22,10 +22,7 @@ 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)
@@ -99,7 +96,7 @@ 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;
@@ -174,7 +171,22 @@ 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);
@@ -182,21 +194,16 @@ wydawca_listener ()
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);
- FD_SET (ctlfd, &rset);
+ if (ctlfd != -1)
+ FD_SET (ctlfd, &rset);
+ if (wfd != -1)
+ FD_SET (wfd, &rset);
if (wakeup_interval)
{
@@ -207,7 +214,7 @@ wydawca_listener ()
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)
@@ -218,26 +225,44 @@ wydawca_listener ()
break;
}
- 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);
+ }
}
}

Return to:

Send suggestions and report system problems to the System administrator.