diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/backup.c | 165 | ||||
-rw-r--r-- | src/builtin.c | 10 | ||||
-rw-r--r-- | src/config.c | 26 | ||||
-rw-r--r-- | src/dictionary.c | 11 | ||||
-rw-r--r-- | src/directive.c | 8 | ||||
-rw-r--r-- | src/diskio.c | 6 | ||||
-rw-r--r-- | src/exec.c | 2 | ||||
-rw-r--r-- | src/gpg.c | 7 | ||||
-rw-r--r-- | src/job.c | 2 | ||||
-rw-r--r-- | src/lock.c | 12 | ||||
-rw-r--r-- | src/mail.c | 14 | ||||
-rw-r--r-- | src/net.c | 4 | ||||
-rw-r--r-- | src/process.c | 4 | ||||
-rw-r--r-- | src/sql.c | 4 | ||||
-rw-r--r-- | src/timer.c | 5 | ||||
-rw-r--r-- | src/triplet.c | 17 | ||||
-rw-r--r-- | src/txtacc.c | 16 | ||||
-rw-r--r-- | src/verify.c | 4 | ||||
-rw-r--r-- | src/wydawca.c | 8 | ||||
-rw-r--r-- | src/wydawca.h | 20 |
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 @@ # # 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\ @@ -57,14 +58,14 @@ 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 @@ -13,14 +13,16 @@ 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; } @@ -217,15 +219,15 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req) } 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; 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) } /* 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; } @@ -546,14 +546,14 @@ cb_sql_host (enum grecs_callback_command cmd, 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) @@ -566,17 +566,17 @@ cb_sql_host (enum grecs_callback_command cmd, 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, @@ -591,13 +591,13 @@ cb_sql (enum grecs_callback_command 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; @@ -893,13 +893,13 @@ cb_notify_event (enum grecs_callback_command cmd, { 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) @@ -981,22 +981,22 @@ cb_dictionary_params (enum grecs_callback_command cmd, 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; } @@ -1156,14 +1156,14 @@ cb_spool (enum grecs_callback_command 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; @@ -1274,14 +1274,14 @@ cb_supp_groups (enum grecs_callback_command cmd, 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; 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[] = { { "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 @@ -89,12 +88,14 @@ dictionary_open (struct dictionary *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 @@ -183,13 +184,13 @@ dictionary_result (struct dictionary *dict, void *handle, 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 @@ -203,23 +204,23 @@ dictionary_quote_string (struct dictionary *dict, void *handle, 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, "e); - 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; 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) 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) @@ -108,13 +108,13 @@ _directive_seq_get (int n, struct file_triplet *trp, 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++) ; @@ -377,13 +377,13 @@ stderr_redirector (const char *tag) 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); } @@ -490,13 +490,13 @@ run_check_script (const char *script, struct file_triplet *trp, 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; 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) 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; @@ -168,13 +168,13 @@ copy_file (const char *file, const char *dst_file) 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; @@ -489,13 +489,13 @@ 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; } @@ -72,13 +72,13 @@ 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. */ @@ -129,13 +129,13 @@ remove_homedir () 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; } @@ -234,13 +234,13 @@ verify_directive_signature (struct file_triplet *trp) 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, @@ -268,13 +268,14 @@ verify_directive_signature (struct file_triplet *trp) 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). */ @@ -202,13 +202,13 @@ schedule_job (const struct spool *spool, uid_t uid) 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); } @@ -184,21 +184,21 @@ host_name () 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 @@ -258,13 +258,13 @@ wydawca_unlock (const char *lockfile) 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; @@ -275,22 +275,22 @@ 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 (!lockdir) - lockdir = xstrdup (LOCALSTATEDIR "/lock/" PACKAGE); + lockdir = grecs_strdup (LOCALSTATEDIR "/lock/" PACKAGE); if (create_hierarchy (lockdir, 0)) exit (EX_OSFILE); } } @@ -288,22 +288,22 @@ mail_send_message (mu_address_t rcpt, const char *text, mu_message_get_header (msg, &hdr); mu_header_append (hdr, "X-Mailer", x_mailer); 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); free (buf); 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); } } @@ -431,23 +431,23 @@ mail_stats () if (debug_level) { 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); } tc = timer_get_count () * 3; 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); tmpl = resolve_message_template (admin_stat_message); if (!tmpl) { @@ -595,13 +595,13 @@ do_notify (struct file_triplet *trp, enum notification_event ev, { if (rcpt) { 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)); free (buf); } else @@ -639,13 +639,13 @@ const char * expand_email_admin (struct metadef *def, void *data) { size_t size; 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; } else def->value = ""; return def->value; @@ -667,13 +667,13 @@ expand_email_owner (struct metadef *def, void *data) trp->project, gettext (errp)); def->value = ""; } 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); } else def->value = ""; @@ -100,13 +100,13 @@ handle_connection (FILE *in, FILE *out) char *buf = NULL; size_t buflen = 0; const struct spool *spool; 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) logmsg (LOG_DEBUG, "recv: %s", buf); spool = wydawca_find_spool (buf); if (!spool) @@ -122,13 +122,13 @@ handle_connection (FILE *in, FILE *out) } else if (spool->url) fprintf (out, "+ OK, URL %s\r\n", spool->url); 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); return; } 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 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; } static int @@ -110,13 +110,13 @@ parse_file_name (const char *name, struct file_info *finfo) for (i = 0; i < sizeof suftab / sizeof suftab[0]; i++) { if (len >= suftab[i].len && 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; } } abort (); /* should not happen */ @@ -27,13 +27,13 @@ struct sql_list static struct sql_list *sql_list; /* Append CONN to the end of 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; } /* Find a configured connection that has the given IDENT */ @@ -195,13 +195,13 @@ sql_quote (struct dictionary *dict, void *handle, const char *input, struct sqlconn *conn = handle; size_t len, size; char *output; 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) *psize = strlen (output); return 0; } 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 @@ #include <wydawca.h> #include <sys/time.h> #include <sys/resource.h> #include <unistd.h> #include <string.h> #include <ctype.h> -#include <xalloc.h> struct timer_slot { char *name; double real; double self_user; /* user time in sec */ @@ -179,13 +178,13 @@ timer_format_time (double t) else if (h) grecs_asprintf (&str, &size, "%02ld:%02ld:%02ld", h, m, s); else grecs_asprintf (&str, &size, "%02ld:%02ld", m, s); } if (!str) - xalloc_die (); + grecs_alloc_die (); return str; } size_t timer_get_count () { @@ -207,13 +206,13 @@ _fill_meta (void *sym, void *data) if (tp->num) \ { \ char *buf = NULL; \ 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; \ tp->def->expand = NULL; \ tp->def++; \ 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) txtacc_free (tp->acc); /* Free uploader list */ for (up = tp->uploader_list; up; ) { struct uploader_info *next = up->next; + free (up->fpr); free (up); up = next; } free (tp); } @@ -91,13 +92,13 @@ register_file (struct file_info *finfo, const struct spool *spool) NULL, hash_triplet_free); if (!triplet_table) grecs_alloc_die (); } |