aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/diskio.c6
-rw-r--r--src/job.c18
-rw-r--r--src/net.c53
-rw-r--r--src/process.c160
-rw-r--r--src/triplet.c104
-rw-r--r--src/verify.c5
-rw-r--r--src/vtab.c18
-rw-r--r--src/watcher.c243
-rw-r--r--src/wydawca.c14
-rw-r--r--src/wydawca.h47
11 files changed, 579 insertions, 97 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
17sbin_PROGRAMS=wydawca 17sbin_PROGRAMS=wydawca
18
19if COND_INOTIFY
20 WATCHER_C=watcher.c
21endif
22
18wydawca_SOURCES=\ 23wydawca_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
53BUILT_SOURCES=cmdline.h 59BUILT_SOURCES=cmdline.h
54EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk 60EXTRA_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
414const char *
415dir_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.
diff --git a/src/job.c b/src/job.c
index 4a97f88..3fae432 100644
--- a/src/job.c
+++ b/src/job.c
@@ -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;
36size_t jobmax; 36size_t jobmax;
37size_t jobcnt; 37size_t jobcnt;
38 38
39static struct spool fake_spool = { "all spools" }; 39struct spool fake_spool = { "all spools" },
40 inotify_spool = { "inotify" } ;
40 41
41static int wakeup; 42static int wakeup;
42 43
@@ -76,13 +77,22 @@ job_active_count ()
76 return count; 77 return count;
77} 78}
78 79
80static int
81procspool (struct spool *spool, void *data)
82{
83 spool_commit_triplets (spool);
84 return 0;
85}
86
79int 87int
80wydawca_scanner (struct job *job) 88wydawca_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
193void 203void
194schedule_job (const struct spool *spool, uid_t uid) 204schedule_job (struct spool *spool, uid_t uid)
195{ 205{
196 struct job *job; 206 struct job *job;
197 207
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
diff --git a/src/process.c b/src/process.c
index c5eb321..ec64589 100644
--- a/src/process.c
+++ b/src/process.c
@@ -24,6 +24,20 @@ struct spool_list
24 24
25static struct spool_list *spool_list; 25static struct spool_list *spool_list;
26 26