aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:21:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:33:34 +0300
commitde3fbe3e8d4dd2a89f7755906d76055784c437cc (patch)
tree65356dd7b5a9010499550c468e960c93515a7e15 /src
parentf569a6f2628b9ddef4dfb4424aff2dad644a8f19 (diff)
downloadwydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.gz
wydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.bz2
Drop gnulib.
* bootstrap: Rewrite. * bootstrap.conf: Remove. * configure.ac: Remove gl_EARLY/gl_INIT * src/backup.c: New file. * src/txtacc.c (txtacc_finish): Make sure a new entry is appended only once to the list. * (all sources): Use grecs memory allocation functions. * src/wydawca.h" Include fnmatch.h and regex.h (backup_type): New enum. (simple_backup_suffix): New extern. (find_backup_file_name): New proto. * tests/bkupname.c: New file. * tests/backup00.at: New file. * tests/backup01.at: New file. * tests/backup02.at: New file. * tests/backup03.at: New file. * tests/Makefile.am: Add new tests. * tests/testsuite.at: Add new tests. * grecs: Update.
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
@@ -16,6 +16,7 @@
sbin_PROGRAMS=wydawca
wydawca_SOURCES=\
+ backup.c\
builtin.c\
builtin.h\
cmdline.h\
@@ -60,8 +61,8 @@ SUFFIXES=.opt .c .h
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)\"\
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
@@ -16,8 +16,10 @@
#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)
@@ -220,9 +222,9 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
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);
diff --git a/src/config.c b/src/config.c
index df9816e..8250749 100644
--- a/src/config.c
+++ b/src/config.c
@@ -146,7 +146,7 @@ safe_file_name (char *file_name)
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);
@@ -549,8 +549,8 @@ cb_sql_host (enum grecs_callback_command cmd,
*p++ = 0;
if (p[0] == '/')
{
- pconn->socket = xstrdup (p);
- pconn->host = xstrdup ("localhost");
+ pconn->socket = grecs_strdup (p);
+ pconn->host = grecs_strdup ("localhost");
}
else
{
@@ -569,11 +569,11 @@ cb_sql_host (enum grecs_callback_command cmd,
}
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;
}
@@ -594,7 +594,7 @@ cb_sql (enum grecs_callback_command cmd,
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;
@@ -896,7 +896,7 @@ cb_notify_event (enum grecs_callback_command cmd,
switch (cmd) {
case grecs_callback_section_begin:
- ntf = xzalloc (sizeof (*ntf));
+ ntf = grecs_zalloc (sizeof (*ntf));
*pdata = ntf;
break;
@@ -984,7 +984,7 @@ cb_dictionary_params (enum grecs_callback_command cmd,
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++)
{
@@ -993,7 +993,7 @@ cb_dictionary_params (enum grecs_callback_command cmd,
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;
}
@@ -1159,8 +1159,8 @@ cb_spool (enum grecs_callback_command cmd,
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];
@@ -1277,8 +1277,8 @@ cb_supp_groups (enum grecs_callback_command cmd,
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++)
{
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -48,8 +48,7 @@ static struct dictionary_descr dictionary_tab[] = {
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;
@@ -92,6 +91,8 @@ 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);
@@ -186,7 +187,7 @@ 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;
@@ -206,7 +207,7 @@ dictionary_quote_string (struct dictionary *dict, void *handle,
if (!input)
{
- *poutput = xmalloc (1);
+ *poutput = grecs_malloc (1);
(*poutput)[0] = 0;
*psize = 1;
return 0;
@@ -216,7 +217,7 @@ dictionary_quote_string (struct dictionary *dict, void *handle,
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;
diff --git a/src/directive.c b/src/directive.c
index 08a14df..fadaedf 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -34,7 +34,7 @@ directive_parse (struct file_triplet *trp)
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++)
{
@@ -111,7 +111,7 @@ _directive_seq_get (int n, struct file_triplet *trp,
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;
@@ -380,7 +380,7 @@ stderr_redirector (const char *tag)
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);
@@ -493,7 +493,7 @@ run_check_script (const char *script, struct file_triplet *trp,
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)
diff --git a/src/diskio.c b/src/diskio.c
index 9addd9b..b175a45 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -46,7 +46,7 @@ concat_dir (const char *base, const char *name, size_t *pbaselen)
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);
@@ -171,7 +171,7 @@ copy_file (const char *file, const char *dst_file)
bufsize /= 2)
;
if (bufsize == 0)
- xalloc_die ();
+ grecs_alloc_die ();
rc = 0;
while (fsize > 0)
@@ -492,7 +492,7 @@ make_signame (const char *file_name)
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);
}
diff --git a/src/exec.c b/src/exec.c
index ed7ee1e..7ebf152 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -75,7 +75,7 @@ log_output (int prio, const char *prog, FILE *fp)
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);
diff --git a/src/gpg.c b/src/gpg.c
index 474d94b..d4f9b71 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -132,7 +132,7 @@ 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"),
@@ -237,7 +237,7 @@ verify_directive_signature (struct file_triplet *trp)
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);
@@ -271,7 +271,8 @@ verify_directive_signature (struct file_triplet *trp)
gpgme_data_release (directive_data);
gpgme_data_release (key_data);
-
+ gpgme_release (ctx);
+
return rc;
}
diff --git a/src/job.c b/src/job.c
index 7e3fdf5..764e463 100644
--- a/src/job.c
+++ b/src/job.c
@@ -205,7 +205,7 @@ schedule_job (const struct spool *spool, uid_t 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;
diff --git a/src/lock.c b/src/lock.c
index 32367de..dece75d 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -187,15 +187,15 @@ host_name ()
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 &&
@@ -261,7 +261,7 @@ wydawca_unlock (const char *lockfile)
static char *
fix_tagname (const char *tag)
{
- char *tagname = xstrdup (tag);
+ char *tagname = grecs_strdup (tag);
char *p;
for (p = tagname; *p; p++)
@@ -278,7 +278,7 @@ wydawca_lockname (const char *tag)
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;
}
@@ -289,7 +289,7 @@ wydawca_lock_init ()
if (enable_locking)
{
if (!lockdir)
- lockdir = xstrdup (LOCALSTATEDIR "/lock/" PACKAGE);
+ lockdir = grecs_strdup (LOCALSTATEDIR "/lock/" PACKAGE);
if (create_hierarchy (lockdir, 0))
exit (EX_OSFILE);
}
diff --git a/src/mail.c b/src/mail.c
index bac0381..6855ed7 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -291,7 +291,7 @@ mail_send_message (mu_address_t rcpt, const char *text,
if (rcpt)
{
mu_address_to_string (rcpt, NULL, 0, &size);
- buf = xmalloc (size + 1);
+ buf = grecs_malloc (size + 1);
mu_address_to_string (rcpt, buf, size + 1, NULL);
mu_header_set_value (hdr, "To", buf, 1);
@@ -300,7 +300,7 @@ mail_send_message (mu_address_t rcpt, const char *text,
if (from_address && mu_header_sget_value (hdr, "From", &sval))
{
mu_address_to_string (from_address, NULL, 0, &size);
- buf = xmalloc (size + 1);
+ buf = grecs_malloc (size + 1);
mu_address_to_string (from_address, buf, size + 1, NULL);
mu_header_set_value (hdr, "From", buf, 1);
free (buf);
@@ -434,7 +434,7 @@ mail_stats ()
size_t size;
char *buf;
mu_address_to_string (admin_address, NULL, 0, &size);
- buf = xmalloc (size + 1);
+ buf = grecs_malloc (size + 1);
mu_address_to_string (admin_address, buf, size + 1, NULL);
logmsg (LOG_DEBUG, _("sending stats to %s"), buf);
free (buf);
@@ -444,7 +444,7 @@ mail_stats ()
exp = make_stat_expansion (tc + 1);
time (&t);
exp[0].kw = "date";
- exp[0].value = exp[0].storage = xstrdup (ctime (&t));
+ exp[0].value = exp[0].storage = grecs_strdup (ctime (&t));
exp[0].value [strlen (exp[0].value) - 1] = 0;
timer_fill_meta (exp + 1, tc);
@@ -598,7 +598,7 @@ do_notify (struct file_triplet *trp, enum notification_event ev,
size_t size;
char *buf;
mu_address_to_string (rcpt, NULL, 0, &size);
- buf = xmalloc (size + 1);
+ buf = grecs_malloc (size + 1);
mu_address_to_string (rcpt, buf, size + 1, NULL);
logmsg (LOG_DEBUG, _("notifying %s (project %s) about %s"),
buf, trp->project, notification_event_str (ev));
@@ -642,7 +642,7 @@ expand_email_admin (struct metadef *def, void *data)
if (mu_address_to_string (admin_address, NULL, 0, &size) == 0)
{
size++;
- def->storage = xmalloc (size);
+ def->storage = grecs_malloc (size);
mu_address_to_string (admin_address, def->storage, size, NULL);
def->value = def->storage;
}
@@ -670,7 +670,7 @@ expand_email_owner (struct metadef *def, void *data)
else if (mu_address_to_string (addr, NULL, 0, &size) == 0)
{
size++;
- def->storage = xmalloc (size);
+ def->storage = grecs_malloc (size);
mu_address_to_string (addr, def->storage, size, NULL);
def->value = def->storage;
mu_address_destroy (&addr);
diff --git a/src/net.c b/src/net.c
index 3e9fe30..d08a6ba 100644
--- a/src/net.c
+++ b/src/net.c
@@ -103,7 +103,7 @@ handle_connection (FILE *in, FILE *out)
char *p;
struct passwd *pw;
- if (getline (&buf, &buflen, in) <= 0)
+ if (grecs_getline (&buf, &buflen, in) <= 0)
return;
trim_crlf (buf);
if (debug_level)
@@ -125,7 +125,7 @@ handle_connection (FILE *in, FILE *out)
else
fprintf (out, "+ OK, spool %s\r\n", spool->tag);
- if (getline (&buf, &buflen, in) < 0)
+ if (grecs_getline (&buf, &buflen, in) < 0)
{
logmsg (LOG_ERR, "protocol error");
free (buf);
diff --git a/src/process.c b/src/process.c
index e41709d..200d987 100644
--- a/src/process.c
+++ b/src/process.c
@@ -27,7 +27,7 @@ static struct spool_list *spool_list;
void
register_spool (struct spool *spool)
{
- struct spool_list *sp = xmalloc (sizeof *sp);
+ struct spool_list *sp = grecs_malloc (sizeof *sp);
sp->spool = *spool;
sp->next = spool_list;
spool_list = sp;
@@ -113,7 +113,7 @@ parse_file_name (const char *name, struct file_info *finfo)
&& memcmp (name + len - suftab[i].len,
suftab[i].suf, suftab[i].len) == 0)
{
- finfo->name = xstrdup (name);
+ finfo->name = grecs_strdup (name);
finfo->type = suftab[i].type;
finfo->root_len = len - suftab[i].len;
return;
diff --git a/src/sql.c b/src/sql.c
index a4b311e..80eb344 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -30,7 +30,7 @@ static struct sql_list *sql_list;
void
sql_register_conn (struct sqlconn *conn)
{
- struct sql_list *ent = xmalloc (sizeof *ent);
+ struct sql_list *ent = grecs_malloc (sizeof *ent);
ent->conn = *conn;
ent->next = sql_list;
sql_list = ent;
@@ -198,7 +198,7 @@ sql_quote (struct dictionary *dict, void *handle, const char *input,
len = strlen (input);
size = 2 * len + 1;
- output = xmalloc (size);
+ output = grecs_malloc (size);
mysql_real_escape_string (&conn->mysql, output, input, len);
*poutput = output;
if (psize)
diff --git a/src/timer.c b/src/timer.c
index 1634462..cece63a 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -20,7 +20,6 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
-#include <xalloc.h>
struct timer_slot
{
@@ -182,7 +181,7 @@ timer_format_time (double t)
grecs_asprintf (&str, &size, "%02ld:%02ld", m, s);
}
if (!str)
- xalloc_die ();
+ grecs_alloc_die ();
return str;
}
@@ -210,7 +209,7 @@ _fill_meta (void *sym, void *data)
size_t size = 0; \
grecs_asprintf (&buf, &size, "timer:%s:%s", slot->name, #arg); \
if (!buf) \
- xalloc_die (); \
+ grecs_alloc_die (); \
tp->def->kw = buf; \
tp->def->storage = timer_format_time (__cat2__(timer_get_,arg) (slot)); \
tp->def->value = tp->def->storage; \
diff --git a/src/triplet.c b/src/triplet.c
index 3083c64..9dfdf2c 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -60,6 +60,7 @@ hash_triplet_free (void *data)
for (up = tp->uploader_list; up; )
{
struct uploader_info *next = up->next;
+ free (up->fpr);
free (up);
up = next;
}
@@ -94,7 +95,7 @@ register_file (struct file_info *finfo, const struct spool *spool)
grecs_alloc_die ();
}
- key.name = xmalloc (finfo->root_len + 1);
+ key.name = grecs_malloc (finfo->root_len + 1);
memcpy (key.name, finfo->name, finfo->root_len);
key.name[finfo->root_len] = 0;
@@ -378,7 +379,7 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret)
/* Size */
if (grecs_asprintf (&sptr, &slen, "%lu", (unsigned long) info->sb.st_size))
- xalloc_die ();
+ grecs_alloc_die ();
/* Figure out padding and format the buffer */
slen = strlen (sptr);
@@ -391,7 +392,7 @@ format_file_data (struct file_triplet *trp, enum file_type type, char **pret)
modes, user_name, group_name, ugswidth - pad + slen,
sptr,
timebuf, info->name))
- xalloc_die ();
+ grecs_alloc_die ();
free (sptr);
*pret = buf;
return 0;
@@ -411,7 +412,7 @@ expand_triplet_ls_full (struct metadef *def, void *data)
if (format_file_data (trp, file_directive, &buf[file_directive]) == 0)
size += strlen (buf[file_directive]) + 1;
- def->value = def->storage = xmalloc (size + 1);
+ def->value = def->storage = grecs_malloc (size + 1);
def->value[0] = 0;
if (buf[file_dist])
{
@@ -446,7 +447,7 @@ expand_triplet_ls_upload (struct metadef *def, void *data)
if (format_file_data (trp, file_signature, &buf[file_signature]) == 0)
size += strlen (buf[file_signature]) + 1;
- def->value = def->storage = xmalloc (size + 1);
+ def->value = def->storage = grecs_malloc (size + 1);
def->value[0] = 0;
if (buf[file_dist])
{
@@ -552,7 +553,7 @@ expand_email_user (struct metadef *def, void *data)
size_t size = 0;
if (grecs_asprintf (&def->storage, &size, "\"%s\" <%s>",
trp->uploader->realname, trp->uploader->email))
- xalloc_die ();
+ grecs_alloc_die ();
def->value = def->storage;
}
return def->value;
@@ -594,7 +595,7 @@ expand_check_result (struct metadef *def, void *data)
def->storage = NULL;
if (grecs_asprintf (&def->storage, &size,
"%d", WEXITSTATUS (status)))
- xalloc_die ();
+ grecs_alloc_die ();
}
else if (WIFSIGNALED (status))
{
@@ -602,7 +603,7 @@ expand_check_result (struct metadef *def, void *data)
def->storage = NULL;
if (grecs_asprintf (&def->storage, &size, "SIG+%d",
WTERMSIG (status)))
- xalloc_die ();
+ grecs_alloc_die ();
}
else
return def->value = "[unrecognized return code]";
diff --git a/src/txtacc.c b/src/txtacc.c
index 91659f6..442e27e 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -34,8 +34,8 @@ struct txtacc
static struct txtacc_entry *
txtacc_alloc_entry (struct grecs_list *list, size_t size)
{
- struct txtacc_entry *p = xmalloc (sizeof (*p));
- p->buf = xmalloc (size);
+ struct txtacc_entry *p = grecs_malloc (sizeof (*p));
+ p->buf = grecs_malloc (size);
p->size = size;
p->len = 0;
grecs_list_append (list, p);
@@ -89,7 +89,7 @@ txtacc_entry_free (void *p)
struct txtacc *
txtacc_create ()
{
- struct txtacc *acc = xmalloc (sizeof (*acc));
+ struct txtacc *acc = grecs_malloc (sizeof (*acc));
acc->cur = grecs_list_create ();
acc->cur->free_entry = txtacc_entry_free;
acc->mem = grecs_list_create ();
@@ -137,6 +137,7 @@ txtacc_finish (struct txtacc *acc, int steal)
txtent = acc->cur->head->data;
acc->cur->head->data = NULL;
txtacc_entry_tailor (txtent);
+ grecs_list_append (acc->mem, txtent);
break;
default:
@@ -158,9 +159,10 @@ txtacc_finish (struct txtacc *acc, int steal)
grecs_list_clear (acc->cur);
p = txtent->buf;
if (steal)
- free (txtent);
- else
- grecs_list_append (acc->mem, txtent);
+ {
+ grecs_list_remove_tail (acc->mem);
+ free (txtent);
+ }
return p;
}
@@ -173,7 +175,7 @@ txtacc_free_string (struct txtacc *acc, char *str)
struct txtacc_entry *tp = ep->data;
if (tp->buf == str)
{
- grecs_list_remove_entry(acc->mem, ep);
+ grecs_list_remove_entry (acc->mem, ep);
free (tp->buf);
return;
}
diff --git a/src/verify.c b/src/verify.c
index a49983c..c8fef11 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -113,7 +113,7 @@ fill_project_name (struct file_triplet *trp)
return 1;
}
- blurb = xmalloc (size + 1);
+ blurb = grecs_malloc (size + 1);
rc = fread (blurb, size, 1, fp);
fclose (fp);
@@ -182,7 +182,7 @@ fill_project_name (struct file_triplet *trp)
struct uploader_info *
new_uploader_info (struct uploader_info *src)
{
- struct uploader_info *p = xmalloc (sizeof (*p));
+ struct uploader_info *p = grecs_malloc (sizeof (*p));
p->next = NULL;
p->name = src->name;
p->realname = src->realname;
diff --git a/src/wydawca.c b/src/wydawca.c
index cc1815b..36aa8b7 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -71,7 +71,7 @@ syslog_printer (int prio, const char *fmt, va_list ap)
if (size > fmtsize)
{
fmtsize = size;
- fmtbuf = x2realloc (fmtbuf, &fmtsize);
+ fmtbuf = grecs_realloc (fmtbuf, fmtsize);
}
sprintf (fmtbuf, "[%s] %s", p, fmt);
fmt = fmtbuf;
@@ -179,7 +179,7 @@ stat_expand (struct metadef *def, void *data)
def->storage = NULL;
if (grecs_asprintf (&def->storage, &size, "%u",
wydawca_stat[(int) def->data]))
- xalloc_die ();
+ grecs_alloc_die ();
def->value = def->storage;
return def->value;
}
@@ -189,7 +189,7 @@ make_stat_expansion (size_t count)
{
int i;
struct metadef *def, *p;
- def = xcalloc (MAX_STAT + count + 1, sizeof (def[0]));
+ def = grecs_calloc (MAX_STAT + count + 1, sizeof (def[0]));
p = def + count;
for (i = 0; i < MAX_STAT; i++, p++)
{
@@ -252,7 +252,7 @@ collect_uids (int argc, char **argv)
int i;