diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/diskio.c | 6 | ||||
-rw-r--r-- | src/job.c | 18 | ||||
-rw-r--r-- | src/net.c | 87 | ||||
-rw-r--r-- | src/process.c | 162 | ||||
-rw-r--r-- | src/triplet.c | 104 | ||||
-rw-r--r-- | src/verify.c | 175 | ||||
-rw-r--r-- | src/vtab.c | 18 | ||||
-rw-r--r-- | src/watcher.c | 243 | ||||
-rw-r--r-- | src/wydawca.c | 14 | ||||
-rw-r--r-- | src/wydawca.h | 49 |
11 files changed, 683 insertions, 201 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 73182c4..828d573 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -15,6 +15,11 @@ | |||
15 | # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. | 15 | # along with Wydawca. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | sbin_PROGRAMS=wydawca | 17 | sbin_PROGRAMS=wydawca |
18 | |||
19 | if COND_INOTIFY | ||
20 | WATCHER_C=watcher.c | ||
21 | endif | ||
22 | |||
18 | wydawca_SOURCES=\ | 23 | wydawca_SOURCES=\ |
19 | backup.c\ | 24 | backup.c\ |
20 | builtin.c\ | 25 | builtin.c\ |
@@ -48,7 +53,8 @@ wydawca_SOURCES=\ | |||
48 | null.c\ | 53 | null.c\ |
49 | timer.c\ | 54 | timer.c\ |
50 | txtacc.c\ | 55 | txtacc.c\ |
51 | report.c | 56 | report.c\ |
57 | $(WATCHER_C) | ||
52 | 58 | ||
53 | BUILT_SOURCES=cmdline.h | 59 | BUILT_SOURCES=cmdline.h |
54 | EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk | 60 | EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk |
diff --git a/src/diskio.c b/src/diskio.c index bab5cb8..751d684 100644 --- a/src/diskio.c +++ b/src/diskio.c | |||
@@ -411,6 +411,12 @@ replace_allowed_p (struct file_triplet *trp) | |||
411 | return strcmp (val, "true") == 0; | 411 | return strcmp (val, "true") == 0; |
412 | } | 412 | } |
413 | 413 | ||
414 | const char * | ||
415 | dir_get_path (struct spool *sp) | ||
416 | { | ||
417 | return sp->source_dir; | ||
418 | } | ||
419 | |||
414 | /* Move the part FILE_ID of the triplet TRP between the directories in | 420 | /* Move the part FILE_ID of the triplet TRP between the directories in |
415 | TRP->SPOOL. TRP->RELATIVE_DIR gives relative directory (i.e. the | 421 | TRP->SPOOL. TRP->RELATIVE_DIR gives relative directory (i.e. the |
416 | directory part of the file name) for backup purposes. | 422 | directory part of the file name) for backup purposes. |
@@ -25,7 +25,7 @@ struct job | |||
25 | { | 25 | { |
26 | struct job *next, *prev; | 26 | struct job *next, *prev; |
27 | int state; | 27 | int state; |
28 | const struct spool *spool; | 28 | struct spool *spool; |
29 | uid_t uid; | 29 | uid_t uid; |
30 | pid_t pid; | 30 | pid_t pid; |
31 | time_t timestamp; | 31 | time_t timestamp; |
@@ -36,7 +36,8 @@ struct job *queue; | |||
36 | size_t jobmax; | 36 | size_t jobmax; |
37 | size_t jobcnt; | 37 | size_t jobcnt; |
38 | 38 | ||
39 | static struct spool fake_spool = { "all spools" }; | 39 | struct spool fake_spool = { "all spools" }, |
40 | inotify_spool = { "inotify" } ; | ||
40 | 41 | ||
41 | static int wakeup; | 42 | static int wakeup; |
42 | 43 | ||
@@ -76,13 +77,22 @@ job_active_count () | |||
76 | return count; | 77 | return count; |
77 | } | 78 | } |
78 | 79 | ||
80 | static int | ||
81 | procspool (struct spool *spool, void *data) | ||
82 | { | ||
83 | spool_commit_triplets (spool); | ||
84 | return 0; | ||
85 | } | ||
86 | |||
79 | int | 87 | int |
80 | wydawca_scanner (struct job *job) | 88 | wydawca_scanner (struct job *job) |
81 | { | 89 | { |
82 | int rc; | 90 | int rc; |
83 | initstats(); | 91 | initstats(); |
84 | timer_start ("wydawca"); | 92 | timer_start ("wydawca"); |
85 | if (job->spool == &fake_spool) | 93 | if (job->spool == &inotify_spool) |
94 | rc = for_each_spool (procspool, NULL); | ||
95 | else if (job->spool == &fake_spool) | ||
86 | rc = scan_all_spools (1, &job->uid); | 96 | rc = scan_all_spools (1, &job->uid); |
87 | else | 97 | else |
88 | { | 98 | { |
@@ -191,7 +201,7 @@ job_insert (struct job *job, struct job *elt) | |||
191 | } | 201 | } |
192 | 202 | ||
193 | void | 203 | void |
194 | schedule_job (const struct spool *spool, uid_t uid) | 204 | schedule_job (struct spool *spool, uid_t uid) |
195 | { | 205 | { |
196 | struct job *job; | 206 | struct job *job; |
197 | 207 | ||
@@ -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 | |||
174 | wydawca_listener () | 171 | wydawca_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 |