aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-12-22 21:39:23 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-12-22 21:54:43 +0200
commit67a64a6a7809c183516740696e15ab88f82d7ef0 (patch)
treeb58f30a8cee98bac7c9f4bc8236c86eefdadb4ef /src
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')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/diskio.c6
-rw-r--r--src/job.c18
-rw-r--r--src/net.c87
-rw-r--r--src/process.c162
-rw-r--r--src/triplet.c104
-rw-r--r--src/verify.c175
-rw-r--r--src/vtab.c18
-rw-r--r--src/watcher.c243
-rw-r--r--src/wydawca.c14
-rw-r--r--src/wydawca.h49
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
@@ -12,12 +12,17 @@
12# GNU General Public License for more details. 12# GNU General Public License for more details.
13# 13#
14# You should have received a copy of the GNU General Public License 14# You should have received a copy of the GNU General Public License
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\
21 builtin.h\ 26 builtin.h\
22 cmdline.h\ 27 cmdline.h\
23 config.c\ 28 config.c\
@@ -45,13 +50,14 @@ wydawca_SOURCES=\
45 mail.h\ 50 mail.h\
46 mail.c\ 51 mail.c\
47 vtab.c\ 52 vtab.c\
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
55 61
56SUFFIXES=.opt .c .h 62SUFFIXES=.opt .c .h
57 63
diff --git a/src/diskio.c b/src/diskio.c
index bab5cb8..751d684 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -408,12 +408,18 @@ replace_allowed_p (struct file_triplet *trp)
408 408
409 if (directive_get_value (trp, "replace", &val)) 409 if (directive_get_value (trp, "replace", &val))
410 return 1; 410 return 1;
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.
417 423
418 Do nothing if dry_run_mode is set. */ 424 Do nothing if dry_run_mode is set. */
419int 425int
diff --git a/src/job.c b/src/job.c
index 4a97f88..3fae432 100644
--- a/src/job.c
+++ b/src/job.c
@@ -22,24 +22,25 @@
22#define STATE_ACTIVE 0x04 22#define STATE_ACTIVE 0x04
23 23
24struct job 24struct 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;
32 int exit_status; 32 int exit_status;
33}; 33};
34 34
35struct job *queue; 35struct 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
43RETSIGTYPE 44RETSIGTYPE
44queue_signal (int sig) 45queue_signal (int sig)
45{ 46{
@@ -73,19 +74,28 @@ job_active_count ()
73 for (job = queue; job; job = job->next) 74 for (job = queue; job; job = job->next)
74 if (job->state & STATE_ACTIVE) 75 if (job->state & STATE_ACTIVE)
75 count++; 76 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 {
89 spool_create_timers (); 99 spool_create_timers ();
90 rc = scan_spool (job->spool, 1, &job->uid); 100 rc = scan_spool (job->spool, 1, &job->uid);
91 } 101 }
@@ -188,13 +198,13 @@ job_insert (struct job *job, struct job *elt)
188 198
189 if (p) 199 if (p)
190 p->prev = job; 200 p->prev = job;
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
198 if (!spool) 208 if (!spool)
199 spool = &fake_spool; 209 spool = &fake_spool;
200 210
diff --git a/src/net.c b/src/net.c
index 4857fa2..3157fe8 100644
--- a/src/net.c
+++ b/src/net.c
@@ -19,16 +19,13 @@
19static int 19static int
20open_listener () 20open_listener ()
21{ 21{
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)
32 { 29 {
33 logmsg (LOG_CRIT, _("cannot create socket: %s"), 30 logmsg (LOG_CRIT, _("cannot create socket: %s"),
34 strerror(errno)); 31 strerror(errno));
@@ -96,13 +93,13 @@ trim_crlf (char *s)
96 93
97void 94void
98handle_connection (FILE *in, FILE *out) 95handle_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
106 if (grecs_getline (&buf, &buflen, in) <= 0) 103 if (grecs_getline (&buf, &buflen, in) <= 0)
107 return; 104 return;
108 trim_crlf (buf); 105 trim_crlf (buf);
@@ -171,74 +168,102 @@ sig_term (int sig)
171} 168}
172 169
173void 170void
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)