aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c53
1 files changed, 39 insertions, 14 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 ()
22 int fd; 22 int fd;
23 23
24 if (listen_sockaddr.sa == NULL) 24 if (listen_sockaddr.sa == NULL)
25 { 25 return -1;
26 logmsg (LOG_CRIT, _("listener address is not configured"));
27 exit (EX_CONFIG);
28 }
29 26
30 fd = socket (listen_sockaddr.sa->sa_family, SOCK_STREAM, 0); 27 fd = socket (listen_sockaddr.sa->sa_family, SOCK_STREAM, 0);
31 if (fd == -1) 28 if (fd == -1)
@@ -99,7 +96,7 @@ handle_connection (FILE *in, FILE *out)
99{ 96{
100 char *buf = NULL; 97 char *buf = NULL;
101 size_t buflen = 0; 98 size_t buflen = 0;
102 const struct spool *spool; 99 struct spool *spool;
103 char *p; 100 char *p;
104 struct passwd *pw; 101 struct passwd *pw;
105 102
@@ -174,6 +171,21 @@ void
174wydawca_listener () 171wydawca_listener ()
175{ 172{
176 int ctlfd = open_listener (); 173 int ctlfd = open_listener ();
174 int wfd = watcher_init ();
175 int maxfd = 0;
176
177 if (ctlfd != -1)
178 maxfd = ctlfd;
179
180 if (wfd != -1 && wfd > maxfd)
181 maxfd = wfd;
182
183 if (maxfd == 0)
184 {
185 logmsg (LOG_CRIT,
186 _("listener address is not configured and inotify is not available"));
187 exit (EX_CONFIG);
188 }
177 189
178 job_init (); 190 job_init ();
179 signal (SIGHUP, sig_hup); 191 signal (SIGHUP, sig_hup);
@@ -182,21 +194,16 @@ wydawca_listener ()
182 signal (SIGINT, sig_term); 194 signal (SIGINT, sig_term);
183 while (!terminate) 195 while (!terminate)
184 { 196 {
185 int fd;
186 FILE *in, *out;
187 int rc; 197 int rc;
188 fd_set rset; 198 fd_set rset;
189 struct timeval to, *pto; 199 struct timeval to, *pto;
190 union {
191 struct sockaddr sa;
192 struct sockaddr_in s_in;
193 struct sockaddr_un s_un;
194 } addr;
195 socklen_t len;
196 200
197 job_queue_runner (); 201 job_queue_runner ();
198 FD_ZERO (&rset); 202 FD_ZERO (&rset);
203 if (ctlfd != -1)
199 FD_SET (ctlfd, &rset); 204 FD_SET (ctlfd, &rset);
205 if (wfd != -1)
206 FD_SET (wfd, &rset);
200 207
201 if (wakeup_interval) 208 if (wakeup_interval)
202 { 209 {
@@ -207,7 +214,7 @@ wydawca_listener ()
207 else 214 else
208 pto = NULL; 215 pto = NULL;
209 216
210 rc = select (ctlfd + 1, &rset, NULL, NULL, pto); 217 rc = select (maxfd + 1, &rset, NULL, NULL, pto);
211 if (rc == 0) 218 if (rc == 0)
212 continue; 219 continue;
213 else if (rc < 0) 220 else if (rc < 0)
@@ -218,6 +225,23 @@ wydawca_listener ()
218 break; 225 break;
219 } 226 }
220 227
228 if (wfd != -1 && FD_ISSET (wfd, &rset))
229 {
230 watcher_run (wfd);
231 }
232
233 if (ctlfd != -1 && FD_ISSET (ctlfd, &rset))
234 {
235 int fd;
236 FILE *in, *out;
237 union
238 {
239 struct sockaddr sa;
240 struct sockaddr_in s_in;
241 struct sockaddr_un s_un;
242 } addr;
243 socklen_t len;
244
221 len = sizeof (addr); 245 len = sizeof (addr);
222 fd = accept (ctlfd, (struct sockaddr*) &addr, &len); 246 fd = accept (ctlfd, (struct sockaddr*) &addr, &len);
223 if (fd == -1) 247 if (fd == -1)
@@ -240,5 +264,6 @@ wydawca_listener ()
240 fclose (out); 264 fclose (out);
241 } 265 }
242 } 266 }
267}
243 268
244 269

Return to:

Send suggestions and report system problems to the System administrator.