diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-08 15:31:17 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-08 16:17:35 +0200 |
commit | 489432d354d88049afe4af54c29965d382d67f7a (patch) | |
tree | 84725496a92564824f75f0a2edd5a595411ffab2 | |
parent | 3325fed2895f079486b88c65409c73153fec306f (diff) | |
download | pies-489432d354d88049afe4af54c29965d382d67f7a.tar.gz pies-489432d354d88049afe4af54c29965d382d67f7a.tar.bz2 |
Uniformly use grecs memory management functions.
* gnulib.modules: Remove unneded modules.
* ident/ident.h: Remove xalloc.h, include errno.h
* ident/ident.c: Use standard allocation functions instead of x*
* ident/pam.c: Remove.
* ident/provider.c: Remove.
* ident/system.c: Remove.
* src/meta.c: Remove.
* src/Makefile.am: Remove meta.c
* src/progman.c: Use grecs_* allocation functions instead of x*.
(notify): Use wordsplit to expand variables within message.
Rename variables: program-name to program_name;
canonical-program-name to canonical_program_name.
* doc/pies.texi: Update.
* src/depmap.c: Use grecs_* allocation functions instead of x*.
(depmap_end): New function.
* src/diag.c (logmsg_vprintf): Use grecs_txtacc instead of obstack.
* src/pies.h (depmap_end): New proto.
Remove unused includes.
* src/acl.c: Use grecs_* allocation functions instead of x*.
* src/ctl.c: Likewise.
* src/inetd.c: Likewise.
* src/limits.c: Likewise.
* src/meta1gram.y: Likewise.
* src/meta1lex.l: Likewise.
* src/pies.c: Likewise.
* src/socket.c: Likewise.
* src/sysvinit.c: Likewise.
* src/userprivs.c: Likewise.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | doc/pies.texi | 10 | ||||
-rw-r--r-- | gnulib.modules | 3 | ||||
-rw-r--r-- | ident/ident.c | 20 | ||||
-rw-r--r-- | ident/ident.h | 4 | ||||
-rw-r--r-- | ident/pam.c | 4 | ||||
-rw-r--r-- | ident/provider.c | 12 | ||||
-rw-r--r-- | ident/system.c | 6 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/acl.c | 22 | ||||
-rw-r--r-- | src/ctl.c | 48 | ||||
-rw-r--r-- | src/depmap.c | 14 | ||||
-rw-r--r-- | src/diag.c | 48 | ||||
-rw-r--r-- | src/inetd.c | 44 | ||||
-rw-r--r-- | src/limits.c | 4 | ||||
-rw-r--r-- | src/meta.c | 127 | ||||
-rw-r--r-- | src/meta1gram.y | 20 | ||||
-rw-r--r-- | src/meta1lex.l | 24 | ||||
-rw-r--r-- | src/pies.c | 28 | ||||
-rw-r--r-- | src/pies.h | 21 | ||||
-rw-r--r-- | src/progman.c | 218 | ||||
-rw-r--r-- | src/socket.c | 4 | ||||
-rw-r--r-- | src/sysvinit.c | 60 | ||||
-rw-r--r-- | src/userprivs.c | 12 |
24 files changed, 360 insertions, 395 deletions
@@ -1 +1,2 @@ +/ABOUT-NLS /ABOUT-NLS~ diff --git a/doc/pies.texi b/doc/pies.texi index 46e1b91..7ad5008 100644 --- a/doc/pies.texi +++ b/doc/pies.texi @@ -1683,4 +1683,4 @@ The table below lists all available variables and their expansions: @headitem Variable @tab Expansion -@item canonical-program-name @tab @samp{pies} -@item program-name @tab Program name of the @command{pies} binary. +@item canonical_program_name @tab @samp{pies} +@item program_name @tab Program name of the @command{pies} binary. @item package @tab Package name (@samp{Pies}). @@ -1714,3 +1714,3 @@ message is used instead: From: <> -X-Agent: $@{canonical-program-name@} ($@{package@} $@{version@}) +X-Agent: $@{canonical_program_name@} ($@{package@} $@{version@}) Subject: Component $@{component@} $@{termination@} $@{retcode@}. @@ -2301,3 +2301,3 @@ return-code (EX_USAGE, EX_CONFIG) @{ From: Pies <> - X-Agent: $@{canonical-program-name@} ($@{package@} $@{version@}) + X-Agent: $@{canonical_program_name@} ($@{package@} $@{version@}) Subject: Component $@{component@} disabled. @@ -2309,3 +2309,3 @@ return-code (EX_USAGE, EX_CONFIG) @{ - To restart, run ``$@{program-name@} -R $@{component@}'' + To restart, run ``$@{program_name@} -R $@{component@}'' --- diff --git a/gnulib.modules b/gnulib.modules index 2612e75..9e9d255 100644 --- a/gnulib.modules +++ b/gnulib.modules @@ -11,3 +11,2 @@ inttostr inttypes -obstack progname @@ -15,3 +14 @@ quotearg sysexits -xalloc -xvasprintf diff --git a/ident/ident.c b/ident/ident.c index dbf3f9b..75d51fa 100644 --- a/ident/ident.c +++ b/ident/ident.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2015 Sergey Poznyakoff + Copyright (C) 2015-2016 Sergey Poznyakoff @@ -21,6 +21,16 @@ pies_identity_create (char const *user) { - pies_identity_t id = xmalloc (sizeof (*id)); - id->provider = NULL; - id->username = xstrdup (user); - id->data = NULL; + pies_identity_t id = malloc (sizeof (*id)); + if (id) + { + id->provider = NULL; + id->data = NULL; + id->username = strdup (user); + if (!id) + { + int ec = errno; + free (id); + errno = ec; + id = NULL; + } + } return id; diff --git a/ident/ident.h b/ident/ident.h index 313926c..c262f58 100644 --- a/ident/ident.h +++ b/ident/ident.h @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2015 Sergey Poznyakoff + Copyright (C) 2015-2016 Sergey Poznyakoff @@ -17,3 +17,3 @@ #include <config.h> -#include "xalloc.h" +#include <errno.h> #include "libpies.h" diff --git a/ident/pam.c b/ident/pam.c index 7302242..96ac02c 100644 --- a/ident/pam.c +++ b/ident/pam.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2015 Sergey Poznyakoff + Copyright (C) 2015-2016 Sergey Poznyakoff @@ -185,3 +185,3 @@ configure (struct grecs_node *node, pies_identity_provider_t provider) int i; - struct pam_identity_provider_data *data = xcalloc (1, sizeof (*data)); + struct pam_identity_provider_data *data = grecs_calloc (1, sizeof (*data)); provider->data = data; diff --git a/ident/provider.c b/ident/provider.c index dd7fc3d..8b9f076 100644 --- a/ident/provider.c +++ b/ident/provider.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2015 Sergey Poznyakoff + Copyright (C) 2015-2016 Sergey Poznyakoff @@ -29,3 +29,3 @@ idmech_copy (void *a, void *b) *ma = *mb; - ma->name = xstrdup (mb->name); + ma->name = grecs_strdup (mb->name); return 0; @@ -40,3 +40,3 @@ pies_identity_mechanism_register (pies_identity_mechanism_t mech) { - idmech_symtab = grecs_symtab_create (sizeof(*mech), + idmech_symtab = grecs_symtab_create (sizeof (*mech), NULL, @@ -47,3 +47,3 @@ pies_identity_mechanism_register (pies_identity_mechanism_t mech) if (!idmech_symtab) - grecs_alloc_die(); + grecs_alloc_die (); } @@ -137,4 +137,4 @@ pies_config_provider (struct grecs_node *node) - prov = xcalloc (1, sizeof (*prov)); - prov->name = xstrdup (name); + prov = grecs_calloc (1, sizeof (*prov)); + prov->name = grecs_strdup (name); prov->mech = mp; diff --git a/ident/system.c b/ident/system.c index dcfe7a2..086eb85 100644 --- a/ident/system.c +++ b/ident/system.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2015 Sergey Poznyakoff + Copyright (C) 2015-2016 Sergey Poznyakoff @@ -62,3 +62,5 @@ system_authenticate (pies_identity_provider_t pr, pies_identity_t id, { - struct system_identity_data *data = xmalloc (sizeof (*data)); + struct system_identity_data *data = malloc (sizeof (*data)); + if (!data) + return -1; data->gid = pwd->pw_gid; diff --git a/src/Makefile.am b/src/Makefile.am index 01149c6..a2400fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,3 +27,2 @@ pies_SOURCES = \ limits.c\ - meta.c\ meta1gram.y\ @@ -1,3 +1,3 @@ /* This file is part of GNU Pies - Copyright (C) 2009-2013 Sergey Poznyakoff + Copyright (C) 2009-2016 Sergey Poznyakoff @@ -113,4 +113,4 @@ pies_acl_create (const char *name, grecs_locus_t *locus) { - pies_acl_t acl = xmalloc (sizeof (acl[0])); - acl->name = name ? xstrdup (name) : NULL; + pies_acl_t acl = grecs_malloc (sizeof (acl[0])); + acl->name = name ? grecs_strdup (name) : NULL; grecs_locus_copy (&acl->locus, locus); @@ -133,3 +133,3 @@ create_acl_sockaddr (int family, int len) { - struct pies_sockaddr *p = xzalloc (sizeof (*p)); + struct pies_sockaddr *p = grecs_zalloc (sizeof (*p)); p->salen = len; @@ -371,4 +371,4 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv) { - entry->names = xcalloc (2, sizeof (entry->names[0])); - entry->names[0] = xstrdup (argv[0]->v.string); + entry->names = grecs_calloc (2, sizeof (entry->names[0])); + entry->names[0] = grecs_strdup (argv[0]->v.string); entry->names[1] = NULL; @@ -379,6 +379,6 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv) struct grecs_list_entry *ep; - entry->names = xcalloc (argv[0]->v.list->count + 1, - sizeof (entry->names[0])); + entry->names = grecs_calloc (argv[0]->v.list->count + 1, + sizeof (entry->names[0])); for (i = 0, ep = argv[0]->v.list->head; ep; ep = ep->next, ++i) - entry->names[i] = xstrdup (ep->data); + entry->names[i] = grecs_strdup (ep->data); entry->names[i] = NULL; @@ -406,3 +406,3 @@ parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl, { - struct acl_entry *entry = xzalloc (sizeof (*entry)); + struct acl_entry *entry = grecs_zalloc (sizeof (*entry)); @@ -744,3 +744,3 @@ pies_acl_install (pies_acl_t acl) if (!acl_table) - xalloc_die (); + grecs_alloc_die (); } @@ -18,3 +18,2 @@ #include "prog.h" -#include "xvasprintf.h" #include "identity.h" @@ -57,3 +56,4 @@ ctlbuf_alloc (struct ctlbuf *buf, size_t s) { - while (buf->level + s >= buf->size) + size_t minsize = buf->level + s; + while (minsize >= buf->size) { @@ -61,3 +61,5 @@ ctlbuf_alloc (struct ctlbuf *buf, size_t s) buf->size = CTLBUFSIZE; - buf->base = x2realloc (buf->base, &buf->size); + else + buf->size *= CTLBUFSIZE; + buf->base = grecs_realloc (buf->base, buf->size); } @@ -417,3 +419,4 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...) va_list ap; - + size_t len = 0; + key.name = (char *) name; @@ -430,3 +433,4 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...) va_start (ap, fmt); - ret->value = xvasprintf (fmt, ap); + ret->value = NULL; + grecs_vasprintf (&ret->value, &len, fmt, ap); va_end (ap); @@ -446,9 +450,10 @@ json_object_set_string (struct json_value *obj, va_list ap; - char *s; + char *s = NULL; + size_t l = 0; va_start (ap, fmt); - s = xvasprintf (fmt, ap); + grecs_vasprintf (&s, &l, fmt, ap); va_end (ap); json_object_set (obj, name, json_new_string (s)); - free (s); + grecs_free (s); } @@ -488,3 +493,3 @@ ctlio_create (void) - io = xmalloc (sizeof (*io)); + io = grecs_malloc (sizeof (*io)); input_init (&io->input); @@ -583,6 +588,7 @@ ctlio_reply (struct ctlio *io, int code, const char *fmt, ...) va_list ap; - char *str; - + char *str = NULL; + size_t len = 0; + va_start (ap, fmt); - str = xvasprintf (fmt, ap); + grecs_vasprintf (&str, &len, fmt, ap); va_end (ap); @@ -590,3 +596,3 @@ ctlio_reply (struct ctlio *io, int code, const char *fmt, ...) io->output.reply = json_error_reply_create (str); - free (str); + grecs_free (str); } @@ -606,6 +612,7 @@ ctlio_printf (struct ctlio *io, const char *fmt, ...) va_list ap; - char *str; + char *str = NULL; + size_t len = 0; va_start (ap, fmt); - str = xvasprintf (fmt, ap); + grecs_vasprintf (&str, &len, fmt, ap); va_end (ap); @@ -735,2 +742,9 @@ do_auth (struct ctlio *io, char const *name, char const *pass) int new_state = CTL_INITIAL_STATE; + + if (!id) + { + logmsg (LOG_AUTH, _("%s: can't authenticate: %s"), + name, strerror (errno)); + return -1; + } @@ -817,3 +831,3 @@ ctlio_authenticate (struct ctlio *io) - user = xmalloc (s + 1); + user = grecs_malloc (s + 1); memcpy (user, data, s); @@ -821,3 +835,3 @@ ctlio_authenticate (struct ctlio *io) - passwd = xmalloc (datalen - s); + passwd = grecs_malloc (datalen - s); memcpy (passwd, p + 1, datalen - s - 1); diff --git a/src/depmap.c b/src/depmap.c index ac02fdc..e4533e8 100644 --- a/src/depmap.c +++ b/src/depmap.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2008-2013 Sergey Poznyakoff + Copyright (C) 2008-2013, 2016 Sergey Poznyakoff @@ -92,4 +92,4 @@ depmap_alloc (size_t count) size_t size = (count + BITS_PER_WORD - 1) / BITS_PER_WORD; - pies_depmap_t dmap = xzalloc (sizeof (*dmap) - 1 - + count * size * sizeof (unsigned)); + pies_depmap_t dmap = grecs_zalloc (sizeof (*dmap) - 1 + + count * size * sizeof (unsigned)); dmap->nrows = count; @@ -155,3 +155,3 @@ depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, { - pies_depmap_pos_t pos = xmalloc (sizeof *pos); + pies_depmap_pos_t pos = grecs_malloc (sizeof *pos); *ppos = pos; @@ -162 +162,7 @@ depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, } + +void +depmap_end (pies_depmap_pos_t pos) +{ + grecs_free (pos); +} @@ -17,3 +17,2 @@ #include "pies.h" -#include "xvasprintf.h" @@ -105,4 +104,2 @@ debug_msg (const char *fmt, ...) -static struct obstack log_stk; -static int log_stk_init; @@ -111,29 +108,34 @@ logmsg_vprintf (int prio, const char *fmt, va_list ap) { - char *str, *p; - - str = xvasprintf (fmt, ap); + char *p, *t, *str; + static char *buf = NULL; + static size_t len = 0; + static struct grecs_txtacc *log_acc; - if (!log_stk_init) + if (grecs_vasprintf (&buf, &len, fmt, ap)) { - obstack_init (&log_stk); - log_stk_init = 1; + logmsg (LOG_CRIT, _("out of memory trying to log a message")); + return; } - for (p = str; *p; ) + if (!log_acc) + log_acc = grecs_txtacc_create (); + + str = buf; + + while (str) { - size_t len = strcspn (p, "\n"); - if (len) - obstack_grow (&log_stk, p, len); - p += len; - if (*p) + p = strchr (str, '\n'); + if (p) { - char *msg; - - obstack_1grow (&log_stk, 0); - msg = obstack_finish (&log_stk); - logmsg (prio, "%s", msg); - obstack_free (&log_stk, msg); - p++; + *p++ = 0; + if (!*p) + p = NULL; + grecs_txtacc_grow_char (log_acc, 0); + t = grecs_txtacc_finish (log_acc, 0); + logmsg (prio, "%s", t); + grecs_txtacc_free_string (log_acc, t); } + else + grecs_txtacc_grow_string (log_acc, str); + str = p; } - free (str); } diff --git a/src/inetd.c b/src/inetd.c index 4a55ad5..3eb4470 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -66,3 +66,3 @@ mktag (const char *address, const char *service) { - str = xmalloc (strlen (address) + 1 + strlen (service) + 1); + str = grecs_malloc (strlen (address) + 1 + strlen (service) + 1); strcpy (str, address); @@ -72,3 +72,3 @@ mktag (const char *address, const char *service) else - str = xstrdup (service); + str = grecs_strdup (service); return str; @@ -139,3 +139,3 @@ inetd_conf_file (const char *file) { - dfl_address = xmalloc (len); + dfl_address = grecs_malloc (len); memcpy (dfl_address, ws.ws_wordv[IFLD_SERVICE], len-1); @@ -195,8 +195,15 @@ inetd_conf_file (const char *file) { + char *s = NULL; + size_t l = 0; + int rc; + /* Create URL from protocol and service fields. */ - str = xasprintf ("inet+%s://%s:%s", - ws.ws_wordv[IFLD_PROTOCOL], - address ? address : "0.0.0.0", - service); - if (pies_url_create (&url, str)) + if (grecs_asprintf (&s, &l, "inet+%s://%s:%s", + ws.ws_wordv[IFLD_PROTOCOL], + address ? address : "0.0.0.0", + service)) + grecs_alloc_die (); + rc = pies_url_create (&url, s); + free (s); + if (rc) { @@ -207,3 +214,2 @@ inetd_conf_file (const char *file) } - free (str); } @@ -276,4 +282,4 @@ inetd_conf_file (const char *file) comp->tcpmux = mktag (address, "tcpmux"); - comp->service = xstrdup (service); - comp->privs.user = xstrdup (user); /* FIXME: memory leak */ + comp->service = grecs_strdup (service); + comp->privs.user = grecs_strdup (user); /* FIXME: memory leak */ if (group) @@ -282,6 +288,6 @@ inetd_conf_file (const char *file) comp->privs.groups->free_entry = listel_dispose; - grecs_list_append (comp->privs.groups, xstrdup (group)); + grecs_list_append (comp->privs.groups, grecs_strdup (group)); } - comp->program = xstrdup (ws.ws_wordv[IFLD_SERVER_PATH]); + comp->program = grecs_strdup (ws.ws_wordv[IFLD_SERVER_PATH]); @@ -292,5 +298,5 @@ inetd_conf_file (const char *file) comp->argc = ws.ws_wordc - IFLD_MIN_COUNT; - comp->argv = xcalloc (comp->argc + 1, sizeof (comp->argv[0])); + comp->argv = grecs_calloc (comp->argc + 1, sizeof (comp->argv[0])); for (i = IFLD_SERVER_ARGS, j = 0; i < ws.ws_wordc; i++, j++) - comp->argv[j] = xstrdup (ws.ws_wordv[i]); + comp->argv[j] = grecs_strdup (ws.ws_wordv[i]); } @@ -299,4 +305,4 @@ inetd_conf_file (const char *file) comp->argc = 1; - comp->argv = xcalloc (comp->argc + 1, sizeof (comp->argv[0])); - comp->argv[0] = xstrdup (comp->program); + comp->argv = grecs_calloc (comp->argc + 1, sizeof (comp->argv[0])); + comp->argv[0] = grecs_strdup (comp->program); } @@ -343,3 +349,3 @@ inetd_conf_dir (const char *name) namebufsize += NAME_INIT_ALLOC; - namebuf = xmalloc (namebufsize); + namebuf = grecs_malloc (namebufsize); memcpy (namebuf, name, namelen); @@ -364,3 +370,3 @@ inetd_conf_dir (const char *name) namebufsize = namelen + len + 1; - namebuf = xrealloc (namebuf, namebufsize); + namebuf = grecs_realloc (namebuf, namebufsize); } diff --git a/src/limits.c b/src/limits.c index 6dadd6c..a2c8ad9 100644 --- a/src/limits.c +++ b/src/limits.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2008, 2009, 2010, 2013 Sergey Poznyakoff + Copyright (C) 2008-2010, 2013, 2016 Sergey Poznyakoff @@ -196,3 +196,3 @@ parse_limits (limits_record_t *plrec, char *str, char **endp) int c; - struct limits_rec *lrec = xmalloc (sizeof (*lrec)); + struct limits_rec *lrec = grecs_malloc (sizeof (*lrec)); *plrec = lrec; diff --git a/src/meta.c b/src/meta.c deleted file mode 100644 index fcd7f8b..0000000 --- a/src/meta.c +++ /dev/null @@ -1,127 +0,0 @@ -/* This file is part of GNU Pies. - Copyright (C) 2008, 2009, 2010, 2013 Sergey Poznyakoff - - GNU Pies 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, or (at your option) - any later version. - - GNU Pies 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 GNU Pies. If not, see <http://www.gnu.org/licenses/>. */ - -#include "pies.h" -#include <c-ctype.h> - -static const char * -meta_expand (struct metadef *def, void *data) -{ - if (!def->value) - { - if (def->expand) - return def->expand (def, data); - def->value = "INTERNAL ERROR: NONEXPANDABLE DATA"; - } - return def->value; -} - -static const char * -find_expansion_char (int c, struct metadef *def, void *data) -{ - for (; def->kw; def++) - if (def->kw[1] == 0 && def->kw[0] == c) - return meta_expand (def, data); - return NULL; -} - -static const char * -find_expansion_word (const char *kw, size_t len, - struct metadef *def, void *data) -{ - for (; def->kw; def++) - if (strlen (def->kw) == len && memcmp (def->kw, kw, len) == 0) - return meta_expand (def, data); - return NULL; -} - -char * -meta_expand_string (const char *string, struct metadef *def, void *data) -{ - const char *p, *s; - char *res; - struct obstack stk; - - if (!string) - return NULL; - - obstack_init (&stk); - - for (p = string; *p;) - { - char *e; - size_t len = strcspn (p, "$"); - - obstack_grow (&stk, p, len); - p += len; - if (*p == '$') - { - switch (*++p) - { - case '$': - obstack_grow (&stk, p, 1); - p++; - break; - - case '{': - e = strchr (p + 1, '}'); - if (e && (s = find_expansion_word (p + 1, e - p - 1, def, data))) - { - obstack_grow (&stk, s, strlen (s)); - p = e + 1; - } - else - { - obstack_grow (&stk, p - 1, 2); - p++; - } - break; - - default: - if ((s = find_expansion_char (*p, def, data)) != NULL) - len = strlen (s); - else - { - s = p - 1; - len = 1; - } - - obstack_grow (&stk, s, len); - p++; - } - } - else - obstack_grow (&stk, p, 1); - } - obstack_1grow (&stk, 0); - res = xstrdup (obstack_finish (&stk)); - obstack_free (&stk, NULL); - return res; -} - -void -meta_free (struct metadef *def) -{ - for (; def->kw; def++) - { - if (def->storage) - { - free (def->storage); - def->value = def->storage = NULL; - } - } -} - diff --git a/src/meta1gram.y b/src/meta1gram.y index 2f774d2..44751f3 100644 --- a/src/meta1gram.y +++ b/src/meta1gram.y @@ -51,3 +51,3 @@ meta1_stmt_create (enum meta1_stmt_type type, const char *ident) { - struct meta1_stmt *p = xmalloc (sizeof (*p)); + struct meta1_stmt *p = grecs_malloc (sizeof (*p)); p->next = NULL; @@ -154,3 +154,3 @@ value : string { - $$ = xmalloc (sizeof (*$$)); + $$ = grecs_malloc (sizeof (*$$)); $$->type = GRECS_TYPE_STRING; @@ -160,3 +160,3 @@ value : string { - $$ = xmalloc (sizeof (*$$)); + $$ = grecs_malloc (sizeof (*$$)); $$->type = GRECS_TYPE_LIST; @@ -166,3 +166,3 @@ value : string { - $$ = xmalloc (sizeof (*$$)); + $$ = grecs_malloc (sizeof (*$$)); $$->type = GRECS_TYPE_STRING; @@ -332,3 +332,3 @@ xlat_listen_socket (struct meta1_stmt *stmt, struct component *comp) } - val = xmalloc (sizeof (*val)); + val = grecs_malloc (sizeof (*val)); val->type = GRECS_TYPE_STRING; @@ -376,3 +376,4 @@ meta1_translate (struct meta1_stmt *stmt) struct meta1_stmt *p; - + size_t len; + if (stmt->type != meta1_block) @@ -388,5 +389,6 @@ meta1_translate (struct meta1_stmt *stmt) comp->redir[RETR_ERR].type = redir_file; - comp->redir[RETR_ERR].v.file = xasprintf ("%s/%s.log", - META1_QUEUE_DIR (), - comp->tag); + comp->redir[RETR_ERR].v.file = NULL; + len = 0; + grecs_asprintf (&comp->redir[RETR_ERR].v.file, &len, + "%s/%s.log", META1_QUEUE_DIR (), comp->tag); component_finish (comp, &stmt->locus); diff --git a/src/meta1lex.l b/src/meta1lex.l index 2aca914..a074a8d 100644 --- a/src/meta1lex.l +++ b/src/meta1lex.l @@ -35,4 +35,3 @@ static struct grecs_locus_point meta1_locus_point; -struct obstack meta1_stk; -int meta1_stk_init; +static struct grecs_txtacc *meta1_txtacc; char *meta1_queue_dir; @@ -121,3 +120,3 @@ meta1_line_add (const char *text, size_t len) { - obstack_grow (&meta1_stk, text, len); + grecs_txtacc_grow (meta1_txtacc, text, len); } @@ -152,3 +151,3 @@ unescape_to_line (int c) } - obstack_1grow (&meta1_stk, t); + grecs_txtacc_grow_char (meta1_txtacc, t); } @@ -158,3 +157,3 @@ meta1_line_add_unescape_last (const char *text, size_t len) { - obstack_grow (&meta1_stk, text, len - 2); + grecs_txtacc_grow (meta1_txtacc, text, len - 2); unescape_to_line (text[len - 1]); @@ -167,4 +166,4 @@ meta1_line_add_unescape_hex (const char *text, size_t len) ; - obstack_grow (&meta1_stk, text, len - 2); - obstack_1grow (&meta1_stk, (char) strtoul (text + len, NULL, 16)); + grecs_txtacc_grow (meta1_txtacc, text, len - 2); + grecs_txtacc_grow_char (meta1_txtacc, (char) strtoul (text + len, NULL, 16)); } @@ -174,7 +173,4 @@ meta1_line_begin () { - if (!meta1_stk_init) - { - obstack_init (&meta1_stk); - meta1_stk_init = 1; - } + if (!meta1_txtacc) + meta1_txtacc = grecs_txtacc_create(); } @@ -184,4 +180,4 @@ meta1_line_finish () { - obstack_1grow (&meta1_stk, 0); - return obstack_finish (&meta1_stk); + grecs_txtacc_grow_char (meta1_txtacc, 0); + return grecs_txtacc_finish (meta1_txtacc, 0); } @@ -103,5 +103,5 @@ add_config (enum config_syntax syntax, const char *name) { - struct config_file *file = xmalloc (sizeof (file[0])); + struct config_file *file = grecs_malloc (sizeof (file[0])); file->syntax = syntax; - file->name = xstrdup (name); + file->name = grecs_strdup (name); if (!config_list) @@ -287,3 +287,3 @@ create_action (struct component *comp, - retv = xcalloc (argc, sizeof *retv); + retv = grecs_calloc (argc, sizeof *retv); if (argc == 0 || (argc == 1 && strcmp (getarg (val, 0, locus), "*") == 0)) @@ -344,3 +344,3 @@ create_action (struct component *comp, - act = xzalloc (sizeof *act); + act = grecs_zalloc (sizeof *act); if (!allflag) @@ -453,3 +453,3 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc) argc = val->v.arg.c; - argv = xcalloc (argc + 1, sizeof (argv[0])); + argv = grecs_calloc (argc + 1, sizeof (argv[0])); for (i = j = 0; i < argc; i++) @@ -458,3 +458,3 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc) == 0) - argv[j++] = xstrdup (val->v.arg.v[i]->v.string); + argv[j++] = grecs_strdup (val->v.arg.v[i]->v.string); } @@ -696,3 +696,3 @@ _cb_redir (enum grecs_callback_command cmd, case redir_file: - rp->v.file = xstrdup (value->v.arg.v[1]->v.string); + rp->v.file = grecs_strdup (value->v.arg.v[1]->v.string); break; @@ -1185,3 +1185,3 @@ make_full_name (const char *dir, const char *file) len--; - p = xmalloc (len + 1 + strlen (file) + 1); + p = grecs_malloc (len + 1 + strlen (file) + 1); memcpy (p, dir, len); @@ -1295,3 +1295,3 @@ component_verify (struct component *comp, grecs_locus_t *locus) _("TCPMUX master not specified, assuming \"tcpmux\"")); - comp->tcpmux = xstrdup ("tcpmux"); + comp->tcpmux = grecs_strdup ("tcpmux"); } @@ -1368,6 +1368,6 @@ component_create (const char *name) { - comp = xzalloc (sizeof (*comp)); + comp = grecs_zalloc (sizeof (*comp)); comp->facility = log_facility; comp->redir[RETR_OUT].type = comp->redir[RETR_ERR].type = redir_null; - comp->tag = xstrdup (name); + comp->tag = grecs_strdup (name); comp->socket_type = SOCK_STREAM; @@ -1958,3 +1958,3 @@ request_restart_components (size_t cc, char **cv) - argv = xcalloc (cc + 4, sizeof (*argv)); + argv = grecs_calloc (cc + 4, sizeof (*argv)); argv[0] = "piesctl"; @@ -2123,5 +2123,5 @@ set_mailer_argcv () mailer_argc = ws.ws_wordc; - mailer_argv = xcalloc (mailer_argc + 1, sizeof (mailer_argv[0])); + mailer_argv = grecs_calloc (mailer_argc + 1, sizeof (mailer_argv[0])); for (i = 0; i < mailer_argc; i++) - mailer_argv[i] = xstrdup (ws.ws_wordv[i]); + mailer_argv[i] = grecs_strdup (ws.ws_wordv[i]); mailer_argv[i] = NULL; @@ -52,7 +52,2 @@ #include "c-ctype.h" -#include "xalloc.h" -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free -#include "obstack.h" -#include "xvasprintf.h" #include "quotearg.h" @@ -362,2 +357,3 @@ size_t depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, size_t depmap_next (pies_depmap_t dmap, pies_depmap_pos_t pos); +void depmap_end (pies_depmap_pos_t pos); @@ -451,17 +447,2 @@ void debug_msg (const char *fmt, ...) PIES_PRINTFLIKE(1,2); while (0) - - -/* meta.c */ -struct metadef -{ - char *kw; - char *value; - const char *(*expand) (struct metadef *, void *); - char *storage; - void *data; -}; - -char *meta_expand_string (const char *string, struct metadef *def, void *data); -void meta_free (struct metadef *def); - diff --git a/src/progman.c b/src/progman.c index 216fb72..eb7b70f 100644 --- a/src/progman.c +++ b/src/progman.c @@ -203,7 +203,8 @@ redir_tag (struct prog *master, int type) static char *redirstr[2] = { "stdout", "stderr" }; - char *str; + char *str = NULL; + size_t len = 0; if (type < ARRAY_SIZE(redirstr)) - str = xasprintf ("%s/%s", master->tag, redirstr[type]); + grecs_asprintf (&str, &len, "%s/%s", master->tag, redirstr[type]); else - str = xasprintf ("%s/%d", master->tag, type); + grecs_asprintf (&str, &len, "%s/%d", master->tag, type); return str; @@ -216,4 +217,4 @@ register_redir (int type, struct prog *master) char *pstr; - struct prog *pp = xzalloc (sizeof (*pp) + strlen (tag) + 1 + - 2 * sizeof (char**)); + struct prog *pp = grecs_zalloc (sizeof (*pp) + strlen (tag) + 1 + + 2 * sizeof (char**)); @@ -253,3 +254,3 @@ register_prog0 (struct component *comp, unsigned index) - newp = xzalloc (sizeof (*newp)); + newp = grecs_zalloc (sizeof (*newp)); newp->type = TYPE_COMPONENT; @@ -282,4 +283,3 @@ register_command (char *tag, char *command, pid_t pid) { |