aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
@@ -7,24 +7,25 @@
# any later version.
#
# Wydawca is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
sbin_PROGRAMS=wydawca
wydawca_SOURCES=\
+ backup.c\
builtin.c\
builtin.h\
cmdline.h\
config.c\
dictionary.c\
directive.c\
diskio.c\
exec.c\
gpg.c\
interval.c\
job.c\
lock.c\
@@ -51,21 +52,21 @@ wydawca_SOURCES=\
BUILT_SOURCES=cmdline.h
EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk
SUFFIXES=.opt .c .h
.opt.h:
$(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@
incdir=$(pkgdatadir)/$(VERSION)/include
inc_DATA = $(PP_SETUP_FILE)
-LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
-INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@
+LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
+INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@
AM_CPPFLAGS= \
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DLOCALSTATEDIR=\"$(localstatedir)\"\
-DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
-DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
-DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)"
diff --git a/src/backup.c b/src/backup.c
new file mode 100644
index 0000000..312375d
--- /dev/null
+++ b/src/backup.c
@@ -0,0 +1,165 @@
+/* wydawca - automatic release submission daemon
+ Copyright (C) 2011 Sergey Poznyakoff
+
+ Wydawca is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ Wydawca is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with wydawca. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "wydawca.h"
+
+char const *simple_backup_suffix = "~";
+
+static const char *
+split_filename (char const *file, char **pdir)
+{
+ const char *p = strrchr (file, '/');
+
+ if (!p)
+ {
+ *pdir = grecs_strdup (".");
+ p = file;
+ }
+ else
+ {
+ size_t len = p - file;
+ char *dir = grecs_malloc (len + 1);
+ memcpy (dir, file, len);
+ dir[len] = 0;
+ *pdir = dir;
+ p++;
+ }
+ return p;
+}
+
+#define MINSUFSIZE 8
+#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
+
+static char *
+get_backup_suffix (char const *file, enum backup_type type)
+{
+ char *dirname;
+ const char *basename;
+ size_t baselen;
+ DIR *dir;
+ struct dirent *ent;
+ char *lastsuf = NULL;
+ size_t lastsuflen = 0;
+ size_t lastsufsize = 0;
+ int carry;
+ char *newsuf;
+ char *q;
+
+ if (type == simple_backups)
+ return grecs_strdup (simple_backup_suffix);
+
+ basename = split_filename (file, &dirname);
+ baselen = strlen (basename);
+ dir = opendir (dirname);
+ if (!dir)
+ {
+ int ec = errno;
+ free (dirname);
+ errno = ec;
+ return NULL;
+ }
+
+ while ((ent = readdir (dir)))
+ {
+ size_t len = strlen (ent->d_name);
+ const char *p;
+ size_t suflen;
+
+ if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen))
+ continue;
+ p = ent->d_name + baselen;
+ suflen = len - baselen;
+ if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' &&
+ (suflen > lastsuflen
+ || (suflen == lastsuflen &&
+ memcmp (p, lastsuf, lastsuflen) > 0)))
+ {
+ carry = 1;
+ for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--)
+ if (*q != '9')
+ carry = 0;
+ q++;
+ if (!ISDIGIT (*q))
+ continue;
+
+ if (suflen > lastsufsize)
+ {
+ lastsufsize = suflen;
+ if (!lastsuf)
+ {
+ if (lastsufsize < MINSUFSIZE)
+ lastsufsize = MINSUFSIZE;
+ lastsuf = grecs_malloc (lastsufsize);
+ }
+ else
+ lastsuf = grecs_realloc (lastsuf, lastsufsize);
+ }
+ memcpy (lastsuf, p, suflen);
+ lastsuflen = suflen;
+ }
+ }
+ closedir (dir);
+ free (dirname);
+
+ if (lastsuf)
+ {
+ size_t newsuflen;
+
+ newsuflen = lastsuflen + carry;
+ newsuf = grecs_malloc (newsuflen + 1);
+ newsuf[0] = '.';
+ newsuf[1] = '~';
+ newsuf[2] = '0';
+ memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3);
+ newsuf[newsuflen-1] = '~';
+ newsuf[newsuflen] = 0;
+
+ for (q = newsuf + newsuflen - 2; *q == '9'; q--)
+ *q = '0';
+ ++*q;
+ free (lastsuf);
+ }
+ else if (type == numbered_existing_backups)
+ newsuf = grecs_strdup (simple_backup_suffix);
+ else
+ newsuf = grecs_strdup (".~1~");
+ return newsuf;
+}
+
+char *
+find_backup_file_name (char const *file, enum backup_type type)
+{
+ size_t flen;
+ char *suffix;
+ char *newname;
+
+ if (type == no_backups)
+ {
+ errno = 0;
+ return NULL;
+ }
+
+ suffix = get_backup_suffix (file, type);
+ if (!suffix)
+ return NULL;
+ flen = strlen (file);
+ newname = grecs_malloc (flen + strlen (suffix) + 1);
+ memcpy (newname, file, flen);
+ strcpy (newname + flen, suffix);
+ free (suffix);
+ /* FIXME: Check newname length */
+ return newname;
+}
diff --git a/src/builtin.c b/src/builtin.c
index 9d1063c..8a07eab 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -7,26 +7,28 @@
option) any later version.
Wydawca is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#include "wydawca.h"
#include "builtin.h"
-#include "fnmatch.h"
-#include "regex.h"
+
+#ifndef FNM_CASEFOLD
+# define FNM_CASEFOLD 0
+#endif
int
builtin_init (struct dictionary *dict)
{
return 0;
}
int
builtin_done (struct dictionary *dict)
{
return 0;
}
@@ -211,27 +213,27 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
if (count == 0)
{
txtacc_free (acc);
bds = NULL;
rc = 1;
}
else
{
size_t i;
char *p;
- bds = xmalloc (sizeof (*bds));
+ bds = grecs_malloc (sizeof (*bds));
count *= ncol;
- bds->wp = xcalloc (count, sizeof (bds->wp[0]));
+ bds->wp = grecs_calloc (count, sizeof (bds->wp[0]));
bds->acc = acc;
p = txtacc_finish (acc, 0);
for (i = 0; i < count; i++)
{
bds->wp[i] = p;
p += strlen (p) + 1;
}
rc = 0;
}
dict->storage = bds;
diff --git a/src/config.c b/src/config.c
index df9816e..8250749 100644
--- a/src/config.c
+++ b/src/config.c
@@ -137,25 +137,25 @@ safe_file_name (char *file_name)
{
file_name[0] = '/';
file_name[1] = 0;
}
return file_name;
}
/* Same as safe_file_name, but returns an allocated copy. */
char *
safe_file_name_alloc (const char *file_name)
{
- char *s = xstrdup (file_name);
+ char *s = grecs_strdup (file_name);
char *ns = safe_file_name (s);
if (!ns)
free (s);
return ns;
}
static struct keyword event_tab[] = {
{ "success", ev_success },
{ "bad-ownership", ev_bad_ownership },
{ "bad-directive-signature", ev_bad_directive_signature },
{ "bad-detached-signature", ev_bad_detached_signature },
@@ -540,70 +540,70 @@ cb_sql_host (enum grecs_callback_command cmd,
char *p;
if (assert_string_arg (locus, cmd, value))
return 1;
p = strchr (value->v.string, ':');
if (p)
{
/* FIXME: Modifies constant string */
*p++ = 0;
if (p[0] == '/')
{
- pconn->socket = xstrdup (p);
- pconn->host = xstrdup ("localhost");
+ pconn->socket = grecs_strdup (p);
+ pconn->host = grecs_strdup ("localhost");
}
else
{
char *end;
unsigned long n = strtoul (p, &end, 10);
if (*end)
{
grecs_error (locus, 0, _("invalid port number (near %s)"), end);
return 0;
}
if (n == 0 || n > USHRT_MAX)
{
grecs_error (locus, 0, _("port number out of range 1..%d"),
USHRT_MAX);
return 0;
}
pconn->port = n;
/* Save host name */
- pconn->host = xstrdup (value->v.string);
+ pconn->host = grecs_strdup (value->v.string);
}
}
else
- pconn->host = xstrdup (value->v.string);
+ pconn->host = grecs_strdup (value->v.string);
return 0;
}
static int
cb_sql (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct sqlconn *pconn;
void **pdata = cb_data;
switch (cmd) {
case grecs_callback_section_begin:
if (!value || value->type != GRECS_TYPE_STRING)
{
grecs_error(locus, 0, _("tag must be a string"));
return 0;
}
- pconn = xzalloc (sizeof (*pconn));
+ pconn = grecs_zalloc (sizeof (*pconn));
pconn->ident = strdup (value->v.string);
*pdata = pconn;
break;
case grecs_callback_section_end:
pconn = *pdata;
sql_register_conn (pconn);
free (pconn);
*pdata = NULL;
break;
case grecs_callback_set_value:
@@ -887,25 +887,25 @@ static struct grecs_keyword notify_event_kw[] = {
static int
cb_notify_event (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct notification *ntf;
void **pdata = cb_data;
switch (cmd) {
case grecs_callback_section_begin:
- ntf = xzalloc (sizeof (*ntf));
+ ntf = grecs_zalloc (sizeof (*ntf));
*pdata = ntf;
break;
case grecs_callback_section_end:
ntf = *pdata;
if (!ntf->msg)
grecs_error (locus, 0, _("missing message definition"));
else
{
struct notification **p = (struct notification **) varptr;
ntf->next = *p;
*p = ntf;
@@ -975,34 +975,34 @@ cb_dictionary_params (enum grecs_callback_command cmd,
size = grecs_list_size (value->v.list);
if (size == 0)
{
meth->parmc = 0;
meth->parmv = NULL;
}
else
{
int i;
struct grecs_list_entry *ep;
meth->parmc = size;
- meth->parmv = xcalloc (size + 1, sizeof (meth->parmv[0]));
+ meth->parmv = grecs_calloc (size + 1, sizeof (meth->parmv[0]));
for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
{
const grecs_value_t *vp = ep->data;
if (assert_string_arg (locus, cmd, vp))
break;
- meth->parmv[i] = xstrdup (vp->v.string);
+ meth->parmv[i] = grecs_strdup (vp->v.string);
}
meth->parmv[i] = NULL;
}
return 0;
}
static struct grecs_keyword dictionary_kw[] = {
{ "type", N_("type"), N_("Dictionary type"),
grecs_type_string, NULL, offsetof(struct dictionary, type),
cb_dictionary_type },
{ "query", N_("string"), N_("Query template"),
grecs_type_string, NULL, offsetof(struct dictionary, query) },
@@ -1150,26 +1150,26 @@ cb_spool (enum grecs_callback_command cmd,
struct spool *spool;
void **pdata = cb_data;
int rc, ec, i;
switch (cmd)
{
case grecs_callback_section_begin:
if (!value || value->type != GRECS_TYPE_STRING)
{
grecs_error (locus, 0, _("tag must be a string"));
return 1;
}
- spool = xzalloc (sizeof (*spool));
- spool->tag = xstrdup (value->v.string);
+ spool = grecs_zalloc (sizeof (*spool));
+ spool->tag = grecs_strdup (value->v.string);
spool->file_sweep_time = file_sweep_time;
for (i = 0; i < NITEMS (spool->dictionary); i++)
spool->dictionary[i] = default_dictionary[i];
spool->archive = default_archive_descr;
*pdata = spool;
break;
case grecs_callback_section_end:
rc = 0;
spool = *pdata;
if (!spool->source_dir)
{
@@ -1268,26 +1268,26 @@ cb_supp_groups (enum grecs_callback_command cmd,
grecs_error (locus, 0, _("expected list value"));
return 1;
}
wydawca_supp_groupc = grecs_list_size (value->v.list);
if (wydawca_supp_groupc == 0)
wydawca_supp_groups = NULL;
else
{
int i;
struct grecs_list_entry *ep;
- wydawca_supp_groups = xcalloc (wydawca_supp_groupc,
- sizeof (wydawca_supp_groups[0]));
+ wydawca_supp_groups = grecs_calloc (wydawca_supp_groupc,
+ sizeof (wydawca_supp_groups[0]));
for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
{
const grecs_value_t *vp = ep->data;
struct group *grp;
if (assert_string_arg (locus, cmd, vp))
break;
grp = getgrnam (vp->v.string);
if (!grp)
{
grecs_error (locus, 0, _("no such group: %s"), value->v.string);
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -39,26 +39,25 @@ static struct dictionary_descr dictionary_tab[] = {
{ "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result,
sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote },
{ "builtin", builtin_init, builtin_done, builtin_free_result,
builtin_open, NULL,
builtin_get,
builtin_lookup },
{ "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
struct dictionary *
dictionary_new (enum dictionary_id id, enum dictionary_type type)
{
- struct dictionary *mp = xmalloc (sizeof mp[0]);
- memset (mp, 0, sizeof mp[0]);
+ struct dictionary *mp = grecs_zalloc (sizeof mp[0]);
mp->id = id;
mp->type = type;
return mp;
}
int
dictionary_init (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed++)
@@ -83,24 +82,26 @@ dictionary_open (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
if (!mp->open)
return NULL;
return mp->open (dict);
}
int
dictionary_close (struct dictionary *dict, void *handle)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
+ if (mp->free)
+ mp->free (dict, handle);
if (!mp->close)
return 0;
return mp->close (dict, handle);
}
int
dictionary_done (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed == 0)
@@ -177,52 +178,52 @@ dictionary_result (struct dictionary *dict, void *handle,
if (nrow >= dict->nrow || ncol >= dict->ncol
|| mp->get (dict, handle, nrow, ncol))
return NULL;
return dict->result;
}
void
dictionary_copy_result (struct dictionary *dict, const char *res, size_t size)
{
if (dict->result_size < size + 1)
{
dict->result_size = size + 1;
- dict->result = x2realloc (dict->result, &dict->result_size);
+ dict->result = grecs_realloc (dict->result, dict->result_size);
}
memcpy (dict->result, res, size);
dict->result[size] = 0;
}
/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed
quoted string. Return its length. */
int
dictionary_quote_string (struct dictionary *dict, void *handle,
const char *input,
char **poutput, size_t *psize)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
size_t size;
int quote;
char *output;
if (!input)
{
- *poutput = xmalloc (1);
+ *poutput = grecs_malloc (1);
(*poutput)[0] = 0;
*psize = 1;
return 0;
}
if (mp->quote)
return mp->quote (dict, handle, input, poutput, psize);
size = wordsplit_c_quoted_length (input, 0, &quote);
- output = xmalloc (size + 1);
+ output = grecs_malloc (size + 1);
wordsplit_c_quote_copy (output, input, 0);
output[size] = 0;
*poutput = output;
if (psize)
*psize = size;
return 0;
}
diff --git a/src/directive.c b/src/directive.c
index 08a14df..fadaedf 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -25,25 +25,25 @@ directive_parse (struct file_triplet *trp)
size_t dcount, i, j;
char *p;
if (debug_level > 2)
logmsg (LOG_DEBUG, _("%s: parsing directive blurb: %s"),
trp->file[file_directive].name, trp->blurb);
dcount = 0;
for (p = trp->blurb; *p; p++)
if (*p == '\n')
dcount++;
- trp->directive = xcalloc (dcount + 1, sizeof trp->directive[0]);
+ trp->directive = grecs_calloc (dcount + 1, sizeof trp->directive[0]);
p = trp->blurb;
for (i = j = 0; i < dcount; i++)
{
trp->directive[j] = p;
p = strchr (p, '\n');
if (p)
*p++ = 0;
if (trim (trp->directive[j]) == 0) /* ignore empty lines */
continue;
if (strchr (trp->directive[j], ':') == NULL)
{
logmsg (LOG_ERR, _("%s: invalid line: %s"),
@@ -102,25 +102,25 @@ _directive_seq_get (int n, struct file_triplet *trp,
{
char *p;
size_t len;
if (trp->directive[n] == NULL)
return 0;
p = strchr (trp->directive[n], ':');
len = p - trp->directive[n];
if (len + 1 > trp->tmpsize)
{
trp->tmpsize = len + 1;
- trp->tmp = x2realloc (trp->tmp, &trp->tmpsize);
+ trp->tmp = grecs_realloc (trp->tmp, trp->tmpsize);
}
memcpy (trp->tmp, trp->directive[n], len);
trp->tmp[len] = 0;
*pkey = trp->tmp;
for (p++; *p && isspace (*p); p++)
;
if (pval)
*pval = p;
return ++n;
}
/* Get the first directive from TRP. Point *PKEY to its keyword and
@@ -371,25 +371,25 @@ stderr_redirector (const char *tag)
}
if (pid == 0)
{
FILE *fp;
size_t size = 0;
char *buf = NULL;
close (p[1]);
fp = fdopen (p[0], "r");
if (!fp)
_exit (127);
- while (getline (&buf, &size, fp) >= 0)
+ while (grecs_getline (&buf, &size, fp) >= 0)
{
trim_crlf (buf);
logmsg (LOG_NOTICE, "%s: %s", tag, buf);
}
_exit (0);
}
close (p[0]);
return p[1];
}
static int
@@ -484,25 +484,25 @@ run_check_script (const char *script, struct file_triplet *trp,
execv ("/bin/sh", argv);
_exit (127);
}
/* Master */
free (script_file);
close (p[1]);
fp = fdopen (p[0], "r");
buf = NULL;
size = total = 0;
if (debug_level > 2)
logmsg (LOG_DEBUG, _("reading script output..."));
- while (getline (&buf, &size, fp) > 0)
+ while (grecs_getline (&buf, &size, fp) > 0)
{
size_t len = strlen (buf);
if (debug_level > 2)
logmsg (LOG_DEBUG, _("read: %s"), buf);
txtacc_grow (trp->acc, buf, len);
total += size;
}
txtacc_1grow (trp->acc, 0);
if (debug_level > 2)
logmsg (LOG_DEBUG, _("bytes read: %lu"), (unsigned long)total);
fclose (fp);
diff --git a/src/diskio.c b/src/diskio.c
index 9addd9b..b175a45 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -37,25 +37,25 @@ sub_dir_p (const char *arg, const char *dir)
slash. */
char *
concat_dir (const char *base, const char *name, size_t *pbaselen)
{
size_t len = strlen (base);
size_t size;
char *dir;
while (len > 0 && base[len-1] == '/')
len--;
size = len + 1 + strlen (name);
- dir = xmalloc (size + 1);
+ dir = grecs_malloc (size + 1);
memcpy (dir, base, len);
dir[len++] = '/';
strcpy (dir + len, name);
if (pbaselen)
*pbaselen = len;
return dir;
}
/* Create the directory DIR, eventually creating all intermediate directories
starting from DIR + BASELEN. */
int
@@ -162,25 +162,25 @@ copy_file (const char *file, const char *dst_file)
file, strerror (errno));
close (in_fd);
return 1;
}
buf = NULL;
fsize = st.st_size;
for (bufsize = fsize; bufsize > 0 && (buf = malloc (bufsize)) == NULL;
bufsize /= 2)
;
if (bufsize == 0)
- xalloc_die ();
+ grecs_alloc_die ();
rc = 0;
while (fsize > 0)
{
size_t rest;
size_t rdbytes;
rest = fsize > bufsize ? bufsize : fsize;
rdbytes = read (in_fd, buf, rest);
if (rdbytes == -1)
{
logmsg (LOG_ERR, _("unexpected error reading %s: %s"),
@@ -483,25 +483,25 @@ archive_single_file (struct file_triplet *trp, const char *file_name,
free (dst_dir);
return rc;
}
static char *
make_signame (const char *file_name)
{
size_t len;
if (((len = strlen (file_name)) > SUF_SIG_LEN
&& memcmp (file_name + len - SUF_SIG_LEN, SUF_SIG, SUF_SIG_LEN)))
{
- char *signame = xmalloc (len + SUF_SIG_LEN + 1);
+ char *signame = grecs_malloc (len + SUF_SIG_LEN + 1);
strcpy (signame, file_name);
return strcat (signame, SUF_SIG);
}
return NULL;
}
/* Archive the file FILE_NAME, located in DPAIR->dest_dir, and remove the
file. Get user IDs from the triplet TRP. Unless FILE_NAME ends in
".sig", do the same with FILE_NAME.sig, if such a file exists.
Do nothing if dry_run_mode is set.
*/
int
diff --git a/src/exec.c b/src/exec.c
index ed7ee1e..7ebf152 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -66,25 +66,25 @@ start_prog (int argc, const char **argv, pid_t *ppid)
return fp;
}
/* Log everything read from FP as the output from the program PROG, using
syslog priority PRIO. */
void
log_output (int prio, const char *prog, FILE *fp)
{
size_t size = 0;
char *buf = NULL;
logmsg (prio, _("%s output follows:"), prog);
- while (getline (&buf, &size, fp) > 0)
+ while (grecs_getline (&buf, &size, fp) > 0)
logmsg (prio, "%s", buf);
logmsg (prio, _("end of %s output"), prog);
free (buf);
}
/* Execute ARGC/ARGV. Return the exit code in RETCODE. */
enum exec_result
wydawca_exec (int argc, const char **argv, int *retcode)
{
FILE *fp;
pid_t pid, npid;
int status;
diff --git a/src/gpg.c b/src/gpg.c
index 474d94b..d4f9b71 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -123,25 +123,25 @@ remove_homedir ()
logmsg (LOG_DEBUG, _("removing GNUPG home directory: %s"), temp_homedir);
if (rmdir_r (temp_homedir))
logmsg (LOG_CRIT, _("failed to remove GPG directory %s"), temp_homedir);
}
/* Create a temporary GPG home directory */
static int
create_gpg_homedir ()
{
if (temp_homedir)
return 0;
- temp_homedir = xstrdup ("/tmp/wydawca-XXXXXX");
+ temp_homedir = grecs_strdup ("/tmp/wydawca-XXXXXX");
if (!mkdtemp (temp_homedir))
{
logmsg (LOG_CRIT, _("cannot create GPG home directory (%s): %s"),
temp_homedir, strerror (errno));
return 1;
}
atexit (remove_homedir);
if (debug_level > 1)
logmsg (LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir);
setenv ("GNUPGHOME", temp_homedir, 1);
return 0;
}
@@ -228,25 +228,25 @@ verify_directive_signature (struct file_triplet *trp)
for (uptr = trp->uploader_list; uptr; uptr = uptr->next)
{
gpgme_import_result_t res;
gpgme_import_status_t pstat;
fail_if_err (gpgme_data_new_from_mem (&key_data,
uptr->gpg_key,
strlen (uptr->gpg_key),
0));
fail_if_err (gpgme_op_import (ctx, key_data));
res = gpgme_op_import_result (ctx);
pstat = res->imports;
- uptr->fpr = xstrdup (pstat->fpr);
+ uptr->fpr = grecs_strdup (pstat->fpr);
if (debug_level > 2)
logmsg (LOG_DEBUG, _("imported key: user = %s, fingerprint = %s"),
uptr->name, uptr->fpr);
}
fail_if_err (gpgme_data_new_from_file (&directive_data,
trp->file[file_directive].name, 1));
gpgme_data_new (&plain);
ec = gpgme_op_verify (ctx, directive_data, NULL, plain);
if (ec == GPG_ERR_NO_ERROR)
{
gpgme_verify_result_t result;
@@ -262,25 +262,26 @@ verify_directive_signature (struct file_triplet *trp)
rc = 0;
}
else
{
rc = 1;
UPDATE_STATS (STAT_BAD_SIGNATURE);
logmsg (LOG_ERR, _("%s: directive verification failed: %s"),
trp->name, gpgme_strerror (ec));
}
gpgme_data_release (directive_data);
gpgme_data_release (key_data);
-
+ gpgme_release (ctx);
+
return rc;
}
/* Verify the detached signature of TRP.
NOTE: It is assumed that the public key is already registered (by
a previous call to verify_directive_signature). */
int
verify_detached_signature (struct file_triplet *trp)
{
gpgme_engine_info_t info;
const char *argv[5];
const struct spool *spool;
diff --git a/src/job.c b/src/job.c
index 7e3fdf5..764e463 100644
--- a/src/job.c
+++ b/src/job.c
@@ -196,25 +196,25 @@ schedule_job (const struct spool *spool, uid_t uid)
struct job *job;
if (!spool)
spool = &fake_spool;
if (debug_level)
logmsg (LOG_DEBUG, _("scheduling job: %s, %lu"),
spool->tag, (unsigned long)uid);
job = job_locate (spool, uid);
if (!job)
{
- job = xzalloc (sizeof (*job));
+ job = grecs_zalloc (sizeof (*job));
job->spool = spool;
job->uid = uid;
job->pid = -1;
time (&job->timestamp);
job_insert (job, NULL);
}
job->state |= STATE_QUEUED;
job_start (job);
}
static void
diff --git a/src/lock.c b/src/lock.c
index 32367de..dece75d 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -178,33 +178,33 @@ host_name ()
static char *hostbuf = NULL;
size_t size = 0;
int rc;
if (hostbuf)
return hostbuf;
do
{
if (!hostbuf)
{
size = 256;
- hostbuf = xmalloc (size);
+ hostbuf = grecs_malloc (size);
}
else
{
size_t ns = size * 2;
if (size < ns)
- xalloc_die ();
+ grecs_alloc_die ();
size = ns;
- hostbuf = xrealloc (hostbuf, size);
+ hostbuf = grecs_realloc (hostbuf, size);
}
}
while ((rc = gethostname (hostbuf, size )) == -1 &&
(errno == EINVAL
#ifdef ENAMETOOLONG
|| errno == ENAMETOOLONG
#endif
));
if (rc)
{
logmsg (LOG_ERR, _("cannot get hostname: %s"), strerror (rc));
exit (EX_SOFTWARE);
@@ -252,45 +252,45 @@ wydawca_lock (const char *lockname)
}
void
wydawca_unlock (const char *lockfile)
{
if (enable_locking)
unlink (lockfile);
}
static char *
fix_tagname (const char *tag)
{
- char *tagname = xstrdup (tag);
+ char *tagname = grecs_strdup (tag);
char *p;
for (p = tagname; *p; p++)
if (!isalnum (*p) && *p != '_' && *p != '-')
*p = '_';
return tagname;
}
char *
wydawca_lockname (const char *tag)
{
char *lockname = NULL;
size_t size = 0;
char *tagname = fix_tagname (tag);
grecs_asprintf (&lockname, &size, "%s/LCK.%s", lockdir, tagname);
if (!lockname)
- xalloc_die ();
+ grecs_alloc_die ();
free (tagname);
return lockname;
}
void
wydawca_lock_init ()
{
if (enable_locking)
{
if