aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 15:31:17 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 16:17:35 +0200
commit489432d354d88049afe4af54c29965d382d67f7a (patch)
tree84725496a92564824f75f0a2edd5a595411ffab2
parent3325fed2895f079486b88c65409c73153fec306f (diff)
downloadpies-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--.gitignore1
-rw-r--r--doc/pies.texi10
-rw-r--r--gnulib.modules3
-rw-r--r--ident/ident.c16
-rw-r--r--ident/ident.h4
-rw-r--r--ident/pam.c4
-rw-r--r--ident/provider.c8
-rw-r--r--ident/system.c6
-rw-r--r--src/Makefile.am1
-rw-r--r--src/acl.c20
-rw-r--r--src/ctl.c44
-rw-r--r--src/depmap.c12
-rw-r--r--src/diag.c48
-rw-r--r--src/inetd.c40
-rw-r--r--src/limits.c4
-rw-r--r--src/meta.c127
-rw-r--r--src/meta1gram.y18
-rw-r--r--src/meta1lex.l24
-rw-r--r--src/pies.c28
-rw-r--r--src/pies.h21
-rw-r--r--src/progman.c196
-rw-r--r--src/socket.c4
-rw-r--r--src/sysvinit.c14
-rw-r--r--src/userprivs.c10
24 files changed, 314 insertions, 349 deletions
diff --git a/.gitignore b/.gitignore
index 216d2e5..11f9326 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/ABOUT-NLS
/ABOUT-NLS~
*.a
*.la
diff --git a/doc/pies.texi b/doc/pies.texi
index 46e1b91..7ad5008 100644
--- a/doc/pies.texi
+++ b/doc/pies.texi
@@ -1681,8 +1681,8 @@ The table below lists all available variables and their expansions:
@caption{Notification Variables}
@multitable @columnfractions 0.5 0.5
@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}).
@item instance @tab Instance name (@pxref{instances}).
@item version @tab Package version (@value{VERSION}).
@@ -1712,7 +1712,7 @@ message is used instead:
@smallexample
From: <>
-X-Agent: $@{canonical-program-name@} ($@{package@} $@{version@})
+X-Agent: $@{canonical_program_name@} ($@{package@} $@{version@})
Subject: Component $@{component@} $@{termination@} $@{retcode@}.
@end smallexample
@@ -2299,7 +2299,7 @@ return-code (EX_USAGE, EX_CONFIG) @{
notify "root";
message <<- EOT
From: Pies <>
- X-Agent: $@{canonical-program-name@} ($@{package@} $@{version@})
+ X-Agent: $@{canonical_program_name@} ($@{package@} $@{version@})
Subject: Component $@{component@} disabled.
Component "$@{component@}" has terminated with code $@{retcode@},
@@ -2307,7 +2307,7 @@ return-code (EX_USAGE, EX_CONFIG) @{
I will not restart it automatically. Please fix its configuration
and restart it manually at your earliest convenience.
- To restart, run ``$@{program-name@} -R $@{component@}''
+ To restart, run ``$@{program_name@} -R $@{component@}''
---
Wuff-wuff,
Pies
diff --git a/gnulib.modules b/gnulib.modules
index 2612e75..9e9d255 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -9,9 +9,6 @@ fprintftime
gettext
inttostr
inttypes
-obstack
progname
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,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2015 Sergey Poznyakoff
+ Copyright (C) 2015-2016 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
@@ -19,10 +19,20 @@
pies_identity_t
pies_identity_create (char const *user)
{
- pies_identity_t id = xmalloc (sizeof (*id));
+ pies_identity_t id = malloc (sizeof (*id));
+ if (id)
+ {
id->provider = NULL;
- id->username = xstrdup (user);
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,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2015 Sergey Poznyakoff
+ Copyright (C) 2015-2016 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
@@ -15,7 +15,7 @@
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
-#include "xalloc.h"
+#include <errno.h>
#include "libpies.h"
#include "grecs.h"
#include "identity.h"
diff --git a/ident/pam.c b/ident/pam.c
index 7302242..96ac02c 100644
--- a/ident/pam.c
+++ b/ident/pam.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2015 Sergey Poznyakoff
+ Copyright (C) 2015-2016 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
@@ -183,7 +183,7 @@ static int
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;
for (i = 0; pam_kw[i].ident; i++)
pam_kw[i].varptr = data;
diff --git a/ident/provider.c b/ident/provider.c
index dd7fc3d..8b9f076 100644
--- a/ident/provider.c
+++ b/ident/provider.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2015 Sergey Poznyakoff
+ Copyright (C) 2015-2016 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
@@ -27,7 +27,7 @@ idmech_copy (void *a, void *b)
pies_identity_mechanism_t mb = b;
*ma = *mb;
- ma->name = xstrdup (mb->name);
+ ma->name = grecs_strdup (mb->name);
return 0;
}
@@ -135,8 +135,8 @@ pies_config_provider (struct grecs_node *node)
return 1;
}
- prov = xcalloc (1, sizeof (*prov));
- prov->name = xstrdup (name);
+ prov = grecs_calloc (1, sizeof (*prov));
+ prov->name = grecs_strdup (name);
prov->mech = mp;
prov->locus = node->locus;
diff --git a/ident/system.c b/ident/system.c
index dcfe7a2..086eb85 100644
--- a/ident/system.c
+++ b/ident/system.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2015 Sergey Poznyakoff
+ Copyright (C) 2015-2016 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
@@ -60,7 +60,9 @@ system_authenticate (pies_identity_provider_t pr, pies_identity_t id,
if (strcmp (crypt (passwd, encrypted_pass), encrypted_pass) == 0)
{
- 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;
id->data = data;
return 0;
diff --git a/src/Makefile.am b/src/Makefile.am
index 01149c6..a2400fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,7 +25,6 @@ pies_SOURCES = \
inetd.c\
inetd-bi.c\
limits.c\
- meta.c\
meta1gram.y\
meta1lex.l\
pies.c\
diff --git a/src/acl.c b/src/acl.c
index 94dd561..412f3ac 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies
- Copyright (C) 2009-2013 Sergey Poznyakoff
+ Copyright (C) 2009-2016 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
@@ -111,8 +111,8 @@ acl_free_entry (void *p)
pies_acl_t
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);
acl->list = grecs_list_create ();
acl->list->free_entry = acl_free_entry;
@@ -131,7 +131,7 @@ pies_acl_free (pies_acl_t acl)
static struct pies_sockaddr *
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;
p->sa.sa_family = family;
return p;
@@ -369,18 +369,18 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv)
}
if (argv[0]->type == GRECS_TYPE_STRING)
{
- 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;
}
else
{
size_t i;
struct grecs_list_entry *ep;
- entry->names = xcalloc (argv[0]->v.list->count + 1,
+ 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;
}
argc--;
@@ -404,7 +404,7 @@ int
parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl,
grecs_value_t *value)
{
- struct acl_entry *entry = xzalloc (sizeof (*entry));
+ struct acl_entry *entry = grecs_zalloc (sizeof (*entry));
grecs_locus_copy (&entry->locus, locus);
entry->allow = allow;
@@ -742,7 +742,7 @@ pies_acl_install (pies_acl_t acl)
NULL,
acl_free);
if (!acl_table)
- xalloc_die ();
+ grecs_alloc_die ();
}
ret = grecs_symtab_lookup_or_install (acl_table, acl, &install);
diff --git a/src/ctl.c b/src/ctl.c
index 46038a2..22aecb8 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -16,7 +16,6 @@
#include "pies.h"
#include "prog.h"
-#include "xvasprintf.h"
#include "identity.h"
#include "base64.h"
#include "json.h"
@@ -55,11 +54,14 @@ ctlbuf_free (struct ctlbuf *buf)
static void
ctlbuf_alloc (struct ctlbuf *buf, size_t s)
{
- while (buf->level + s >= buf->size)
+ size_t minsize = buf->level + s;
+ while (minsize >= buf->size)
{
if (buf->size == 0)
buf->size = CTLBUFSIZE;
- buf->base = x2realloc (buf->base, &buf->size);
+ else
+ buf->size *= CTLBUFSIZE;
+ buf->base = grecs_realloc (buf->base, buf->size);
}
}
@@ -415,6 +417,7 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...)
int install = 1;
struct http_header key, *ret;
va_list ap;
+ size_t len = 0;
key.name = (char *) name;
key.value = NULL;
@@ -428,7 +431,8 @@ output_set_header (struct output *out, char const *name, char const *fmt, ...)
if (!install)
free (ret->value);
va_start (ap, fmt);
- ret->value = xvasprintf (fmt, ap);
+ ret->value = NULL;
+ grecs_vasprintf (&ret->value, &len, fmt, ap);
va_end (ap);
return 0;
}
@@ -444,13 +448,14 @@ json_object_set_string (struct json_value *obj,
char const *name, char const *fmt, ...)
{
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);
}
static void
@@ -486,7 +491,7 @@ ctlio_create (void)
{
struct ctlio *io;
- io = xmalloc (sizeof (*io));
+ io = grecs_malloc (sizeof (*io));
input_init (&io->input);
output_init (&io->output);
io->state = identity_provider_list ? CTL_INITIAL_STATE : CTL_ADMIN_STATE;
@@ -581,14 +586,15 @@ ctlio_reply (struct ctlio *io, int code, const char *fmt, ...)
if (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);
io->output.reply = json_error_reply_create (str);
- free (str);
+ grecs_free (str);
}
else
io->output.reply = json_error_reply_create (http_text (code));
@@ -604,10 +610,11 @@ static void
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);
ctlio_print (io, str);
free (str);
@@ -734,6 +741,13 @@ do_auth (struct ctlio *io, char const *name, char const *pass)
pies_identity_t id = pies_identity_create (name);
int new_state = CTL_INITIAL_STATE;
+ if (!id)
+ {
+ logmsg (LOG_AUTH, _("%s: can't authenticate: %s"),
+ name, strerror (errno));
+ return -1;
+ }
+
for (ep = identity_provider_list->head; ep; ep = ep->next)
{
pies_identity_provider_t provider = ep->data;
@@ -815,11 +829,11 @@ ctlio_authenticate (struct ctlio *io)
char *passwd;
size_t s = p - data;
- user = xmalloc (s + 1);
+ user = grecs_malloc (s + 1);
memcpy (user, data, s);
user[s] = 0;
- passwd = xmalloc (datalen - s);
+ passwd = grecs_malloc (datalen - s);
memcpy (passwd, p + 1, datalen - s - 1);
passwd[datalen - s - 1] = 0;
diff --git a/src/depmap.c b/src/depmap.c
index ac02fdc..e4533e8 100644
--- a/src/depmap.c
+++ b/src/depmap.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2008-2013 Sergey Poznyakoff
+ Copyright (C) 2008-2013, 2016 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
@@ -90,7 +90,7 @@ pies_depmap_t
depmap_alloc (size_t count)
{
size_t size = (count + BITS_PER_WORD - 1) / BITS_PER_WORD;
- pies_depmap_t dmap = xzalloc (sizeof (*dmap) - 1
+ pies_depmap_t dmap = grecs_zalloc (sizeof (*dmap) - 1
+ count * size * sizeof (unsigned));
dmap->nrows = count;
dmap->rowlen = size;
@@ -153,10 +153,16 @@ size_t
depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir,
size_t coord, pies_depmap_pos_t *ppos)
{
- pies_depmap_pos_t pos = xmalloc (sizeof *pos);
+ pies_depmap_pos_t pos = grecs_malloc (sizeof *pos);
*ppos = pos;
pos->dir = dir;
pos->coord[!pos->dir] = coord;
pos->coord[pos->dir] = -1;
return depmap_next (dmap, pos);
}
+
+void
+depmap_end (pies_depmap_pos_t pos)
+{
+ grecs_free (pos);
+}
diff --git a/src/diag.c b/src/diag.c
index 165cc2f..65d9562 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -15,7 +15,6 @@
along with GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
#include "pies.h"
-#include "xvasprintf.h"
unsigned debug_level;
int source_info_option;
@@ -103,39 +102,42 @@ debug_msg (const char *fmt, ...)
}
-static struct obstack log_stk;
-static int log_stk_init;
void
logmsg_vprintf (int prio, const char *fmt, va_list ap)
{
- char *str, *p;
+ char *p, *t, *str;
+ static char *buf = NULL;
+ static size_t len = 0;
+ static struct grecs_txtacc *log_acc;
- str = xvasprintf (fmt, ap);
-
- 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);
}
void
diff --git a/src/inetd.c b/src/inetd.c
index 4a55ad5..3eb4470 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -64,13 +64,13 @@ mktag (const char *address, const char *service)
if (address)
{
- str = xmalloc (strlen (address) + 1 + strlen (service) + 1);
+ str = grecs_malloc (strlen (address) + 1 + strlen (service) + 1);
strcpy (str, address);
strcat (str, ":");
strcat (str, service);
}
else
- str = xstrdup (service);
+ str = grecs_strdup (service);
return str;
}
@@ -137,7 +137,7 @@ inetd_conf_file (const char *file)
dfl_address = NULL;
else
{
- dfl_address = xmalloc (len);
+ dfl_address = grecs_malloc (len);
memcpy (dfl_address, ws.ws_wordv[IFLD_SERVICE], len-1);
dfl_address[len-1] = 0;
}
@@ -193,19 +193,25 @@ inetd_conf_file (const char *file)
}
else
{
+ char *s = NULL;
+ size_t l = 0;
+ int rc;
+
/* Create URL from protocol and service fields. */
- str = xasprintf ("inet+%s://%s:%s",
+ if (grecs_asprintf (&s, &l, "inet+%s://%s:%s",
ws.ws_wordv[IFLD_PROTOCOL],
address ? address : "0.0.0.0",
- service);
- if (pies_url_create (&url, str))
+ service))
+ grecs_alloc_die ();
+ rc = pies_url_create (&url, s);
+ free (s);
+ if (rc)
{
/* FIXME: Better error message */
logmsg (LOG_ERR, "%s:%lu: %s",
file, line_no, _("invalid socket address"));
continue;
}
- free (str);
}
/* Parse wait/nowait field */
@@ -274,31 +280,31 @@ inetd_conf_file (const char *file)
comp->flags = flags;
if (ISCF_TCPMUX (comp->flags))
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)
{
comp->privs.groups = grecs_list_create ();
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]);
if (ws.ws_wordc > IFLD_MIN_COUNT)
{
size_t i, j;
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]);
}
else
{
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);
}
if (progman_lookup_component (comp->tag) == NULL)
@@ -341,7 +347,7 @@ inetd_conf_dir (const char *name)
if (name[namelen-1] != '/')
namebufsize++;
namebufsize += NAME_INIT_ALLOC;
- namebuf = xmalloc (namebufsize);
+ namebuf = grecs_malloc (namebufsize);
memcpy (namebuf, name, namelen);
if (name[namelen-1] != '/')
namebuf[namelen++] = 0;
@@ -362,7 +368,7 @@ inetd_conf_dir (const char *name)
if (namelen + len >= namebufsize)
{
namebufsize = namelen + len + 1;
- namebuf = xrealloc (namebuf, namebufsize);
+ namebuf = grecs_realloc (namebuf, namebufsize);
}
strcpy (namebuf + namelen, ent->d_name);
errs |= inetd_conf_file (namebuf);
diff --git a/src/limits.c b/src/limits.c
index 6dadd6c..a2c8ad9 100644
--- a/src/limits.c
+++ b/src/limits.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2008, 2009, 2010, 2013 Sergey Poznyakoff
+ Copyright (C) 2008-2010, 2013, 2016 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
@@ -194,7 +194,7 @@ int
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;
lrec->set = 0;
while ((c = *str++))
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
@@ -49,7 +49,7 @@ struct meta1_stmt
struct meta1_stmt *
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;
p->type = type;
p->ident = ident;
@@ -152,19 +152,19 @@ ident : META1_IDENT
value : string
{
- $$ = xmalloc (sizeof (*$$));
+ $$ = grecs_malloc (sizeof (*$$));
$$->type = GRECS_TYPE_STRING;
$$->v.string = $1;
}
| list
{
- $$ = xmalloc (sizeof (*$$));
+ $$ = grecs_malloc (sizeof (*$$));
$$->type = GRECS_TYPE_LIST;
$$->v.list = $1;
}
| META1_NUMBER
{
- $$ = xmalloc (sizeof (*$$));
+ $$ = grecs_malloc (sizeof (*$$));
$$->type = GRECS_TYPE_STRING;
$$->v.string = $1;
}
@@ -330,7 +330,7 @@ xlat_listen_socket (struct meta1_stmt *stmt, struct component *comp)
meta1_line_add (p->v.value->v.string, strlen (p->v.value->v.string));
}
}
- val = xmalloc (sizeof (*val));
+ val = grecs_malloc (sizeof (*val));
val->type = GRECS_TYPE_STRING;
val->v.string = meta1_line_finish ();
stmt->type = meta1_simple;
@@ -374,6 +374,7 @@ meta1_translate (struct meta1_stmt *stmt)
{
struct component *comp;
struct meta1_stmt *p;
+ size_t len;
if (stmt->type != meta1_block)
return;
@@ -386,8 +387,9 @@ meta1_translate (struct meta1_stmt *stmt)
comp->privs.allgroups = 1;
comp->dir = META1_QUEUE_DIR ();
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
@@ -33,8 +33,7 @@
#include "meta1lex.h"
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;
#define yylval meta1lval
@@ -119,7 +118,7 @@ yywrap ()
void
meta1_line_add (const char *text, size_t len)
{
- obstack_grow (&meta1_stk, text, len);
+ grecs_txtacc_grow (meta1_txtacc, text, len);
}
static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v";
@@ -150,13 +149,13 @@ unescape_to_line (int c)
if (t == c && t != '\\' && t != '\"')
grecs_error (&meta1lloc, 0, _("unknown escape sequence '\\%c'"), c);
}
- obstack_1grow (&meta1_stk, t);
+ grecs_txtacc_grow_char (meta1_txtacc, t);
}
void
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]);
}
@@ -165,25 +164,22 @@ meta1_line_add_unescape_hex (const char *text, size_t len)
{
for (; text[len-1] != 'x' && len > 0; 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));
}
void
meta1_line_begin ()
{
- if (!meta1_stk_init)
- {
-