summaryrefslogtreecommitdiffabout
path: root/src/net.c
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-22 19:39:23 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-12-22 19:54:43 (GMT)
commit67a64a6a7809c183516740696e15ab88f82d7ef0 (patch) (unidiff)
treeb58f30a8cee98bac7c9f4bc8236c86eefdadb4ef /src/net.c
parent2c28190e77ce38b6437a2be8337680f77f58d37a (diff)
downloadwydawca-67a64a6a7809c183516740696e15ab88f82d7ef0.tar.gz
wydawca-67a64a6a7809c183516740696e15ab88f82d7ef0.tar.bz2
Implement inotify support.
* configure.ac: New option --with-inotify. Bye default, use inotify if it is present. * src/watcher.c: New file. Implements inotify watcher. * src/Makefile.am [COND_INOTIFY] (wydawca_SOURCES): Add watcher.c * src/diskio.c (dir_get_path): New function. * src/job.c (job) <spool>: Remove const qualifier. All uses changed. (inotify_spool): New pseudo-spool. (fake_spool): Remove static qualifier. (wydawca_scanner): Support for inotify spools. * src/net.c (open_listener): Don't exit if the listener address is not set. (wydawca_listener): Listen on the listener socket and on the inotify descriptor. If none is set, bail out. * src/process.c (for_each_spool) (file_info_cleanup) (spool_cwd_add_new_file,spool_add_new_file): New functions. (scan_spool_unlocked): Use spool_cwd_add_new_file. Don't initialize dictionaries here: it will be done in spool_commit_triplets. (spool_open_dictionaries): New function. (close_dictionaries): Rename to spool_close_dictionaries. Clear dict_inited. * src/triplet.c (hash_triplet_compare): Compare spools as well. (register_file): Likewise. (triplet_lookup): New function. (check_triplet_state): New argument: noauth. All uses updated. (enumerate_triplets): Rename to spool_commit_triplets. Call spool_open_dictionaries. (count_processable_triplets,triplet_remove_file): New functions. * src/verify.c (verify_directive_file): New argument: noauth. All uses updated. * src/vtab.c (reg): Initialize get_path member. (get_path): New function. * src/wydawca.c (main): Set print_version_hook. * src/wydawca.h (virt_tab) <get_path>: New method. (spool) <dict_inited>: New member. (fake_spool, inotify_spool): New externs. (spool_add_new_file, spool_cwd_add_new_file) (spool_open_dictionaries, spool_close_dictionaries) (for_each_spool, count_processable_triplets) (triplet_remove_file, get_path): New protos. (enumerate_triplets): Rename to spool_commit_triplets. (verify_directive_file): Take two arguments.
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 ()
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,7 +171,22 @@ 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;
177 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 }
189
178 job_init (); 190 job_init ();
179 signal (SIGHUP, sig_hup); 191 signal (SIGHUP, sig_hup);
180 signal (SIGTERM, sig_term); 192 signal (SIGTERM, sig_term);
@@ -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);
199 FD_SET (ctlfd, &rset); 203 if (ctlfd != -1)
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,26 +225,44 @@ wydawca_listener ()
218 break; 225 break;
219 } 226 }
220 227
221 len = sizeof (addr); 228 if (wfd != -1 && FD_ISSET (wfd, &rset))
222 fd = accept (ctlfd, (struct sockaddr*) &addr, &len);
223 if (fd == -1)
224 continue;
225 /* FIXME: Use Mailutils ACLs? */
226#ifdef WITH_LIBWRAP
227 if (!tcpwrap_access(fd))
228 { 229 {
229 close(fd); 230 watcher_run (wfd);
230 continue;
231 } 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
245 len = sizeof (addr);
246 fd = accept (ctlfd, (struct sockaddr*) &addr, &len);
247 if (fd == -1)
248 continue;
249 /* FIXME: Use Mailutils ACLs? */
250#ifdef WITH_LIBWRAP
251 if (!tcpwrap_access(fd))
252 {
253 close(fd);
254 continue;
255 }
232#endif 256#endif
233 257
234 in = fdopen (fd, "r"); 258 in = fdopen (fd, "r");
235 setlinebuf (in); 259 setlinebuf (in);
236 out = fdopen (fd, "w"); 260 out = fdopen (fd, "w");
237 setlinebuf (out); 261 setlinebuf (out);
238 handle_connection (in, out); 262 handle_connection (in, out);
239 fclose (in); 263 fclose (in);
240 fclose (out); 264 fclose (out);
265 }
241 } 266 }
242} 267}
243 268

Return to:

Send suggestions and report system problems to the System administrator.