summaryrefslogtreecommitdiffabout
path: root/src
Unidiff
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/Makefile.am5
-rw-r--r--src/backup.c165
-rw-r--r--src/builtin.c10
-rw-r--r--src/config.c26
-rw-r--r--src/dictionary.c11
-rw-r--r--src/directive.c8
-rw-r--r--src/diskio.c6
-rw-r--r--src/exec.c2
-rw-r--r--src/gpg.c7
-rw-r--r--src/job.c2
-rw-r--r--src/lock.c12
-rw-r--r--src/mail.c14
-rw-r--r--src/net.c4
-rw-r--r--src/process.c4
-rw-r--r--src/sql.c4
-rw-r--r--src/timer.c5
-rw-r--r--src/triplet.c17
-rw-r--r--src/txtacc.c16
-rw-r--r--src/verify.c4
-rw-r--r--src/wydawca.c8
-rw-r--r--src/wydawca.h20
21 files changed, 268 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8139849..3b524ba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,12 +13,13 @@
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
18wydawca_SOURCES=\ 18wydawca_SOURCES=\
19 backup.c\
19 builtin.c\ 20 builtin.c\
20 builtin.h\ 21 builtin.h\
21 cmdline.h\ 22 cmdline.h\
22 config.c\ 23 config.c\
23 dictionary.c\ 24 dictionary.c\
24 directive.c\ 25 directive.c\
@@ -57,14 +58,14 @@ SUFFIXES=.opt .c .h
57.opt.h: 58.opt.h:
58 $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@ 59 $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@
59 60
60incdir=$(pkgdatadir)/$(VERSION)/include 61incdir=$(pkgdatadir)/$(VERSION)/include
61inc_DATA = $(PP_SETUP_FILE) 62inc_DATA = $(PP_SETUP_FILE)
62 63
63LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ 64LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
64INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@ 65INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@
65AM_CPPFLAGS= \ 66AM_CPPFLAGS= \
66 -DSYSCONFDIR=\"$(sysconfdir)\"\ 67 -DSYSCONFDIR=\"$(sysconfdir)\"\
67 -DLOCALSTATEDIR=\"$(localstatedir)\"\ 68 -DLOCALSTATEDIR=\"$(localstatedir)\"\
68 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ 69 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
69 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ 70 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
70 -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)" 71 -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)"
diff --git a/src/backup.c b/src/backup.c
new file mode 100644
index 0000000..312375d
--- a/dev/null
+++ b/src/backup.c
@@ -0,0 +1,165 @@
1/* wydawca - automatic release submission daemon
2 Copyright (C) 2011 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
19char const *simple_backup_suffix = "~";
20
21static const char *
22split_filename (char const *file, char **pdir)
23{
24 const char *p = strrchr (file, '/');
25
26 if (!p)
27 {
28 *pdir = grecs_strdup (".");
29 p = file;
30 }
31 else
32 {
33 size_t len = p - file;
34 char *dir = grecs_malloc (len + 1);
35 memcpy (dir, file, len);
36 dir[len] = 0;
37 *pdir = dir;
38 p++;
39 }
40 return p;
41}
42
43#define MINSUFSIZE 8
44#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
45
46static char *
47get_backup_suffix (char const *file, enum backup_type type)
48{
49 char *dirname;
50 const char *basename;
51 size_t baselen;
52 DIR *dir;
53 struct dirent *ent;
54 char *lastsuf = NULL;
55 size_t lastsuflen = 0;
56 size_t lastsufsize = 0;
57 int carry;
58 char *newsuf;
59 char *q;
60
61 if (type == simple_backups)
62 return grecs_strdup (simple_backup_suffix);
63
64 basename = split_filename (file, &dirname);
65 baselen = strlen (basename);
66 dir = opendir (dirname);
67 if (!dir)
68 {
69 int ec = errno;
70 free (dirname);
71 errno = ec;
72 return NULL;
73 }
74
75 while ((ent = readdir (dir)))
76 {
77 size_t len = strlen (ent->d_name);
78 const char *p;
79 size_t suflen;
80
81 if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen))
82 continue;
83 p = ent->d_name + baselen;
84 suflen = len - baselen;
85 if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' &&
86 (suflen > lastsuflen
87 || (suflen == lastsuflen &&
88 memcmp (p, lastsuf, lastsuflen) > 0)))
89 {
90 carry = 1;
91 for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--)
92 if (*q != '9')
93 carry = 0;
94 q++;
95 if (!ISDIGIT (*q))
96 continue;
97
98 if (suflen > lastsufsize)
99 {
100 lastsufsize = suflen;
101 if (!lastsuf)
102 {
103 if (lastsufsize < MINSUFSIZE)
104 lastsufsize = MINSUFSIZE;
105 lastsuf = grecs_malloc (lastsufsize);
106 }
107 else
108 lastsuf = grecs_realloc (lastsuf, lastsufsize);
109 }
110 memcpy (lastsuf, p, suflen);
111 lastsuflen = suflen;
112 }
113 }
114 closedir (dir);
115 free (dirname);
116
117 if (lastsuf)
118 {
119 size_t newsuflen;
120
121 newsuflen = lastsuflen + carry;
122 newsuf = grecs_malloc (newsuflen + 1);
123 newsuf[0] = '.';
124 newsuf[1] = '~';
125 newsuf[2] = '0';
126 memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3);
127 newsuf[newsuflen-1] = '~';
128 newsuf[newsuflen] = 0;
129
130 for (q = newsuf + newsuflen - 2; *q == '9'; q--)
131 *q = '0';
132 ++*q;
133 free (lastsuf);
134 }
135 else if (type == numbered_existing_backups)
136 newsuf = grecs_strdup (simple_backup_suffix);
137 else
138 newsuf = grecs_strdup (".~1~");
139 return newsuf;
140}
141
142char *
143find_backup_file_name (char const *file, enum backup_type type)
144{
145 size_t flen;
146 char *suffix;
147 char *newname;
148
149 if (type == no_backups)
150 {
151 errno = 0;
152 return NULL;
153 }
154
155 suffix = get_backup_suffix (file, type);
156 if (!suffix)
157 return NULL;
158 flen = strlen (file);
159 newname = grecs_malloc (flen + strlen (suffix) + 1);
160 memcpy (newname, file, flen);
161 strcpy (newname + flen, suffix);
162 free (suffix);
163 /* FIXME: Check newname length */
164 return newname;
165}
diff --git a/src/builtin.c b/src/builtin.c
index 9d1063c..8a07eab 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -13,14 +13,16 @@
13 13
14 You should have received a copy of the GNU General Public License along 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/>. */ 15 with wydawca. If not, see <http://www.gnu.org/licenses/>. */
16 16
17#include "wydawca.h" 17#include "wydawca.h"
18#include "builtin.h" 18#include "builtin.h"
19#include "fnmatch.h" 19
20#include "regex.h" 20#ifndef FNM_CASEFOLD
21# define FNM_CASEFOLD 0
22#endif
21 23
22int 24int
23builtin_init (struct dictionary *dict) 25builtin_init (struct dictionary *dict)
24{ 26{
25 return 0; 27 return 0;
26} 28}
@@ -217,15 +219,15 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
217 } 219 }
218 else 220 else
219 { 221 {
220 size_t i; 222 size_t i;
221 char *p; 223 char *p;
222 224
223 bds = xmalloc (sizeof (*bds)); 225 bds = grecs_malloc (sizeof (*bds));
224 count *= ncol; 226 count *= ncol;
225 bds->wp = xcalloc (count, sizeof (bds->wp[0])); 227 bds->wp = grecs_calloc (count, sizeof (bds->wp[0]));
226 bds->acc = acc; 228 bds->acc = acc;
227 p = txtacc_finish (acc, 0); 229 p = txtacc_finish (acc, 0);
228 230
229 for (i = 0; i < count; i++) 231 for (i = 0; i < count; i++)
230 { 232 {
231 bds->wp[i] = p; 233 bds->wp[i] = p;
diff --git a/src/config.c b/src/config.c
index df9816e..8250749 100644
--- a/src/config.c
+++ b/src/config.c
@@ -143,13 +143,13 @@ safe_file_name (char *file_name)
143} 143}
144 144
145/* Same as safe_file_name, but returns an allocated copy. */ 145/* Same as safe_file_name, but returns an allocated copy. */
146char * 146char *
147safe_file_name_alloc (const char *file_name) 147safe_file_name_alloc (const char *file_name)
148{ 148{
149 char *s = xstrdup (file_name); 149 char *s = grecs_strdup (file_name);
150 char *ns = safe_file_name (s); 150 char *ns = safe_file_name (s);
151 if (!ns) 151 if (!ns)
152 free (s); 152 free (s);
153 return ns; 153 return ns;
154} 154}
155 155
@@ -546,14 +546,14 @@ cb_sql_host (enum grecs_callback_command cmd,
546 if (p) 546 if (p)
547 { 547 {
548 /* FIXME: Modifies constant string */ 548 /* FIXME: Modifies constant string */
549 *p++ = 0; 549 *p++ = 0;
550 if (p[0] == '/') 550 if (p[0] == '/')
551 { 551 {
552 pconn->socket = xstrdup (p); 552 pconn->socket = grecs_strdup (p);
553 pconn->host = xstrdup ("localhost"); 553 pconn->host = grecs_strdup ("localhost");
554 } 554 }
555 else 555 else
556 { 556 {
557 char *end; 557 char *end;
558 unsigned long n = strtoul (p, &end, 10); 558 unsigned long n = strtoul (p, &end, 10);
559 if (*end) 559 if (*end)
@@ -566,17 +566,17 @@ cb_sql_host (enum grecs_callback_command cmd,
566 grecs_error (locus, 0, _("port number out of range 1..%d"), 566 grecs_error (locus, 0, _("port number out of range 1..%d"),
567 USHRT_MAX); 567 USHRT_MAX);
568 return 0; 568 return 0;
569 } 569 }
570 pconn->port = n; 570 pconn->port = n;
571 /* Save host name */ 571 /* Save host name */
572 pconn->host = xstrdup (value->v.string); 572 pconn->host = grecs_strdup (value->v.string);
573 } 573 }
574 } 574 }
575 else 575 else
576 pconn->host = xstrdup (value->v.string); 576 pconn->host = grecs_strdup (value->v.string);
577 return 0; 577 return 0;
578} 578}
579 579
580static int 580static int
581cb_sql (enum grecs_callback_command cmd, 581cb_sql (enum grecs_callback_command cmd,
582 grecs_locus_t *locus, 582 grecs_locus_t *locus,
@@ -591,13 +591,13 @@ cb_sql (enum grecs_callback_command cmd,
591 case grecs_callback_section_begin: 591 case grecs_callback_section_begin:
592 if (!value || value->type != GRECS_TYPE_STRING) 592 if (!value || value->type != GRECS_TYPE_STRING)
593 { 593 {
594 grecs_error(locus, 0, _("tag must be a string")); 594 grecs_error(locus, 0, _("tag must be a string"));
595 return 0; 595 return 0;
596 } 596 }
597 pconn = xzalloc (sizeof (*pconn)); 597 pconn = grecs_zalloc (sizeof (*pconn));
598 pconn->ident = strdup (value->v.string); 598 pconn->ident = strdup (value->v.string);
599 *pdata = pconn; 599 *pdata = pconn;
600 break; 600 break;
601 601
602 case grecs_callback_section_end: 602 case grecs_callback_section_end:
603 pconn = *pdata; 603 pconn = *pdata;
@@ -893,13 +893,13 @@ cb_notify_event (enum grecs_callback_command cmd,
893{ 893{
894 struct notification *ntf; 894 struct notification *ntf;
895 void **pdata = cb_data; 895 void **pdata = cb_data;
896 896
897 switch (cmd) { 897 switch (cmd) {
898 case grecs_callback_section_begin: 898 case grecs_callback_section_begin:
899 ntf = xzalloc (sizeof (*ntf)); 899 ntf = grecs_zalloc (sizeof (*ntf));
900 *pdata = ntf; 900 *pdata = ntf;
901 break; 901 break;
902 902
903 case grecs_callback_section_end: 903 case grecs_callback_section_end:
904 ntf = *pdata; 904 ntf = *pdata;
905 if (!ntf->msg) 905 if (!ntf->msg)
@@ -981,22 +981,22 @@ cb_dictionary_params (enum grecs_callback_command cmd,
981 else 981 else
982 { 982 {
983 int i; 983 int i;
984 struct grecs_list_entry *ep; 984 struct grecs_list_entry *ep;
985 985
986 meth->parmc = size; 986 meth->parmc = size;
987 meth->parmv = xcalloc (size + 1, sizeof (meth->parmv[0])); 987 meth->parmv = grecs_calloc (size + 1, sizeof (meth->parmv[0]));
988 988
989 for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++) 989 for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
990 { 990 {
991 const grecs_value_t *vp = ep->data; 991 const grecs_value_t *vp = ep->data;
992 992
993 if (assert_string_arg (locus, cmd, vp)) 993 if (assert_string_arg (locus, cmd, vp))
994 break; 994 break;
995 995
996 meth->parmv[i] = xstrdup (vp->v.string); 996 meth->parmv[i] = grecs_strdup (vp->v.string);
997 } 997 }
998 meth->parmv[i] = NULL; 998 meth->parmv[i] = NULL;
999 } 999 }
1000 return 0; 1000 return 0;
1001} 1001}
1002 1002
@@ -1156,14 +1156,14 @@ cb_spool (enum grecs_callback_command cmd,
1156 case grecs_callback_section_begin: 1156 case grecs_callback_section_begin:
1157 if (!value || value->type != GRECS_TYPE_STRING) 1157 if (!value || value->type != GRECS_TYPE_STRING)
1158 { 1158 {
1159 grecs_error (locus, 0, _("tag must be a string")); 1159 grecs_error (locus, 0, _("tag must be a string"));
1160 return 1; 1160 return 1;
1161 } 1161 }
1162 spool = xzalloc (sizeof (*spool)); 1162 spool = grecs_zalloc (sizeof (*spool));
1163 spool->tag = xstrdup (value->v.string); 1163 spool->tag = grecs_strdup (value->v.string);
1164 spool->file_sweep_time = file_sweep_time; 1164 spool->file_sweep_time = file_sweep_time;
1165 for (i = 0; i < NITEMS (spool->dictionary); i++) 1165 for (i = 0; i < NITEMS (spool->dictionary); i++)
1166 spool->dictionary[i] = default_dictionary[i]; 1166 spool->dictionary[i] = default_dictionary[i];
1167 spool->archive = default_archive_descr; 1167 spool->archive = default_archive_descr;
1168 *pdata = spool; 1168 *pdata = spool;
1169 break; 1169 break;
@@ -1274,14 +1274,14 @@ cb_supp_groups (enum grecs_callback_command cmd,
1274 wydawca_supp_groups = NULL; 1274 wydawca_supp_groups = NULL;
1275 else 1275 else
1276 { 1276 {
1277 int i; 1277 int i;
1278 struct grecs_list_entry *ep; 1278 struct grecs_list_entry *ep;
1279 1279
1280 wydawca_supp_groups = xcalloc (wydawca_supp_groupc, 1280 wydawca_supp_groups = grecs_calloc (wydawca_supp_groupc,
1281 sizeof (wydawca_supp_groups[0])); 1281 sizeof (wydawca_supp_groups[0]));
1282 1282
1283 for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++) 1283 for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
1284 { 1284 {
1285 const grecs_value_t *vp = ep->data; 1285 const grecs_value_t *vp = ep->data;
1286 struct group *grp; 1286 struct group *grp;
1287 1287
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -45,14 +45,13 @@ static struct dictionary_descr dictionary_tab[] = {
45 { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL } 45 { "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL }
46}; 46};
47 47
48struct dictionary * 48struct dictionary *
49dictionary_new (enum dictionary_id id, enum dictionary_type type) 49dictionary_new (enum dictionary_id id, enum dictionary_type type)
50{ 50{
51 struct dictionary *mp = xmalloc (sizeof mp[0]); 51 struct dictionary *mp = grecs_zalloc (sizeof mp[0]);
52 memset (mp, 0, sizeof mp[0]);
53 mp->id = id; 52 mp->id = id;
54 mp->type = type; 53 mp->type = type;
55 return mp; 54 return mp;
56} 55}
57 56
58int 57int
@@ -89,12 +88,14 @@ dictionary_open (struct dictionary *dict)
89} 88}
90 89
91int 90int
92dictionary_close (struct dictionary *dict, void *handle) 91dictionary_close (struct dictionary *dict, void *handle)
93{ 92{
94 struct dictionary_descr *mp = dictionary_tab + dict->type; 93 struct dictionary_descr *mp = dictionary_tab + dict->type;
94 if (mp->free)
95 mp->free (dict, handle);
95 if (!mp->close) 96 if (!mp->close)
96 return 0; 97 return 0;
97 return mp->close (dict, handle); 98 return mp->close (dict, handle);
98} 99}
99 100
100int 101int
@@ -183,13 +184,13 @@ dictionary_result (struct dictionary *dict, void *handle,
183void 184void
184dictionary_copy_result (struct dictionary *dict, const char *res, size_t size) 185dictionary_copy_result (struct dictionary *dict, const char *res, size_t size)
185{ 186{
186 if (dict->result_size < size + 1) 187 if (dict->result_size < size + 1)
187 { 188 {
188 dict->result_size = size + 1; 189 dict->result_size = size + 1;
189 dict->result = x2realloc (dict->result, &dict->result_size); 190 dict->result = grecs_realloc (dict->result, dict->result_size);
190 } 191 }
191 memcpy (dict->result, res, size); 192 memcpy (dict->result, res, size);
192 dict->result[size] = 0; 193 dict->result[size] = 0;
193} 194}
194 195
195/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed 196/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed
@@ -203,23 +204,23 @@ dictionary_quote_string (struct dictionary *dict, void *handle,
203 size_t size; 204 size_t size;
204 int quote; 205 int quote;
205 char *output; 206 char *output;
206 207
207 if (!input) 208 if (!input)
208 { 209 {
209 *poutput = xmalloc (1); 210 *poutput = grecs_malloc (1);
210 (*poutput)[0] = 0; 211 (*poutput)[0] = 0;
211 *psize = 1; 212 *psize = 1;
212 return 0; 213 return 0;
213 } 214 }
214 215
215 if (mp->quote) 216 if (mp->quote)
216 return mp->quote (dict, handle, input, poutput, psize); 217 return mp->quote (dict, handle, input, poutput, psize);
217 218
218 size = wordsplit_c_quoted_length (input, 0, &quote); 219 size = wordsplit_c_quoted_length (input, 0, &quote);
219 output = xmalloc (size + 1); 220 output = grecs_malloc (size + 1);
220 wordsplit_c_quote_copy (output, input, 0); 221 wordsplit_c_quote_copy (output, input, 0);
221 output[size] = 0; 222 output[size] = 0;
222 223
223 *poutput = output; 224 *poutput = output;
224 if (psize) 225 if (psize)
225 *psize = size; 226 *psize = size;
diff --git a/src/directive.c b/src/directive.c
index 08a14df..fadaedf 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -31,13 +31,13 @@ directive_parse (struct file_triplet *trp)
31 31
32 dcount = 0; 32 dcount = 0;
33 for (p = trp->blurb; *p; p++) 33 for (p = trp->blurb; *p; p++)
34 if (*p == '\n') 34 if (*p == '\n')
35 dcount++; 35 dcount++;
36 36
37 trp->directive = xcalloc (dcount + 1, sizeof trp->directive[0]); 37 trp->directive = grecs_calloc (dcount + 1, sizeof trp->directive[0]);
38 p = trp->blurb; 38 p = trp->blurb;
39 for (i = j = 0; i < dcount; i++) 39 for (i = j = 0; i < dcount; i++)
40 { 40 {
41 trp->directive[j] = p; 41 trp->directive[j] = p;
42 p = strchr (p, '\n'); 42 p = strchr (p, '\n');
43 if (p) 43 if (p)
@@ -108,13 +108,13 @@ _directive_seq_get (int n, struct file_triplet *trp,
108 108
109 p = strchr (trp->directive[n], ':'); 109 p = strchr (trp->directive[n], ':');
110 len = p - trp->directive[n]; 110 len = p - trp->directive[n];
111 if (len + 1 > trp->tmpsize) 111 if (len + 1 > trp->tmpsize)
112 { 112 {
113 trp->tmpsize = len + 1; 113 trp->tmpsize = len + 1;
114 trp->tmp = x2realloc (trp->tmp, &trp->tmpsize); 114 trp->tmp = grecs_realloc (trp->tmp, trp->tmpsize);
115 } 115 }
116 memcpy (trp->tmp, trp->directive[n], len); 116 memcpy (trp->tmp, trp->directive[n], len);
117 trp->tmp[len] = 0; 117 trp->tmp[len] = 0;
118 *pkey = trp->tmp; 118 *pkey = trp->tmp;
119 for (p++; *p && isspace (*p); p++) 119 for (p++; *p && isspace (*p); p++)
120 ; 120 ;
@@ -377,13 +377,13 @@ stderr_redirector (const char *tag)
377 char *buf = NULL; 377 char *buf = NULL;
378 378
379 close (p[1]); 379 close (p[1]);
380 fp = fdopen (p[0], "r"); 380 fp = fdopen (p[0], "r");
381 if (!fp) 381 if (!fp)
382 _exit (127); 382 _exit (127);
383 while (getline (&buf, &size, fp) >= 0) 383 while (grecs_getline (&buf, &size, fp) >= 0)
384 { 384 {
385 trim_crlf (buf); 385 trim_crlf (buf);
386 logmsg (LOG_NOTICE, "%s: %s", tag, buf); 386 logmsg (LOG_NOTICE, "%s: %s", tag, buf);
387 } 387 }
388 _exit (0); 388 _exit (0);
389 } 389 }
@@ -490,13 +490,13 @@ run_check_script (const char *script, struct file_triplet *trp,
490 close (p[1]); 490 close (p[1]);
491 fp = fdopen (p[0], "r"); 491 fp = fdopen (p[0], "r");
492 buf = NULL; 492 buf = NULL;
493 size = total = 0; 493 size = total = 0;
494 if (debug_level > 2) 494 if (debug_level > 2)
495 logmsg (LOG_DEBUG, _("reading script output...")); 495 logmsg (LOG_DEBUG, _("reading script output..."));
496 while (getline (&buf, &size, fp) > 0) 496 while (grecs_getline (&buf, &size, fp) > 0)
497 { 497 {
498 size_t len = strlen (buf); 498 size_t len = strlen (buf);
499 if (debug_level > 2) 499 if (debug_level > 2)
500 logmsg (LOG_DEBUG, _("read: %s"), buf); 500 logmsg (LOG_DEBUG, _("read: %s"), buf);
501 txtacc_grow (trp->acc, buf, len); 501 txtacc_grow (trp->acc, buf, len);
502 total += size; 502 total += size;
diff --git a/src/diskio.c b/src/diskio.c
index 9addd9b..b175a45 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -43,13 +43,13 @@ concat_dir (const char *base, const char *name, size_t *pbaselen)
43 char *dir; 43 char *dir;
44 44
45 while (len > 0 && base[len-1] == '/') 45 while (len > 0 && base[len-1] == '/')
46 len--; 46 len--;
47 47
48 size = len + 1 + strlen (name); 48 size = len + 1 + strlen (name);
49 dir = xmalloc (size + 1); 49 dir = grecs_malloc (size + 1);
50 memcpy (dir, base, len); 50 memcpy (dir, base, len);
51 dir[len++] = '/'; 51 dir[len++] = '/';
52 strcpy (dir + len, name); 52 strcpy (dir + len, name);
53 53
54 if (pbaselen) 54 if (pbaselen)
55 *pbaselen = len; 55 *pbaselen = len;
@@ -168,13 +168,13 @@ copy_file (const char *file, const char *dst_file)
168 fsize = st.st_size; 168 fsize = st.st_size;
169 169
170 for (bufsize = fsize; bufsize > 0 && (buf = malloc (bufsize)) == NULL; 170 for (bufsize = fsize; bufsize > 0 && (buf = malloc (bufsize)) == NULL;
171 bufsize /= 2) 171 bufsize /= 2)
172 ; 172 ;
173 if (bufsize == 0) 173 if (bufsize == 0)
174 xalloc_die (); 174 grecs_alloc_die ();
175 175
176 rc = 0; 176 rc = 0;
177 while (fsize > 0) 177 while (fsize > 0)
178 { 178 {
179 size_t rest; 179 size_t rest;
180 size_t rdbytes; 180 size_t rdbytes;
@@ -489,13 +489,13 @@ make_signame (const char *file_name)
489{ 489{
490 size_t len; 490 size_t len;
491 491
492 if (((len = strlen (file_name)) > SUF_SIG_LEN 492 if (((len = strlen (file_name)) > SUF_SIG_LEN
493 && memcmp (file_name + len - SUF_SIG_LEN, SUF_SIG, SUF_SIG_LEN))) 493 && memcmp (file_name + len - SUF_SIG_LEN, SUF_SIG, SUF_SIG_LEN)))
494 { 494 {
495 char *signame = xmalloc (len + SUF_SIG_LEN + 1); 495 char *signame = grecs_malloc (len + SUF_SIG_LEN + 1);
496 strcpy (signame, file_name); 496 strcpy (signame, file_name);
497 return strcat (signame, SUF_SIG); 497 return strcat (signame, SUF_SIG);
498 } 498 }
499 return NULL; 499 return NULL;
500} 500}
501 501
diff --git a/src/exec.c b/src/exec.c
index ed7ee1e..7ebf152 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -72,13 +72,13 @@ void
72log_output (int prio, const char *prog, FILE *fp) 72log_output (int prio, const char *prog, FILE *fp)
73{ 73{
74 size_t size = 0; 74 size_t size = 0;
75 char *buf = NULL; 75 char *buf = NULL;
76 76
77 logmsg (prio, _("%s output follows:"), prog); 77 logmsg (prio, _("%s output follows:"), prog);
78 while (getline (&buf, &size, fp) > 0) 78 while (grecs_getline (&buf, &size, fp) > 0)
79 logmsg (prio, "%s", buf); 79 logmsg (prio, "%s", buf);
80 logmsg (prio, _("end of %s output"), prog); 80 logmsg (prio, _("end of %s output"), prog);
81 free (buf); 81 free (buf);
82} 82}
83 83
84/* Execute ARGC/ARGV. Return the exit code in RETCODE. */ 84/* Execute ARGC/ARGV. Return the exit code in RETCODE. */
diff --git a/src/gpg.c b/src/gpg.c
index 474d94b..d4f9b71 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -129,13 +129,13 @@ remove_homedir ()
129static int 129static int
130create_gpg_homedir () 130create_gpg_homedir ()
131{ 131{
132 if (temp_homedir) 132 if (temp_homedir)
133 return 0; 133 return 0;
134 134
135 temp_homedir = xstrdup ("/tmp/wydawca-XXXXXX"); 135 temp_homedir = grecs_strdup ("/tmp/wydawca-XXXXXX");
136 if (!mkdtemp (temp_homedir)) 136 if (!mkdtemp (temp_homedir))
137 { 137 {
138 logmsg (LOG_CRIT, _("cannot create GPG home directory (%s): %s"), 138 logmsg (LOG_CRIT, _("cannot create GPG home directory (%s): %s"),
139 temp_homedir, strerror (errno)); 139 temp_homedir, strerror (errno));
140 return 1; 140 return 1;
141 } 141 }
@@ -234,13 +234,13 @@ verify_directive_signature (struct file_triplet *trp)
234 uptr->gpg_key, 234 uptr->gpg_key,
235 strlen (uptr->gpg_key), 235 strlen (uptr->gpg_key),
236 0)); 236 0));
237 fail_if_err (gpgme_op_import (ctx, key_data)); 237 fail_if_err (gpgme_op_import (ctx, key_data));
238 res = gpgme_op_import_result (ctx); 238 res = gpgme_op_import_result (ctx);
239 pstat = res->imports; 239 pstat = res->imports;
240 uptr->fpr = xstrdup (pstat->fpr); 240 uptr->fpr = grecs_strdup (pstat->fpr);
241 if (debug_level > 2) 241 if (debug_level > 2)
242 logmsg (LOG_DEBUG, _("imported key: user = %s, fingerprint = %s"), 242 logmsg (LOG_DEBUG, _("imported key: user = %s, fingerprint = %s"),
243 uptr->name, uptr->fpr); 243 uptr->name, uptr->fpr);
244 } 244 }
245 245
246 fail_if_err (gpgme_data_new_from_file (&directive_data, 246 fail_if_err (gpgme_data_new_from_file (&directive_data,
@@ -268,13 +268,14 @@ verify_directive_signature (struct file_triplet *trp)
268 logmsg (LOG_ERR, _("%s: directive verification failed: %s"), 268 logmsg (LOG_ERR, _("%s: directive verification failed: %s"),
269 trp->name, gpgme_strerror (ec)); 269 trp->name, gpgme_strerror (ec));
270 } 270 }
271 271
272 gpgme_data_release (directive_data); 272 gpgme_data_release (directive_data);
273 gpgme_data_release (key_data); 273 gpgme_data_release (key_data);
274 274 gpgme_release (ctx);
275
275 return rc; 276 return rc;
276} 277}
277 278
278/* Verify the detached signature of TRP. 279/* Verify the detached signature of TRP.
279 NOTE: It is assumed that the public key is already registered (by 280 NOTE: It is assumed that the public key is already registered (by
280 a previous call to verify_directive_signature). */ 281 a previous call to verify_directive_signature). */
diff --git a/src/job.c b/src/job.c
index 7e3fdf5..764e463 100644
--- a/src/job.c
+++ b/src/job.c
@@ -202,13 +202,13 @@ schedule_job (const struct spool *spool, uid_t uid)
202 logmsg (LOG_DEBUG, _("scheduling job: %s, %lu"), 202 logmsg (LOG_DEBUG, _("scheduling job: %s, %lu"),
203 spool->tag, (unsigned long)uid); 203 spool->tag, (unsigned long)uid);
204 204
205 job = job_locate (spool, uid); 205 job = job_locate (spool, uid);
206 if (!job) 206 if (!job)
207 { 207 {
208 job = xzalloc (sizeof (*job)); 208 job = grecs_zalloc (sizeof (*job));
209 job->spool = spool; 209 job->spool = spool;
210 job->uid = uid; 210 job->uid = uid;
211 job->pid = -1; 211 job->pid = -1;
212 time (&job->timestamp); 212 time (&job->timestamp);
213 job_insert (job, NULL); 213 job_insert (job, NULL);
214 } 214 }
diff --git a/src/lock.c b/src/lock.c
index 32367de..dece75d 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -184,21 +184,21 @@ host_name ()
184 184
185 do 185 do
186 { 186 {
187 if (!hostbuf) 187 if (!hostbuf)
188 { 188 {
189 size = 256; 189 size = 256;
190 hostbuf = xmalloc (size); 190 hostbuf = grecs_malloc (size);
191 } 191 }
192 else 192 else
193 { 193 {
194 size_t ns = size * 2; 194 size_t ns = size * 2;
195 if (size < ns) 195 if (size < ns)
196 xalloc_die (); 196 grecs_alloc_die ();
197 size = ns; 197 size = ns;
198 hostbuf = xrealloc (hostbuf, size); 198 hostbuf = grecs_realloc (hostbuf, size);
199 } 199 }
200 } 200 }
201 while ((rc = gethostname (hostbuf, size )) == -1 && 201 while ((rc = gethostname (hostbuf, size )) == -1 &&
202 (errno == EINVAL 202 (errno == EINVAL
203#ifdef ENAMETOOLONG 203#ifdef ENAMETOOLONG
204 || errno == ENAMETOOLONG 204 || errno == ENAMETOOLONG
@@ -258,13 +258,13 @@ wydawca_unlock (const char *lockfile)
258 unlink (lockfile); 258 unlink (lockfile);
259} 259}
260 260
261static char * 261static char *
262fix_tagname (const char *tag) 262fix_tagname (const char *tag)
263{ 263{
264 char *tagname = xstrdup (tag); 264 char *tagname = grecs_strdup (tag);
265 char *p; 265 char *p;
266 266
267 for (p = tagname; *p; p++) 267 for (p = tagname; *p; p++)
268 if (!isalnum (*p) && *p != '_' && *p != '-') 268 if (!isalnum (*p) && *p != '_' && *p != '-')
269 *p = '_'; 269 *p = '_';
270 return tagname; 270 return tagname;
@@ -275,22 +275,22 @@ wydawca_lockname (const char *tag)
275{ 275{
276 char *lockname = NULL; 276 char *lockname = NULL;
277 size_t size = 0; 277 size_t size = 0;
278 char *tagname = fix_tagname (tag); 278 char *tagname = fix_tagname (tag);
279 grecs_asprintf (&lockname, &size, "%s/LCK.%s", lockdir, tagname); 279 grecs_asprintf (&lockname, &size, "%s/LCK.%s", lockdir, tagname);
280 if (!lockname) 280 if (!lockname)
281 xalloc_die (); 281 grecs_alloc_die ();
282 free (tagname); 282 free (tagname);
283 return lockname; 283 return lockname;
284} 284}
285 285
286void 286void
287wydawca_lock_init () 287wydawca_lock_init ()
288{ 288{
289 if (enable_locking) 289 if (enable_locking)
290 { 290 {
291 if (!lockdir) 291 if (!lockdir)
292 lockdir = xstrdup (LOCALSTATEDIR "/lock/" PACKAGE); 292 lockdir = grecs_strdup (LOCALSTATEDIR "/lock/" PACKAGE);
293 if (create_hierarchy (lockdir, 0)) 293 if (create_hierarchy (lockdir, 0))
294 exit (EX_OSFILE); 294 exit (EX_OSFILE);
295 } 295 }
296} 296}
diff --git a/src/mail.c b/src/mail.c
index bac0381..6855ed7 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -288,22 +288,22 @@ mail_send_message (mu_address_t rcpt, const char *text,
288 mu_message_get_header (msg, &hdr); 288 mu_message_get_header (msg, &hdr);
289 mu_header_append (hdr, "X-Mailer", x_mailer); 289 mu_header_append (hdr, "X-Mailer", x_mailer);
290 290
291 if (rcpt) 291 if (rcpt)
292 { 292 {
293 mu_address_to_string (rcpt, NULL, 0, &size); 293 mu_address_to_string (rcpt, NULL, 0, &size);
294 buf = xmalloc (size + 1); 294 buf = grecs_malloc (size + 1);
295 mu_address_to_string (rcpt, buf, size + 1, NULL); 295 mu_address_to_string (rcpt, buf, size + 1, NULL);
296 296
297 mu_header_set_value (hdr, "To", buf, 1); 297 mu_header_set_value (hdr, "To", buf, 1);
298 free (buf); 298 free (buf);
299 299
300 if (from_address && mu_header_sget_value (hdr, "From", &sval)) 300 if (from_address && mu_header_sget_value (hdr, "From", &sval))
301 { 301 {
302 mu_address_to_string (from_address, NULL, 0, &size); 302 mu_address_to_string (from_address, NULL, 0, &size);
303 buf = xmalloc (size + 1); 303 buf = grecs_malloc (size + 1);
304 mu_address_to_string (from_address, buf, size + 1, NULL); 304 mu_address_to_string (from_address, buf, size + 1, NULL);
305 mu_header_set_value (hdr, "From", buf, 1); 305 mu_header_set_value (hdr, "From", buf, 1);
306 free (buf); 306 free (buf);
307 } 307 }
308 } 308 }
309 309
@@ -431,23 +431,23 @@ mail_stats ()
431 431
432 if (debug_level) 432 if (debug_level)
433 { 433 {
434 size_t size; 434 size_t size;
435 char *buf; 435 char *buf;
436 mu_address_to_string (admin_address, NULL, 0, &size); 436 mu_address_to_string (admin_address, NULL, 0, &size);
437 buf = xmalloc (size + 1); 437 buf = grecs_malloc (size + 1);
438 mu_address_to_string (admin_address, buf, size + 1, NULL); 438 mu_address_to_string (admin_address, buf, size + 1, NULL);
439 logmsg (LOG_DEBUG, _("sending stats to %s"), buf); 439 logmsg (LOG_DEBUG, _("sending stats to %s"), buf);
440 free (buf); 440 free (buf);
441 } 441 }
442 442
443 tc = timer_get_count () * 3; 443 tc = timer_get_count () * 3;
444 exp = make_stat_expansion (tc + 1); 444 exp = make_stat_expansion (tc + 1);
445 time (&t); 445 time (&t);
446 exp[0].kw = "date"; 446 exp[0].kw = "date";
447 exp[0].value = exp[0].storage = xstrdup (ctime (&t)); 447 exp[0].value = exp[0].storage = grecs_strdup (ctime (&t));
448 exp[0].value [strlen (exp[0].value) - 1] = 0; 448 exp[0].value [strlen (exp[0].value) - 1] = 0;
449 timer_fill_meta (exp + 1, tc); 449 timer_fill_meta (exp + 1, tc);
450 450
451 tmpl = resolve_message_template (admin_stat_message); 451 tmpl = resolve_message_template (admin_stat_message);
452 if (!tmpl) 452 if (!tmpl)
453 { 453 {
@@ -595,13 +595,13 @@ do_notify (struct file_triplet *trp, enum notification_event ev,
595 { 595 {
596 if (rcpt) 596 if (rcpt)
597 { 597 {
598 size_t size; 598 size_t size;
599 char *buf; 599 char *buf;
600 mu_address_to_string (rcpt, NULL, 0, &size); 600 mu_address_to_string (rcpt, NULL, 0, &size);
601 buf = xmalloc (size + 1); 601 buf = grecs_malloc (size + 1);
602 mu_address_to_string (rcpt, buf, size + 1, NULL); 602 mu_address_to_string (rcpt, buf, size + 1, NULL);
603 logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"), 603 logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"),
604 buf, trp->project, notification_event_str (ev)); 604 buf, trp->project, notification_event_str (ev));
605 free (buf); 605 free (buf);
606 } 606 }
607 else 607 else
@@ -639,13 +639,13 @@ const char *
639expand_email_admin (struct metadef *def, void *data) 639expand_email_admin (struct metadef *def, void *data)
640{ 640{
641 size_t size; 641 size_t size;
642 if (mu_address_to_string (admin_address, NULL, 0, &size) == 0) 642 if (mu_address_to_string (admin_address, NULL, 0, &size) == 0)
643 { 643 {
644 size++; 644 size++;
645 def->storage = xmalloc (size); 645 def->storage = grecs_malloc (size);
646 mu_address_to_string (admin_address, def->storage, size, NULL); 646 mu_address_to_string (admin_address, def->storage, size, NULL);
647 def->value = def->storage; 647 def->value = def->storage;
648 } 648 }
649 else 649 else
650 def->value = ""; 650 def->value = "";
651 return def->value; 651 return def->value;
@@ -667,13 +667,13 @@ expand_email_owner (struct metadef *def, void *data)
667 trp->project, gettext (errp)); 667 trp->project, gettext (errp));
668 def->value = ""; 668 def->value = "";
669 } 669 }
670 else if (mu_address_to_string (addr, NULL, 0, &size) == 0) 670 else if (mu_address_to_string (addr, NULL, 0, &size) == 0)
671 { 671 {
672 size++; 672 size++;
673 def->storage = xmalloc (size); 673 def->storage = grecs_malloc (size);
674 mu_address_to_string (addr, def->storage, size, NULL); 674 mu_address_to_string (addr, def->storage, size, NULL);
675 def->value = def->storage; 675 def->value = def->storage;
676 mu_address_destroy (&addr); 676 mu_address_destroy (&addr);
677 } 677 }
678 else 678 else
679 def->value = ""; 679 def->value = "";
diff --git a/src/net.c b/src/net.c
index 3e9fe30..d08a6ba 100644
--- a/src/net.c
+++ b/src/net.c
@@ -100,13 +100,13 @@ handle_connection (FILE *in, FILE *out)
100 char *buf = NULL; 100 char *buf = NULL;
101 size_t buflen = 0; 101 size_t buflen = 0;
102 const struct spool *spool; 102 const struct spool *spool;
103 char *p; 103 char *p;
104 struct passwd *pw; 104 struct passwd *pw;
105 105
106 if (getline (&buf, &buflen, in) <= 0) 106 if (grecs_getline (&buf, &buflen, in) <= 0)
107 return; 107 return;
108 trim_crlf (buf); 108 trim_crlf (buf);
109 if (debug_level) 109 if (debug_level)
110 logmsg (LOG_DEBUG, "recv: %s", buf); 110 logmsg (LOG_DEBUG, "recv: %s", buf);
111 spool = wydawca_find_spool (buf); 111 spool = wydawca_find_spool (buf);
112 if (!spool) 112 if (!spool)
@@ -122,13 +122,13 @@ handle_connection (FILE *in, FILE *out)
122 } 122 }
123 else if (spool->url) 123 else if (spool->url)
124 fprintf (out, "+ OK, URL %s\r\n", spool->url); 124 fprintf (out, "+ OK, URL %s\r\n", spool->url);
125 else 125 else
126 fprintf (out, "+ OK, spool %s\r\n", spool->tag); 126 fprintf (out, "+ OK, spool %s\r\n", spool->tag);
127 127
128 if (getline (&buf, &buflen, in) < 0) 128 if (grecs_getline (&buf, &buflen, in) < 0)
129 { 129 {
130 logmsg (LOG_ERR, "protocol error"); 130 logmsg (LOG_ERR, "protocol error");
131 free (buf); 131 free (buf);
132 return; 132 return;
133 } 133 }
134 134
diff --git a/src/process.c b/src/process.c
index e41709d..200d987 100644
--- a/src/process.c
+++ b/src/process.c
@@ -24,13 +24,13 @@ struct spool_list
24 24
25static struct spool_list *spool_list; 25static struct spool_list *spool_list;
26 26
27void 27void
28register_spool (struct spool *spool) 28register_spool (struct spool *spool)
29{ 29{
30 struct spool_list *sp = xmalloc (sizeof *sp); 30 struct spool_list *sp = grecs_malloc (sizeof *sp);
31 sp->spool = *spool; 31 sp->spool = *spool;
32 sp->next = spool_list; 32 sp->next = spool_list;
33 spool_list = sp; 33 spool_list = sp;
34} 34}
35 35
36static int 36static int
@@ -110,13 +110,13 @@ parse_file_name (const char *name, struct file_info *finfo)
110 for (i = 0; i < sizeof suftab / sizeof suftab[0]; i++) 110 for (i = 0; i < sizeof suftab / sizeof suftab[0]; i++)
111 { 111 {
112 if (len >= suftab[i].len 112 if (len >= suftab[i].len
113 && memcmp (name + len - suftab[i].len, 113 && memcmp (name + len - suftab[i].len,
114 suftab[i].suf, suftab[i].len) == 0) 114 suftab[i].suf, suftab[i].len) == 0)
115 { 115 {
116 finfo->name = xstrdup (name); 116 finfo->name = grecs_strdup (name);
117 finfo->type = suftab[i].type; 117 finfo->type = suftab[i].type;
118 finfo->root_len = len - suftab[i].len; 118 finfo->root_len = len - suftab[i].len;
119 return; 119 return;
120 } 120 }
121 } 121 }
122 abort (); /* should not happen */ 122 abort (); /* should not happen */
diff --git a/src/sql.c b/src/sql.c
index a4b311e..80eb344 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -27,13 +27,13 @@ struct sql_list
27static struct sql_list *sql_list; 27static struct sql_list *sql_list;
28 28
29/* Append CONN to the end of sql_list */ 29/* Append CONN to the end of sql_list */
30void 30void
31sql_register_conn (struct sqlconn *conn) 31sql_register_conn (struct sqlconn *conn)
32{ 32{
33 struct sql_list *ent = xmalloc (sizeof *ent); 33 struct sql_list *ent = grecs_malloc (sizeof *ent);
34 ent->conn = *conn; 34 ent->conn = *conn;
35 ent->next = sql_list; 35 ent->next = sql_list;
36 sql_list = ent; 36 sql_list = ent;
37} 37}
38 38
39/* Find a configured connection that has the given IDENT */ 39/* Find a configured connection that has the given IDENT */
@@ -195,13 +195,13 @@ sql_quote (struct dictionary *dict, void *handle, const char *input,
195 struct sqlconn *conn = handle; 195 struct sqlconn *conn = handle;
196 size_t len, size; 196 size_t len, size;
197 char *output; 197 char *output;
198 198
199 len = strlen (input); 199 len = strlen (input);
200 size = 2 * len + 1; 200 size = 2 * len + 1;
201 output = xmalloc (size); 201 output = grecs_malloc (size);
202 mysql_real_escape_string (&conn->mysql, output, input, len); 202 mysql_real_escape_string (&conn->mysql, output, input, len);
203 *poutput = output; 203 *poutput = output;
204 if (psize) 204 if (psize)
205 *psize = strlen (output); 205 *psize = strlen (output);
206 return 0; 206 return 0;
207} 207}
diff --git a/src/timer.c b/src/timer.c
index 1634462..cece63a 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -17,13 +17,12 @@
17#include <wydawca.h> 17#include <wydawca.h>
18#include <sys/time.h> 18#include <sys/time.h>
19#include <sys/resource.h> 19#include <sys/resource.h>
20#include <unistd.h> 20#include <unistd.h>
21#include <string.h> 21#include <string.h>
22#include <ctype.h> 22#include <ctype.h>
23#include <xalloc.h>
24 23
25struct timer_slot 24struct timer_slot
26{ 25{
27 char *name; 26 char *name;
28 double real; 27 double real;
29 double self_user; /* user time in sec */ 28 double self_user; /* user time in sec */
@@ -179,13 +178,13 @@ timer_format_time (double t)
179 else if (h) 178 else if (h)
180 grecs_asprintf (&str, &size, "%02ld:%02ld:%02ld", h, m, s); 179 grecs_asprintf (&str, &size, "%02ld:%02ld:%02ld", h, m, s);
181 else 180 else
182 grecs_asprintf (&str, &size, "%02ld:%02ld", m, s); 181 grecs_asprintf (&str, &size, "%02ld:%02ld", m, s);
183 } 182 }
184 if (!str) 183 if (!str)
185 xalloc_die (); 184 grecs_alloc_die ();
186 return str; 185 return str;
187} 186}
188 187
189size_t 188size_t
190timer_get_count () 189timer_get_count ()
191{ 190{
@@ -207,13 +206,13 @@ _fill_meta (void *sym, void *data)
207 if (tp->num) \ 206 if (tp->num) \
208 { \ 207 { \
209 char *buf = NULL; \ 208 char *buf = NULL; \
210 size_t size = 0; \ 209 size_t size = 0; \
211 grecs_asprintf (&buf, &size, "timer:%s:%s", slot->name, #arg); \ 210 grecs_asprintf (&buf, &size, "timer:%s:%s", slot->name, #arg); \
212 if (!buf) \ 211 if (!buf) \
213 xalloc_die (); \ 212 grecs_alloc_die (); \
214 tp->def->kw = buf; \ 213 tp->def->kw = buf; \
215 tp->def->storage = timer_format_time (__cat2__(timer_get_,arg) (slot)); \ 214 tp->def->storage = timer_format_time (__cat2__(timer_get_,arg) (slot)); \
216 tp->def->value = tp->def->storage; \ 215 tp->def->value = tp->def->storage; \
217 tp->def->expand = NULL; \ 216 tp->def->expand = NULL; \
218 tp->def++; \ 217 tp->def++; \
219 tp->num--; \ 218 tp->num--; \
diff --git a/src/triplet.c b/src/triplet.c
index 3083c64..9dfdf2c 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -57,12 +57,13 @@ hash_triplet_free (void *data)
57 txtacc_free (tp->acc); 57 txtacc_free (tp->acc);
58 58
59 /* Free uploader list */ 59 /* Free uploader list */
60 for (up = tp->uploader_list; up; ) 60 for (up = tp->uploader_list; up; )
61 { 61 {
62 struct uploader_info *next = up->next; 62 struct uploader_info *next = up->next;
63 free (up->fpr);
63 free (up); 64 free (up);
64 up = next; 65 up = next;
65 } 66 }
66 67
67 free (tp); 68 free (tp);
68} 69}
@@ -91,13 +92,13 @@ register_file (struct file_info *finfo, const struct spool *spool)
91 NULL, 92 NULL,
92 hash_triplet_free); 93 hash_triplet_free);
93 if (!triplet_table) 94 if (!triplet_table)
94 grecs_alloc_die (); 95 grecs_alloc_die ();
95 } 96 }
96 97
97 key.name = xmalloc (finfo->root_len + 1); 98 key.name = grecs_malloc (finfo->root_len + 1);
98 memcpy (key.name, finfo->name, finfo->root_len); 99 memcpy (key.name, finfo->name, finfo->root_len);
99 key.name[finfo->root_len] = 0; 100 key.name[finfo->root_len] = 0;
100 101
101 ret = grecs_symtab_lookup_or_install (triplet_table, &key, &install); 102 ret = grecs_symtab_lookup_or_install (triplet_table, &key, &install);
102 if (!ret) 103 if (!ret)
103 grecs_alloc_die (); 104 grecs_alloc_die ();
@@ -375,26 +376,26 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret)
375 group_name = "unknown"; /* should not happen */ 376 group_name = "unknown"; /* should not happen */
376 else 377 else
377 group_name = grp->gr_name; 378 group_name = grp->gr_name;
378 379
379 /* Size */ 380 /* Size */
380 if (grecs_asprintf (&sptr, &slen, "%lu", (unsigned long) info->sb.st_size)) 381 if (grecs_asprintf (&sptr, &slen, "%lu", (unsigned long) info->sb.st_size))
381 xalloc_die (); 382 grecs_alloc_die ();
382 383
383 /* Figure out padding and format the buffer */ 384 /* Figure out padding and format the buffer */
384 slen = strlen (sptr); 385 slen = strlen (sptr);
385 pad = strlen (user_name) + 1 + strlen (group_name) + 1 + slen; 386 pad = strlen (user_name) + 1 + strlen (group_name) + 1 + slen;
386 if (pad > ugswidth) 387 if (pad > ugswidth)
387 ugswidth = pad; 388 ugswidth = pad;
388 389
389 if (grecs_asprintf (&buf, &size, 390 if (grecs_asprintf (&buf, &size,
390 "%s %s %s %*s %s %s", 391 "%s %s %s %*s %s %s",
391 modes, user_name, group_name, ugswidth - pad + slen, 392 modes, user_name, group_name, ugswidth - pad + slen,
392 sptr, 393 sptr,
393 timebuf, info->name)) 394 timebuf, info->name))
394 xalloc_die (); 395 grecs_alloc_die ();
395 free (sptr); 396 free (sptr);
396 *pret = buf; 397 *pret = buf;
397 return 0; 398 return 0;
398} 399}
399 400
400static const char * 401static const char *
@@ -408,13 +409,13 @@ expand_triplet_ls_full (struct metadef *def, void *data)
408 size += strlen (buf[file_dist]) + 1; 409 size += strlen (buf[file_dist]) + 1;
409 if (format_file_data (trp, file_signature, &buf[file_signature]) == 0) 410 if (format_file_data (trp, file_signature, &buf[file_signature]) == 0)
410 size += strlen (buf[file_signature]) + 1; 411 size += strlen (buf[file_signature]) + 1;
411 if (format_file_data (trp, file_directive, &buf[file_directive]) == 0) 412 if (format_file_data (trp, file_directive, &buf[file_directive]) == 0)
412 size += strlen (buf[file_directive]) + 1; 413 size += strlen (buf[file_directive]) + 1;
413 414
414 def->value = def->storage = xmalloc (size + 1); 415 def->value = def->storage = grecs_malloc (size + 1);
415 def->value[0] = 0; 416 def->value[0] = 0;
416 if (buf[file_dist]) 417 if (buf[file_dist])
417 { 418 {
418 strcat (def->value, buf[file_dist]); 419 strcat (def->value, buf[file_dist]);
419 strcat (def->value, "\n"); 420 strcat (def->value, "\n");
420 } 421 }
@@ -443,13 +444,13 @@ expand_triplet_ls_upload (struct metadef *def, void *data)
443 444
444 if (format_file_data (trp, file_dist, &buf[file_dist]) == 0) 445 if (format_file_data (trp, file_dist, &buf[file_dist]) == 0)
445 size += strlen (buf[file_dist]) + 1; 446 size += strlen (buf[file_dist]) + 1;
446 if (format_file_data (trp, file_signature, &buf[file_signature]) == 0) 447 if (format_file_data (trp, file_signature, &buf[file_signature]) == 0)
447 size += strlen (buf[file_signature]) + 1; 448 size += strlen (buf[file_signature]) + 1;
448 449
449 def->value = def->storage = xmalloc (size + 1); 450 def->value = def->storage = grecs_malloc (size + 1);
450 def->value[0] = 0; 451 def->value[0] = 0;
451 if (buf[file_dist]) 452 if (buf[file_dist])
452 { 453 {
453 strcat (def->value, buf[file_dist]); 454 strcat (def->value, buf[file_dist]);
454 strcat (def->value, "\n"); 455 strcat (def->value, "\n");
455 } 456 }
@@ -549,13 +550,13 @@ expand_email_user (struct metadef *def, void *data)
549 struct file_triplet *trp = data; 550 struct file_triplet *trp = data;
550 if (trp->uploader) 551 if (trp->uploader)
551 { 552 {
552 size_t size = 0; 553 size_t size = 0;
553 if (grecs_asprintf (&def->storage, &size, "\"%s\" <%s>", 554 if (grecs_asprintf (&def->storage, &size, "\"%s\" <%s>",
554 trp->uploader->realname, trp->uploader->email)) 555 trp->uploader->realname, trp->uploader->email))
555 xalloc_die (); 556 grecs_alloc_die ();
556 def->value = def->storage; 557 def->value = def->storage;
557 } 558 }
558 return def->value; 559 return def->value;
559} 560}
560 561
561static const char * 562static const char *
@@ -591,21 +592,21 @@ expand_check_result (struct metadef *def, void *data)
591 else if (WIFEXITED (status)) 592 else if (WIFEXITED (status))
592 { 593 {
593 size_t size = 0; 594 size_t size = 0;
594 def->storage = NULL; 595 def->storage = NULL;
595 if (grecs_asprintf (&def->storage, &size, 596 if (grecs_asprintf (&def->storage, &size,
596 "%d", WEXITSTATUS (status))) 597 "%d", WEXITSTATUS (status)))
597 xalloc_die (); 598 grecs_alloc_die ();
598 } 599 }
599 else if (WIFSIGNALED (status)) 600 else if (WIFSIGNALED (status))
600 { 601 {
601 size_t size = 0; 602 size_t size = 0;
602 def->storage = NULL; 603 def->storage = NULL;
603 if (grecs_asprintf (&def->storage, &size, "SIG+%d", 604 if (grecs_asprintf (&def->storage, &size, "SIG+%d",
604 WTERMSIG (status))) 605 WTERMSIG (status)))
605 xalloc_die (); 606 grecs_alloc_die ();
606 } 607 }
607 else 608 else
608 return def->value = "[unrecognized return code]"; 609 return def->value = "[unrecognized return code]";
609 return def->value = def->storage; 610 return def->value = def->storage;
610} 611}
611 612
diff --git a/src/txtacc.c b/src/txtacc.c
index 91659f6..442e27e 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -31,14 +31,14 @@ struct txtacc
31 struct grecs_list *mem; /* List of already allocated elements */ 31 struct grecs_list *mem; /* List of already allocated elements */
32}; 32};
33 33
34static struct txtacc_entry * 34static struct txtacc_entry *
35txtacc_alloc_entry (struct grecs_list *list, size_t size) 35txtacc_alloc_entry (struct grecs_list *list, size_t size)
36{ 36{
37 struct txtacc_entry *p = xmalloc (sizeof (*p)); 37 struct txtacc_entry *p = grecs_malloc (sizeof (*p));
38 p->buf = xmalloc (size); 38 p->buf = grecs_malloc (size);
39 p->size = size; 39 p->size = size;
40 p->len = 0; 40 p->len = 0;
41 grecs_list_append (list, p); 41 grecs_list_append (list, p);
42 return p; 42 return p;
43} 43}
44 44
@@ -86,13 +86,13 @@ txtacc_entry_free (void *p)
86 } 86 }
87} 87}
88 88
89struct txtacc * 89struct txtacc *
90txtacc_create () 90txtacc_create ()
91{ 91{
92 struct txtacc *acc = xmalloc (sizeof (*acc)); 92 struct txtacc *acc = grecs_malloc (sizeof (*acc));
93 acc->cur = grecs_list_create (); 93 acc->cur = grecs_list_create ();
94 acc->cur->free_entry = txtacc_entry_free; 94 acc->cur->free_entry = txtacc_entry_free;
95 acc->mem = grecs_list_create (); 95 acc->mem = grecs_list_create ();
96 acc->mem->free_entry = txtacc_entry_free; 96 acc->mem->free_entry = txtacc_entry_free;
97 return acc; 97 return acc;
98} 98}
@@ -134,12 +134,13 @@ txtacc_finish (struct txtacc *acc, int steal)
134 return NULL; 134 return NULL;
135 135
136 case 1: 136 case 1:
137 txtent = acc->cur->head->data; 137 txtent = acc->cur->head->data;
138 acc->cur->head->data = NULL; 138 acc->cur->head->data = NULL;
139 txtacc_entry_tailor (txtent); 139 txtacc_entry_tailor (txtent);
140 grecs_list_append (acc->mem, txtent);
140 break; 141 break;
141 142
142 default: 143 default:
143 size = 0; 144 size = 0;
144 for (ep = acc->cur->head; ep; ep = ep->next) 145 for (ep = acc->cur->head; ep; ep = ep->next)
145 { 146 {
@@ -155,28 +156,29 @@ txtacc_finish (struct txtacc *acc, int steal)
155 } 156 }
156 } 157 }
157 158
158 grecs_list_clear (acc->cur); 159 grecs_list_clear (acc->cur);
159 p = txtent->buf; 160 p = txtent->buf;
160 if (steal) 161 if (steal)
161 free (txtent); 162 {
162 else 163 grecs_list_remove_tail (acc->mem);
163 grecs_list_append (acc->mem, txtent); 164 free (txtent);
165 }
164 return p; 166 return p;
165} 167}
166 168
167void 169void
168txtacc_free_string (struct txtacc *acc, char *str) 170txtacc_free_string (struct txtacc *acc, char *str)
169{ 171{
170 struct grecs_list_entry *ep; 172 struct grecs_list_entry *ep;
171 for (ep = acc->mem->head; ep; ep = ep->next) 173 for (ep = acc->mem->head; ep; ep = ep->next)
172 { 174 {
173 struct txtacc_entry *tp = ep->data; 175 struct txtacc_entry *tp = ep->data;
174 if (tp->buf == str) 176 if (tp->buf == str)
175 { 177 {
176 grecs_list_remove_entry(acc->mem, ep); 178 grecs_list_remove_entry (acc->mem, ep);
177 free (tp->buf); 179 free (tp->buf);
178 return; 180 return;
179 } 181 }
180 } 182 }
181} 183}
182 184
diff --git a/src/verify.c b/src/verify.c
index a49983c..c8fef11 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -110,13 +110,13 @@ fill_project_name (struct file_triplet *trp)
110 { 110 {
111 logmsg (LOG_ERR, _("cannot open file %s: %s"), 111 logmsg (LOG_ERR, _("cannot open file %s: %s"),
112 trp->file[file_directive].name, strerror (errno)); 112 trp->file[file_directive].name, strerror (errno));
113 return 1; 113 return 1;
114 } 114 }
115 115
116 blurb = xmalloc (size + 1); 116 blurb = grecs_malloc (size + 1);
117 117
118 rc = fread (blurb, size, 1, fp); 118 rc = fread (blurb, size, 1, fp);
119 fclose (fp); 119 fclose (fp);
120 120
121 if (rc != 1) 121 if (rc != 1)
122 { 122 {
@@ -179,13 +179,13 @@ fill_project_name (struct file_triplet *trp)
179 return 0; 179 return 0;
180} 180}
181 181
182struct uploader_info * 182struct uploader_info *
183new_uploader_info (struct uploader_info *src) 183new_uploader_info (struct uploader_info *src)
184{ 184{
185 struct uploader_info *p = xmalloc (sizeof (*p)); 185 struct uploader_info *p = grecs_malloc (sizeof (*p));
186 p->next = NULL; 186 p->next = NULL;
187 p->name = src->name; 187 p->name = src->name;
188 p->realname = src->realname; 188 p->realname = src->realname;
189 p->gpg_key = src->gpg_key; 189 p->gpg_key = src->gpg_key;
190 p->email = src->email; 190 p->email = src->email;
191 p->fpr = NULL; 191 p->fpr = NULL;
diff --git a/src/wydawca.c b/src/wydawca.c
index cc1815b..36aa8b7 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -68,13 +68,13 @@ syslog_printer (int prio, const char *fmt, va_list ap)
68 const char *p = mu_syslog_priority_to_string (prio); 68 const char *p = mu_syslog_priority_to_string (prio);
69 size_t size = strlen (p) + 3 + strlen (fmt) + 1; 69 size_t size = strlen (p) + 3 + strlen (fmt) + 1;
70 70
71 if (size > fmtsize) 71 if (size > fmtsize)
72 { 72 {
73 fmtsize = size; 73 fmtsize = size;
74 fmtbuf = x2realloc (fmtbuf, &fmtsize); 74 fmtbuf = grecs_realloc (fmtbuf, fmtsize);
75 } 75 }
76 sprintf (fmtbuf, "[%s] %s", p, fmt); 76 sprintf (fmtbuf, "[%s] %s", p, fmt);
77 fmt = fmtbuf; 77 fmt = fmtbuf;
78 } 78 }
79 79
80#if HAVE_VSYSLOG 80#if HAVE_VSYSLOG
@@ -176,23 +176,23 @@ static const char *
176stat_expand (struct metadef *def, void *data) 176stat_expand (struct metadef *def, void *data)
177{ 177{
178 size_t size = 0; 178 size_t size = 0;
179 def->storage = NULL; 179 def->storage = NULL;
180 if (grecs_asprintf (&def->storage, &size, "%u", 180 if (grecs_asprintf (&def->storage, &size, "%u",
181 wydawca_stat[(int) def->data])) 181 wydawca_stat[(int) def->data]))
182 xalloc_die (); 182 grecs_alloc_die ();
183 def->value = def->storage; 183 def->value = def->storage;
184 return def->value; 184 return def->value;
185} 185}
186 186
187struct metadef * 187struct metadef *
188make_stat_expansion (size_t count) 188make_stat_expansion (size_t count)
189{ 189{
190 int i; 190 int i;
191 struct metadef *def, *p; 191 struct metadef *def, *p;
192 def = xcalloc (MAX_STAT + count + 1, sizeof (def[0])); 192 def = grecs_calloc (MAX_STAT + count + 1, sizeof (def[0]));
193 p = def + count; 193 p = def + count;
194 for (i = 0; i < MAX_STAT; i++, p++) 194 for (i = 0; i < MAX_STAT; i++, p++)
195 { 195 {
196 p->kw = stat_kwname[i]; 196 p->kw = stat_kwname[i];
197 p->value = NULL; 197 p->value = NULL;
198 p->storage = NULL; 198 p->storage = NULL;
@@ -249,13 +249,13 @@ static uid_t *uidv;
249static void 249static void
250collect_uids (int argc, char **argv) 250collect_uids (int argc, char **argv)
251{ 251{
252 int i; 252 int i;
253 253
254 uidc = argc; 254 uidc = argc;
255 uidv = xcalloc (uidc, sizeof (uidv[0])); 255 uidv = grecs_calloc (uidc, sizeof (uidv[0]));
256 for (i = 0; i < argc; i++) 256 for (i = 0; i < argc; i++)
257 { 257 {
258 struct passwd *pw = getpwnam (argv[i]); 258 struct passwd *pw = getpwnam (argv[i]);
259 if (!pw) 259 if (!pw)
260 { 260 {
261 char *p; 261 char *p;
diff --git a/src/wydawca.h b/src/wydawca.h
index 2307bad..94b7ee3 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -38,20 +38,19 @@
38#include <sys/wait.h> 38#include <sys/wait.h>
39#include <netdb.h> 39#include <netdb.h>
40#include <arpa/inet.h> 40#include <arpa/inet.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <time.h> 42#include <time.h>
43#include <sysexits.h> 43#include <sysexits.h>
44#include <fnmatch.h>
45#include <regex.h>
44 46
45#include <mailutils/types.h> 47#include <mailutils/types.h>
46#include <mailutils/url.h> 48#include <mailutils/url.h>
47#include <mailutils/errno.h> 49#include <mailutils/errno.h>
48 50
49#include "error.h"
50#include "xalloc.h"
51#include "backupfile.h"
52#include "grecs.h" 51#include "grecs.h"
53#include "wordsplit.h" 52#include "wordsplit.h"
54 53
55#define SP(s) ((s) ? (s) : "NONE") 54#define SP(s) ((s) ? (s) : "NONE")
56 55
57#define WYDAWCA_EX_AGAIN 1 56#define WYDAWCA_EX_AGAIN 1
@@ -107,12 +106,27 @@ struct dictionary
107 unsigned nrow; /* Number of rows */ 106 unsigned nrow; /* Number of rows */
108 107
109 void *storage; 108 void *storage;
110}; 109};
111 110
112 111
112enum backup_type
113 {
114 no_backups, /* Don't make backups */
115 simple_backups, /* Make only simple backups */
116 numbered_existing_backups,/* Make numbered backups for files that already
117 have such backups and simple backups for the
118 rest */
119 numbered_backups, /* Make only numbered backups */
120 };
121
122extern char const *simple_backup_suffix;
123
124char *find_backup_file_name (char const *, enum backup_type);
125
126
113/* Archive types */ 127/* Archive types */
114 128
115enum archive_type 129enum archive_type
116 { 130 {
117 archive_none, /* No archivation requested */ 131 archive_none, /* No archivation requested */
118 archive_directory, /* Archive by moving files to a separate directory 132 archive_directory, /* Archive by moving files to a separate directory

Return to:

Send suggestions and report system problems to the System administrator.