aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-27 13:44:31 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-27 13:44:31 +0300
commit9dff021e31a300dcd5eda941d9e4992a6a8e465a (patch)
tree9ba56aa2ccbd7c24b1d1e8535c8e3eeef25f27cf
parente19cf8e1303700b5b2e4f3e525285f63a3c7b51f (diff)
downloadwydawca-9dff021e31a300dcd5eda941d9e4992a6a8e465a.tar.gz
wydawca-9dff021e31a300dcd5eda941d9e4992a6a8e465a.tar.bz2
Use BSD queue macros to implement queues and linked lists.
-rw-r--r--modules/mailutils/mod_mailutils.c2
-rw-r--r--src/Makefile.am13
-rw-r--r--src/config.c18
-rw-r--r--src/directive.c14
-rw-r--r--src/event.c43
-rw-r--r--src/gpg.c5
-rw-r--r--src/module.c30
-rw-r--r--src/net.c49
-rw-r--r--src/queue.h574
-rw-r--r--src/spool.c (renamed from src/process.c)84
-rw-r--r--src/sql.c10
-rw-r--r--src/triplet.c99
-rw-r--r--src/watcher.c44
-rw-r--r--src/wydawca.h66
-rw-r--r--tests/mailnotify.at12
15 files changed, 777 insertions, 286 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c
index 00ea697..759fa14 100644
--- a/modules/mailutils/mod_mailutils.c
+++ b/modules/mailutils/mod_mailutils.c
@@ -603,7 +603,7 @@ wy_config(grecs_node_t *node)
603} 603}
604 604
605void 605void
606wy_flush() 606wy_flush(void)
607{ 607{
608 if (mailer_opened) { 608 if (mailer_opened) {
609 mu_mailer_close(mailer); 609 mu_mailer_close(mailer);
diff --git a/src/Makefile.am b/src/Makefile.am
index 5af4c2c..5b70f5e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,10 +16,6 @@
16 16
17sbin_PROGRAMS=wydawca 17sbin_PROGRAMS=wydawca
18 18
19if COND_INOTIFY
20 WATCHER_C=watcher.c
21endif
22
23wydawca_SOURCES=\ 19wydawca_SOURCES=\
24 backup.c\ 20 backup.c\
25 builtin.c\ 21 builtin.c\
@@ -30,13 +26,12 @@ wydawca_SOURCES=\
30 directive.c\ 26 directive.c\
31 diskio.c\ 27 diskio.c\
32 exec.c\ 28 exec.c\
33 event.c\
34 gpg.c\ 29 gpg.c\
35 interval.c\ 30 interval.c\
36 module.c\ 31 module.c\
37 net.c\ 32 net.c\
38 pidfile.c\ 33 pidfile.c\
39 process.c\ 34 spool.c\
40 sql.c\ 35 sql.c\
41 sql.h\ 36 sql.h\
42 tcpwrap.c\ 37 tcpwrap.c\
@@ -49,7 +44,11 @@ wydawca_SOURCES=\
49 null.c\ 44 null.c\
50 timer.c\ 45 timer.c\
51 thread_name.c\ 46 thread_name.c\
52 $(WATCHER_C) 47 queue.h
48
49if COND_INOTIFY
50 wydawca_SOURCES += watcher.c
51endif
53 52
54BUILT_SOURCES=cmdline.h 53BUILT_SOURCES=cmdline.h
55EXTRA_DIST=cmdline.opt 54EXTRA_DIST=cmdline.opt
diff --git a/src/config.c b/src/config.c
index a7ceb92..ee9f0c3 100644
--- a/src/config.c
+++ b/src/config.c
@@ -125,7 +125,7 @@ static struct archive_descr default_archive_descr = {
125}; 125};
126 126
127static struct dictionary *default_dictionary[dictionary_count]; 127static struct dictionary *default_dictionary[dictionary_count];
128struct notification *default_notification = NULL; 128NOTIFYQ default_notification = NOTIFYQ_INITIALIZER(default_notification);
129 129
130/* safe_file_name: convert a file name possibly containig relative 130/* safe_file_name: convert a file name possibly containig relative
131 specs (../) into a safer form using only direct descendence. 131 specs (../) into a safer form using only direct descendence.
@@ -879,9 +879,7 @@ cb_notify_event(enum grecs_callback_command cmd, grecs_node_t * node,
879 else { 879 else {
880 /* FIXME: Check if the module is defined. Better yet, 880 /* FIXME: Check if the module is defined. Better yet,
881 delay this check until config_finish */ 881 delay this check until config_finish */
882 struct notification **p = (struct notification **) varptr; 882 NOTIFYQ_APPEND((NOTIFYQ*)varptr, ntf);
883 ntf->next = *p;
884 *p = ntf;
885 /* FIXME: check ev and tgt? */ 883 /* FIXME: check ev and tgt? */
886 } 884 }
887 break; 885 break;
@@ -1135,7 +1133,7 @@ static struct grecs_keyword spool_kw[] = {
1135 { "notify-event", NULL, 1133 { "notify-event", NULL,
1136 N_("Configure notification"), 1134 N_("Configure notification"),
1137 grecs_type_section, GRECS_MULT, 1135 grecs_type_section, GRECS_MULT,
1138 NULL, offsetof(struct spool, notification), 1136 NULL, offsetof(struct spool, notification_queue),
1139 cb_notify_event, NULL, notify_event_kw }, 1137 cb_notify_event, NULL, notify_event_kw },
1140 { "check-script", NULL, 1138 { "check-script", NULL,
1141 N_("A /bin/sh script to verify the tarball"), 1139 N_("A /bin/sh script to verify the tarball"),
@@ -1207,14 +1205,16 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t * node,
1207 return 1; 1205 return 1;
1208 } 1206 }
1209 1207
1210 if (rc) 1208 if (rc) {
1209 //FIXME: free spool */
1211 return rc; 1210 return rc;
1211 }
1212 1212
1213 if (!spool->notification) 1213 //FIXME
1214 spool->notification = default_notification; 1214 if (NOTIFYQ_EMPTY(&spool->notification_queue))
1215 spool->notification_queue = default_notification;
1215 spool->dest_dir = wy_url_printable(spool->dest_url); 1216 spool->dest_dir = wy_url_printable(spool->dest_url);
1216 register_spool(spool); 1217 register_spool(spool);
1217 free(spool);
1218 *pdata = NULL; 1218 *pdata = NULL;
1219 break; 1219 break;
1220 1220
diff --git a/src/directive.c b/src/directive.c
index 8e7afeb..bb5ce4b 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -58,10 +58,12 @@ str_dirname_sig(char const *a, char const *b)
58 while (*a && *b) { 58 while (*a && *b) {
59 if (*a != *b) { 59 if (*a != *b) {
60 if (arg2) { 60 if (arg2) {
61 if (ISSPACE(*a) && strncmp(b, ".sig", 4) == 0) { 61 if (ISSPACE(*a)
62 && strncmp(b, SUF_SIG, SUF_SIG_LEN) == 0) {
62 arg2 = 1; 63 arg2 = 1;
63 b += 4; 64 b += 4;
64 } else if (ISSPACE(*b) && strncmp(a, ".sig", 4) == 0) { 65 } else if (ISSPACE(*b)
66 && strncmp(a, SUF_SIG, SUF_SIG_LEN) == 0) {
65 arg2 = -1; 67 arg2 = -1;
66 a += 4; 68 a += 4;
67 } else 69 } else
@@ -77,10 +79,10 @@ str_dirname_sig(char const *a, char const *b)
77 b++; 79 b++;
78 } 80 }
79 81
80 if (*a == 0 && strcmp(b, ".sig") == 0) 82 if (*a == 0 && strcmp(b, SUF_SIG) == 0)
81 return (arg2 == 0 || arg2 == 1) ? 1 : 0; 83 return (arg2 == 0 || arg2 == 1) ? 1 : 0;
82 84
83 if (*b == 0 && strcmp(a, ".sig") == 0) 85 if (*b == 0 && strcmp(a, SUF_SIG) == 0)
84 return (arg2 == 0 || arg2 == -1) ? -1 : 0; 86 return (arg2 == 0 || arg2 == -1) ? -1 : 0;
85 87
86 return 0; 88 return 0;
@@ -649,7 +651,7 @@ external_check(struct wy_triplet *trp)
649 651
650 if (rc) { 652 if (rc) {
651 wydawca_stat_incr(WY_STAT_CHECK_FAIL); 653 wydawca_stat_incr(WY_STAT_CHECK_FAIL);
652 notify(spool->notification, trp, wy_ev_check_fail); 654 notify(&spool->notification_queue, trp, wy_ev_check_fail);
653 } 655 }
654 656
655 return rc; 657 return rc;
@@ -759,6 +761,6 @@ process_directives(struct wy_triplet *trp)
759 wydawca_stat_incr(WY_STAT_TRIPLET_SUCCESS); 761 wydawca_stat_incr(WY_STAT_TRIPLET_SUCCESS);
760 triplet_report_finish(trp); 762 triplet_report_finish(trp);
761 timer_stop(WY_TIMER_TRIPLET); 763 timer_stop(WY_TIMER_TRIPLET);
762 notify(spool->notification, trp, wy_ev_success); 764 notify(&spool->notification_queue, trp, wy_ev_success);
763 return 0; 765 return 0;
764} 766}
diff --git a/src/event.c b/src/event.c
deleted file mode 100644
index da26a30..0000000
--- a/src/event.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/* wydawca - automatic release submission daemon
2 Copyright (C) 2007-2020 Sergey Poznyakoff
3
4 Wydawca is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 Wydawca is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with wydawca. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "wydawca.h"
18
19void
20notify(struct notification *n, struct wy_triplet *t, enum wy_event e)
21{
22 for (; n; n = n->next)
23 if (n->ev == e) {
24 if (n->modname)
25 module_notify(n->modname, n->modcfg, e, t);
26 }
27}
28
29void
30notify_finish(void)
31{
32 notify(default_notification, NULL, wy_ev_finish);
33}
34
35void
36notify_flush(struct spool *sp)
37{
38 struct notification *n;