summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 13:31:17 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-08 14:17:35 (GMT)
commit489432d354d88049afe4af54c29965d382d67f7a (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore1
-rw-r--r--doc/pies.texi10
-rw-r--r--gnulib.modules3
-rw-r--r--ident/ident.c20
-rw-r--r--ident/ident.h4
-rw-r--r--ident/pam.c4
-rw-r--r--ident/provider.c12
-rw-r--r--ident/system.c6
-rw-r--r--src/Makefile.am1
-rw-r--r--src/acl.c22
-rw-r--r--src/ctl.c48
-rw-r--r--src/depmap.c14
-rw-r--r--src/diag.c48
-rw-r--r--src/inetd.c44
-rw-r--r--src/limits.c4
-rw-r--r--src/meta.c127
-rw-r--r--src/meta1gram.y20
-rw-r--r--src/meta1lex.l24
-rw-r--r--src/pies.c28
-rw-r--r--src/pies.h21
-rw-r--r--src/progman.c218
-rw-r--r--src/socket.c4
-rw-r--r--src/sysvinit.c60
-rw-r--r--src/userprivs.c12
24 files changed, 360 insertions, 395 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));
- 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,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;
}
@@ -38,14 +38,14 @@ pies_identity_mechanism_register (pies_identity_mechanism_t mech)
if (!idmech_symtab)
{
- idmech_symtab = grecs_symtab_create (sizeof(*mech),
+ idmech_symtab = grecs_symtab_create (sizeof (*mech),
NULL,
NULL,
idmech_copy,
NULL,
NULL);
if (!idmech_symtab)
- grecs_alloc_die();
+ grecs_alloc_die ();
}
install = 1;
@@ -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,
- 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;
}
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,7 +417,8 @@ 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;
ret = grecs_symtab_lookup_or_install (out->headers, &key, &install);
@@ -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);
@@ -733,6 +740,13 @@ do_auth (struct ctlio *io, char const *name, char const *pass)
struct grecs_list_entry *ep;
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)
{
@@ -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,8 +90,8 @@ 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
- + count * size * sizeof (unsigned));
+ pies_depmap_t dmap = grecs_zalloc (sizeof (*dmap) - 1
+ + count * size * sizeof (unsigned));
dmap->nrows = count;
dmap->rowlen = size;
return dmap;
@@ -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;
-
- 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);
}
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",
- 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)
{
/* 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
+++ b/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,7 +374,8 @@ 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)
- {
- obstack_init (&meta1_stk);
- meta1_stk_init = 1;
- }
+ if (!meta1_txtacc)
+ meta1_txtacc = grecs_txtacc_create();
}
char *
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);
}
char *
diff --git a/src/pies.c b/src/pies.c
index 09f9fab..733f3db 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -101,9 +101,9 @@ str_to_config_syntax (const char *str, enum config_syntax *psynt)
void
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)
config_list = grecs_list_create ();
grecs_list_append (config_list, file);
@@ -285,7 +285,7 @@ create_action (struct component *comp,
int allflag = 0;
struct action *act;
- retv = xcalloc (argc, sizeof *retv);
+ retv = grecs_calloc (argc, sizeof *retv);
if (argc == 0 || (argc == 1 && strcmp (getarg (val, 0, locus), "*") == 0))
allflag = 1;
else
@@ -342,7 +342,7 @@ create_action (struct component *comp,
return NULL;
}
- act = xzalloc (sizeof *act);
+ act = grecs_zalloc (sizeof *act);
if (!allflag)
{
act->nstat = retc;
@@ -451,12 +451,12 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc)
char **argv;
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++)
{
if (assert_grecs_value_type (locus, val->v.arg.v[i], GRECS_TYPE_STRING)
== 0)
- argv[j++] = xstrdup (val->v.arg.v[i]->v.string);
+ argv[j++] = grecs_strdup (val->v.arg.v[i]->v.string);
}
argv[j] = NULL;
if (pargc)
@@ -694,7 +694,7 @@ _cb_redir (enum grecs_callback_command cmd,
break;
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;
}
}
@@ -1183,7 +1183,7 @@ make_full_name (const char *dir, const char *file)
while (len > 0 && dir[len - 1] == '/')
len--;
- p = xmalloc (len + 1 + strlen (file) + 1);
+ p = grecs_malloc (len + 1 + strlen (file) + 1);
memcpy (p, dir, len);
p[len++] = '/';
strcpy (p + len, file);
@@ -1293,7 +1293,7 @@ component_verify (struct component *comp, grecs_locus_t *locus)
COMPERR (grecs_warning,
"%s",
_("TCPMUX master not specified, assuming \"tcpmux\""));
- comp->tcpmux = xstrdup ("tcpmux");
+ comp->tcpmux = grecs_strdup ("tcpmux");
}
}
else if (comp->tcpmux)
@@ -1366,10 +1366,10 @@ component_create (const char *name)
struct component *comp = progman_lookup_component (name);
if (!comp)
{
- 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;
}
return comp;
@@ -1956,7 +1956,7 @@ request_restart_components (size_t cc, char **cv)
char **argv;
size_t i;
- argv = xcalloc (cc + 4, sizeof (*argv));
+ argv = grecs_calloc (cc + 4, sizeof (*argv));
argv[0] = "piesctl";
argv[1] = "--url";
argv[2] = (char*) pies_control_url ();
@@ -2121,9 +2121,9 @@ set_mailer_argcv ()
exit (EX_CONFIG);
}
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;
wordsplit_free (&ws);
}
diff --git a/src/pies.h b/src/pies.h
index f22ccb2..e0d24d2 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -50,11 +50,6 @@
#include "progname.h"
#include "inttostr.h"
#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"
#include "fprintftime.h"
@@ -360,6 +355,7 @@ void depmap_tc (pies_depmap_t dmap);
size_t depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir,
size_t coord, pies_depmap_pos_t *ppos);
size_t depmap_next (pies_depmap_t dmap, pies_depmap_pos_t pos);
+void depmap_end (pies_depmap_pos_t pos);
int assert_grecs_value_type (grecs_locus_t *locus,
const grecs_value_t *value, int type);
@@ -449,21 +445,6 @@ void debug_msg (const char *fmt, ...) PIES_PRINTFLIKE(1,2);
debug_msg args; \
} \
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);
-
/* userprivs.c */
int switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups);
diff --git a/src/progman.c b/src/progman.c
index 216fb72..eb7b70f 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -201,11 +201,12 @@ static char *
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;
}
@@ -214,8 +215,8 @@ register_redir (int type, struct prog *master)
{
char *tag = redir_tag (master, type);
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**));
pp->type = TYPE_REDIRECTOR;
pstr = (char *) (pp + 1);
@@ -251,7 +252,7 @@ register_prog0 (struct component *comp, unsigned index)
{
struct prog *newp;
- newp = xzalloc (sizeof (*newp));
+ newp = grecs_zalloc (sizeof (*newp));
newp->type = TYPE_COMPONENT;
newp->tag = comp->tag;
newp->pid = 0;
@@ -280,8 +281,7 @@ register_prog (struct component *comp)
void
register_command (char *tag, char *command, pid_t pid)
{
- struct prog *newp = xzalloc (sizeof (*newp));
- newp = xzalloc (sizeof (*newp));
+ struct prog *newp = grecs_zalloc (sizeof (*newp));
newp->type = TYPE_COMMAND;
newp->tag = tag;
newp->pid = pid;
@@ -321,7 +321,7 @@ prog_rebuild_prerequisites (struct prog *prog)
if (depc == 0)
return;
- prog->prereq = xcalloc (depc + 1, sizeof (prog->prereq[0]));
+ prog->prereq = grecs_calloc (depc + 1, sizeof (prog->prereq[0]));
depc = 0;
if (comp->prereq)
@@ -549,7 +549,7 @@ conn_class_lookup (const char *tag,
int install = 1;
struct conn_class *probe, *ret;
- probe = xmalloc (sizeof (probe[0]));
+ probe = grecs_malloc (sizeof (probe[0]));
probe->tag = tag;
probe->sa_storage = *sa_storage_ptr;
probe->sa_len = sa_len;
@@ -578,7 +578,7 @@ conn_class_lookup (const char *tag,
NULL,
conn_class_free);
if (!conn_tab)
- xalloc_die ();
+ grecs_alloc_die ();
}
ret = grecs_symtab_lookup_or_install (conn_tab, probe, &install);
@@ -671,7 +671,7 @@ add_env (const char *name, const char *value)
char **new_env;
envsize = i + 4;
- new_env = xcalloc (envsize, sizeof new_env[0]);
+ new_env = grecs_calloc (envsize, sizeof new_env[0]);
for (i = 0; (new_env[i] = environ[i]); i++)
;
environ = new_env;
@@ -679,15 +679,15 @@ add_env (const char *name, const char *value)
else if (i == envsize)
{
envsize += 4;
- environ = xrealloc (environ,
- envsize * sizeof environ[0]);
+ environ = grecs_realloc (environ,
+ envsize * sizeof environ[0]);
}
environ[i+1] = NULL;
}
if (!value)
value = "";
- p = xmalloc (namelen + 1 + strlen (value) + 1);
+ p = grecs_malloc (namelen + 1 + strlen (value) + 1);
strcpy (p, name);
p[namelen] = '=';
strcpy (p + namelen + 1, value);
@@ -743,7 +743,7 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
if (a && b)
{
- res = xmalloc (namelen + 1 + strlen (a) + strlen (b) + 1);
+ res = grecs_malloc (namelen + 1 + strlen (a) + strlen (b) + 1);
strcpy (res + namelen + 1, a);
strcat (res, b);
}
@@ -752,7 +752,7 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
len = strlen (a);
if (c_ispunct (a[len-1]))
len--;
- res = xmalloc (namelen + 1 + len + 1);
+ res = grecs_malloc (namelen + 1 + len + 1);
memcpy (res + namelen + 1, a, len);
res[namelen + 1 + len] = 0;
}
@@ -761,7 +761,7 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
if (c_ispunct (b[0]))
b++;
len = strlen (b);
- res = xmalloc (namelen + 1 + len + 1);
+ res = grecs_malloc (namelen + 1 + len + 1);
strcpy (res + namelen + 1, b);
}
memcpy (res, name, namelen);
@@ -795,7 +795,7 @@ environ_setup (char **hint)
count++;
/* Allocate new environment. */
- new_env = xcalloc (count + 1, sizeof new_env[0]);
+ new_env = grecs_calloc (count + 1, sizeof new_env[0]);
/* Populate the environment. */
n = 0;
@@ -1494,7 +1494,7 @@ component_fixup_depend (struct component *comp)
tgt->prereq = grecs_list_create();
}
/* FIXME: memory allocation */
- grecs_list_append (tgt->prereq, xstrdup (comp->tag));
+ grecs_list_append (tgt->prereq, grecs_strdup (comp->tag));
}
grecs_list_free (comp->depend);
comp->depend = NULL;
@@ -1533,6 +1533,7 @@ print_dep (struct prog *prog)
struct prog *dp = prog_lookup_by_idx (n);
logmsg_printf (LOG_NOTICE, "%s -> ", dp->tag);
}
+ depmap_end (pos);
logmsg_printf (LOG_NOTICE, "%s\n", prog->tag);
}
@@ -1791,7 +1792,7 @@ prog_start_prerequisites (struct prog *prog)
{
int i;
int ret;
-
+
if (prog->v.p.status == status_disabled)
return 1;
if (!prog->prereq)
@@ -1870,7 +1871,7 @@ prog_stop_dependents (struct prog *prog)
}
prog_stop (dp, SIGTERM);
}
- free (pos);
+ depmap_end (pos);
}
void
@@ -2009,7 +2010,7 @@ wordsplit_string (struct wordsplit const *ws)
{
char *ret, *p;
size_t count = ws->ws_wordc + ws->ws_offs;
- char **argv = xcalloc (count, sizeof (argv[0]));
+ char **argv = grecs_calloc (count, sizeof (argv[0]));
size_t i;
size_t len = 0;
@@ -2019,7 +2020,7 @@ wordsplit_string (struct wordsplit const *ws)
len += strlen (argv[i]);
}
len += count;
- ret = xmalloc (len);
+ ret = grecs_malloc (len);
for (i = 0, p = ret; i < count; i++)
{
@@ -2168,62 +2169,135 @@ send_msg (char *rcpts, const char *msg_text)
static const char default_termination_message[] =
"From: <>\n"
-"X-Agent: ${canonical-program-name} (${package} ${version})\n"
+"X-Agent: ${canonical_program_name} (${package} ${version})\n"
"Subject: Component ${component} ${termination} ${retcode}.\n"
"\n";
+
+struct notify_closure
+{
+ const char *tag;
+ int status;
+ struct action *act;
+};
-static void
-notify (const char *tag, int status, struct action *act)
+static int
+notify_get_tag (char **ret, void *data)
{
- struct metadef mdef[] =
- {
- { "canonical-program-name", "pies" },
- { "package", PACKAGE },
- { "version", PACKAGE_VERSION },
-#define COMPONENT_IDX 3
- { "component", NULL },
-#define TERMINATION_IDX 4
- { "termination", NULL },
-#define RETCODE_IDX 5
- { "retcode", NULL },
-#define PROGRAM_NAME_IDX 6
- { "program-name", NULL },
-#define INSTANCE_IDX 7
- { "instance", NULL },
- { NULL }
- };
-
- char *msg_text = NULL;
- char buf[INT_BUFSIZE_BOUND (uintmax_t)];
+ struct notify_closure const *clos = data;
+ char *s = strdup (clos->tag);
+ if (!s)
+ return WRDSE_NOSPACE;
+ *ret = s;
+ return WRDSE_OK;
+}
- mdef[COMPONENT_IDX].value = (char*) tag;
- mdef[INSTANCE_IDX].value = (char*) tag;
- if (WIFEXITED (status))
- {
- /* TRANSLATORS: The subject of this statement is 'component' */
- mdef[TERMINATION_IDX].value = (char*) _("exited with code");
- mdef[RETCODE_IDX].value = umaxtostr (WEXITSTATUS (status), buf);
- }
- else if (WIFSIGNALED (status))
- {
- /* TRANSLATORS: The subject of this statement is 'component' */
- mdef[TERMINATION_IDX].value = (char*) _("terminated on signal");
- mdef[RETCODE_IDX].value = umaxtostr (WTERMSIG (status), buf);
- }
+static int
+notify_get_termination (char **ret, void *data)
+{
+ struct notify_closure const *clos = data;
+ char const *msg;
+ char *s;
+
+ if (WIFEXITED (clos->status))
+ /* TRANSLATORS: The subject of this statement is 'component' */
+ msg = _("exited with code");
+ else if (WIFSIGNALED (clos->status))
+ /* TRANSLATORS: The subject of this statement is 'component' */
+ msg = _("terminated on signal");
else
- {
- mdef[TERMINATION_IDX].value = "UNKNOWN";
- mdef[RETCODE_IDX].value = "UNKNOWN";
- }
- mdef[PROGRAM_NAME_IDX].value = (char*) program_name;
- msg_text = meta_expand_string (act->message ?
- act->message : default_termination_message,
- mdef, NULL);
+ msg = "UNKNOWN";
- send_msg (act->addr, msg_text);
- free (msg_text);
+ s = strdup (msg);
+ if (!s)
+ return WRDSE_NOSPACE;
+ *ret = s;
+ return WRDSE_OK;
}
+
+static int
+notify_get_retcode (char **ret, void *data)
+{
+ struct notify_closure const *clos = data;
+ char *s = NULL;
+ size_t l = 0;
+
+ if (WIFEXITED (clos->status))
+ grecs_asprintf (&s, &l, "%d", WEXITSTATUS (clos->status));
+ else if (WIFSIGNALED (clos->status))
+ grecs_asprintf (&s, &l, "%d", WTERMSIG (clos->status));
+ else
+ s = strdup ("UNKNOWN");
+ if (!s)
+ return WRDSE_NOSPACE;
+ *ret = s;
+ return WRDSE_OK;
+}
+
+struct notify_variable
+{
+ char *name;
+ size_t name_length;
+ int (*get) (char **ret, void *data);
+};
+
+static struct notify_variable notify_vartab[] = {
+#define S(s) #s, sizeof(#s)-1
+ { S(component), notify_get_tag },
+ { S(termination), notify_get_termination },
+ { S(retcode), notify_get_retcode },
+#undef S
+ { NULL }
+};
+
+static int
+notify_getvar (char **ret, const char *vptr, size_t vlen, void *data)
+{
+ struct notify_variable *var;
+ for (var = notify_vartab; var->name; var++)
+ if (var->name_length == vlen && memcmp (var->name, vptr, vlen) == 0)
+ return var->get (ret, data);
+ return WRDSE_UNDEF;
+}
+
+static void
+notify (const char *tag, int status, struct action *act)
+{
+ const char *env[] = {
+#define PROGRAM_NAME_IDX 1
+ "program_name", NULL,
+#define INSTANCE_IDX 3
+ "instance", NULL,
+ "canonical_program_name", "pies",
+ "package", PACKAGE,
+ "version", PACKAGE_VERSION,
+ NULL
+ };
+ struct wordsplit ws;
+ struct notify_closure closure;
+ closure.tag = tag;
+ closure.status = status;
+ closure.act = act;
+
+ env[PROGRAM_NAME_IDX] = program_name;
+ env[INSTANCE_IDX] = instance;
+
+ ws.ws_env = env;
+ ws.ws_getvar = notify_getvar;
+ ws.ws_closure = &closure;
+ if (wordsplit (act->message ? act->message : default_termination_message,
+ &ws,
+ WRDSF_NOSPLIT | WRDSF_NOCMD | WRDSF_QUOTE |
+ WRDSF_ENV | WRDSF_ENV_KV |
+ WRDSF_GETVAR | WRDSF_CLOSURE))
+ {
+ logmsg (LOG_ERR, "wordsplit: %s", wordsplit_strerror (&ws));
+ return;
+ }
+ send_msg (act->addr, ws.ws_wordv[0]);
+ wordsplit_free (&ws);
+}
+
static int
status_matches_p (struct action *act, unsigned status)
{
@@ -2281,7 +2355,7 @@ run_command (struct action *act, struct prog *prog, unsigned retcode,
/* Master */
debug (1, (_("started command: %s, pid=%lu"),
act->command, (unsigned long) pid));
- register_command ((char*) _("[action]"), xstrdup (act->command), pid);
+ register_command ((char*) _("[action]"), grecs_strdup (act->command), pid);
}
static void
diff --git a/src/socket.c b/src/socket.c
index c94ad4b..f239074 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2007, 2008, 2009, 2010, 2013 Sergey Poznyakoff
+ Copyright (C) 2007-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
@@ -440,7 +440,7 @@ register_socket (int fd,
socket_handler_t ex,
void *data)
{
- struct sockinst *sip = xmalloc (sizeof *sip);
+ struct sockinst *sip = grecs_malloc (sizeof *sip);
sip->fd = fd;
sip->dead = 0;
sip->handler[PIES_EVT_RD] = rd;
diff --git a/src/sysvinit.c b/src/sysvinit.c
index faa504a..965bce2 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -366,37 +366,39 @@ envsetup ()
static void
sysvinit_setenv (char const *data, int size)
{
- int i, j;
+ int i, j;
- while (size) {
- char const *var = data;
- size_t len = strlen (var) + 1;
- size -= len;
- if (size < 0)
- break;
- data += len;
- if (strncmp (var, "INIT_", 5) != 0)
- continue;
- len = strcspn (var, "=");
- for (i = ENVI_AVAIL; i < NR_ENVHINT; i++) {
- char *s = sysvinit_environ_hint[i];
- if (s) {
- for (j = 0; *s && j < len; j++, s++)
- if (var[j] != *s) break;
- if (*s != '=' || j != len)
- continue;
- free (sysvinit_environ_hint[i]);
- }
-
- if (var[len] == '=')
- sysvinit_environ_hint[i] = xstrdup (var);
- else
- for (j = i + 1; j < NR_ENVHINT; j++, i++)
- sysvinit_environ_hint[i] =
- sysvinit_environ_hint[j];
- break;
- }
+ while (size)
+ {
+ char const *var = data;
+ size_t len = strlen (var) + 1;
+ size -= len;
+ if (size < 0)
+ break;
+ data += len;
+ if (strncmp (var, "INIT_", 5) != 0)
+ continue;
+ len = strcspn (var, "=");
+ for (i = ENVI_AVAIL; i < NR_ENVHINT; i++)
+ {
+ char *s = sysvinit_environ_hint[i];
+ if (s)
+ {
+ for (j = 0; *s && j < len; j++, s++)
+ if (var[j] != *s) break;
+ if (*s != '=' || j != len)
+ continue;
+ free (sysvinit_environ_hint[i]);
+ }
+
+ if (var[len] == '=')
+ sysvinit_environ_hint[i] = grecs_strdup (var);
+ else
+ for (j = i + 1; j < NR_ENVHINT; j++, i++)
+ sysvinit_environ_hint[i] = sysvinit_environ_hint[j];
+ break;
}
+ }
}
char *init_fifo = INIT_FIFO;
diff --git a/src/userprivs.c b/src/userprivs.c
index 5f56ce9..646421e 100644
--- a/src/userprivs.c
+++ b/src/userprivs.c
@@ -1,5 +1,5 @@
/* This file is part of GNU Pies.
- Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013 Sergey Poznyakoff
+ Copyright (C) 2007-2011, 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
@@ -33,7 +33,7 @@ get_user_groups (struct grecs_list *init_list, const char *user)
struct group *gr;
struct grecs_list *list;
- list = grecs_list_create();
+ list = grecs_list_create ();
if (init_list)
{
@@ -41,7 +41,7 @@ get_user_groups (struct grecs_list *init_list, const char *user)
for (ep = init_list->head; ep; ep = ep->next)
{
- grecs_list_append (list, xstrdup ((char*)ep->data));
+ grecs_list_append (list, grecs_strdup ((char*)ep->data));
}
}
@@ -52,7 +52,7 @@ get_user_groups (struct grecs_list *init_list, const char *user)
for (p = gr->gr_mem; *p; p++)
if (strcmp (*p, user) == 0)
{
- grecs_list_append (list, xstrdup (gr->gr_name));
+ grecs_list_append (list, grecs_strdup (gr->gr_name));
break;
}
}
@@ -70,7 +70,7 @@ switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups)
/* Create a list of supplementary groups */
size = 1 + (retain_groups ? grecs_list_size (retain_groups) : 0);
- emptygidset = xcalloc (size, sizeof emptygidset[0]);
+ emptygidset = grecs_calloc (size, sizeof emptygidset[0]);
emptygidset[0] = gid ? gid : getegid ();
if (retain_groups)
@@ -98,7 +98,7 @@ switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups)
(unsigned long) emptygidset[0], strerror (errno));
rc = 1;
}
- free (emptygidset);
+ grecs_free (emptygidset);
/* Switch to the user's gid. On some OSes the effective gid must
be reset first */

Return to:

Send suggestions and report system problems to the System administrator.