diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-22 23:03:24 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-23 00:42:30 +0300 |
commit | 21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee (patch) | |
tree | c3204285a3ba57d590d815c682f1113b6f48d834 /src | |
parent | eb8797c9a28f3f4e238bad89b56d331492df7828 (diff) | |
download | pies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.gz pies-21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee.tar.bz2 |
Switch to the latest Grecs.
* Makefile.am (ChangeLog): Use git2chg.awk to build it.
* NEWS: Update.
* bootstrap.conf (gnulib_modules): Grecs does not depend on gnulib any more.
* configure.ac: Version 1.2.90.
Define GRECS_HOST_PROJECT_INCLUDES, remove grecs Makefiles from
AC_CONFIG_FILES: it is now done by GRECS_SETUP itself.
* gnulib.modules (gitlog-to-changelog,argp): Remove.
(configmake): New module.
* grecs: Update to a52ab6c6.
* lib/libpies.h: Remove redefinitions of _() and N_().
* src/Makefile.am: Update for the recent grecs.
* src/acl.c: Rewrite using Grecs support for lists and symtabs.
* src/acl.h: Likewise.
* src/diag.c: Likewise.
* src/inetd.c: Likewise.
* src/meta1gram.y: Likewise.
* src/meta1lex.h: Likewise.
* src/meta1lex.l: Likewise.
* src/pies.c: Likewise.
* src/pies.h: Likewise.
* src/progman.c: Likewise.
* src/userprivs.c: Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 17 | ||||
-rw-r--r-- | src/acl.c | 206 | ||||
-rw-r--r-- | src/acl.h | 4 | ||||
-rw-r--r-- | src/cmdline.opt | 193 | ||||
-rw-r--r-- | src/diag.c | 40 | ||||
-rw-r--r-- | src/inetd.c | 18 | ||||
-rw-r--r-- | src/meta1gram.y | 47 | ||||
-rw-r--r-- | src/meta1lex.h | 3 | ||||
-rw-r--r-- | src/meta1lex.l | 55 | ||||
-rw-r--r-- | src/pies.c | 329 | ||||
-rw-r--r-- | src/pies.h | 12 | ||||
-rw-r--r-- | src/progman.c | 86 | ||||
-rw-r--r-- | src/userprivs.c | 49 |
14 files changed, 534 insertions, 526 deletions
diff --git a/src/.gitignore b/src/.gitignore index 18a7111..4ad4290 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1 +1,2 @@ +cmdline.h inetd diff --git a/src/Makefile.am b/src/Makefile.am index 19c6483..455b2c2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,3 @@ # This file is part of GNU Pies. -# Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff +# Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff # @@ -37,2 +37,3 @@ noinst_HEADERS = \ acl.h\ + cmdline.h\ meta1gram.h\ @@ -43,5 +44,13 @@ meta1lex.c: meta1gram.h +BUILT_SOURCES=cmdline.h + incdir=$(pkgdatadir)/$(VERSION)/include inc_DATA = pp-setup -EXTRA_DIST = pp-setup inetd.in +EXTRA_DIST = cmdline.opt pp-setup inetd.in + +SUFFIXES=.opt .c .h +.opt.h: + $(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@ + +cmdline.h: cmdline.opt @@ -51,3 +60,3 @@ INCLUDES = \ -I$(top_builddir)/gnu\ - -I$(top_srcdir)/grecs/src + @GRECS_INCLUDES@ @@ -55,3 +64,3 @@ LDADD = \ ../lib/libpies.a\ - ../grecs/src/libgrecs.a\ + @GRECS_LDADD@\ ../gnu/libgnu.a\ @@ -1,3 +1,3 @@ /* This file is part of GNU Pies - Copyright (C) 2009, 2010 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -27,3 +27,2 @@ #include <netdb.h> -#include <hash.h> @@ -42,4 +41,4 @@ struct acl_entry pies_acl_t acl; - gl_list_t groups; - gl_list_t sockaddrs; + struct grecs_list *groups; + struct grecs_list *sockaddrs; }; @@ -50,3 +49,3 @@ struct pies_acl grecs_locus_t locus; - gl_list_t list; + struct grecs_list *list; }; @@ -63,7 +62,3 @@ pies_acl_create (const char *name, grecs_locus_t *locus) acl->locus = *locus; - acl->list = gl_list_create_empty(&gl_linked_list_implementation, - NULL, - NULL, - NULL, - false); + acl->list = grecs_list_create (); return acl; @@ -71,2 +66,10 @@ pies_acl_create (const char *name, grecs_locus_t *locus) +void +pies_acl_free (pies_acl_t acl) +{ + free (acl->name); + grecs_list_free (acl->list); + free (acl); +} + static struct pies_sockaddr * @@ -191,3 +194,3 @@ _parse_sockaddr (struct acl_entry *entry, const grecs_value_t *value) } - gl_list_add_last (entry->sockaddrs, sptr); + grecs_list_append (entry->sockaddrs, sptr); return 0; @@ -196,3 +199,3 @@ _parse_sockaddr (struct acl_entry *entry, const grecs_value_t *value) static int -_parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) +_parse_from (struct acl_entry *entry, size_t argc, grecs_value_t **argv) { @@ -200,3 +203,3 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) return 0; - else if (argv->type == GRECS_TYPE_LIST) + else if (argv[0]->type == GRECS_TYPE_LIST) { @@ -205,6 +208,6 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) } - else if (strcmp (argv->v.string, "from")) + else if (strcmp (argv[0]->v.string, "from")) { grecs_error (&entry->locus, 0, _("expected `from', but found `%s'"), - argv->v.string); + argv[0]->v.string); return 1; @@ -221,10 +224,6 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) - entry->sockaddrs = gl_list_create_empty(&gl_linked_list_implementation, - NULL, - NULL, - NULL, - false); - if (argv->type == GRECS_TYPE_STRING) + entry->sockaddrs = grecs_list_create (); + if (argv[0]->type == GRECS_TYPE_STRING) { - if (_parse_sockaddr (entry, argv)) + if (_parse_sockaddr (entry, argv[0])) return 1; @@ -233,8 +232,7 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) { - gl_list_iterator_t itr = gl_list_iterator (argv->v.list); - const void *p; int rc = 0; - while (gl_list_iterator_next (&itr, &p, NULL)) - rc += _parse_sockaddr (entry, (const grecs_value_t*) p); - gl_list_iterator_free (&itr); + struct grecs_list_entry *ep; + + for (ep = argv[0]->v.list->head; ep; ep = ep->next) + rc += _parse_sockaddr (entry, (const grecs_value_t*) ep->data); if (rc) @@ -252,3 +250,3 @@ _parse_from (struct acl_entry *entry, size_t argc, const grecs_value_t *argv) static int -_parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) +_parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t **argv) { @@ -256,3 +254,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) return 0; - if (strcmp (argv->v.string, "acl") == 0) + if (strcmp (argv[0]->v.string, "acl") == 0) { @@ -267,3 +265,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) - if (argv->type != GRECS_TYPE_STRING) + if (argv[0]->type != GRECS_TYPE_STRING) { @@ -274,3 +272,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) - entry->acl = pies_acl_lookup (argv->v.string); + entry->acl = pies_acl_lookup (argv[0]->v.string); @@ -279,3 +277,3 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) grecs_error (&entry->locus, 0, _("ACL not defined: `%s'"), - argv->v.string); + argv[0]->v.string); return 1; @@ -289,5 +287,5 @@ _parse_sub_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) static int -_parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv) +_parse_group (struct acl_entry *entry, size_t argc, grecs_value_t **argv) { - if (strcmp (argv->v.string, "group") == 0) + if (strcmp (argv[0]->v.string, "group") == 0) { @@ -301,13 +299,9 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv) } - if (argv->type == GRECS_TYPE_STRING) + if (argv[0]->type == GRECS_TYPE_STRING) { - entry->groups = gl_list_create_empty(&gl_linked_list_implementation, - NULL, - NULL, - NULL, - false); - gl_list_add_last (entry->groups, (void *) argv->v.string); + entry->groups = grecs_list_create (); + grecs_list_append (entry->groups, xstrdup (argv[0]->v.string)); } else - entry->groups = argv->v.list; + entry->groups = argv[0]->v.list; argc--; @@ -319,7 +313,7 @@ _parse_group (struct acl_entry *entry, size_t argc, grecs_value_t * argv) static int -_parse_acl (struct acl_entry *entry, size_t argc, grecs_value_t *argv) +_parse_acl (struct acl_entry *entry, size_t argc, grecs_value_t **argv) { - if (assert_grecs_value_type (&entry->locus, argv, GRECS_TYPE_STRING)) + if (assert_grecs_value_type (&entry->locus, argv[0], GRECS_TYPE_STRING)) return 1; - else if (_parse_token (entry, argv) == 0) + else if (_parse_token (entry, argv[0]) == 0) return _parse_sub_acl (entry, argc - 1, argv + 1); @@ -358,3 +352,3 @@ parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl, } - gl_list_add_last (acl->list, entry); + grecs_list_append (acl->list, entry); return 0; @@ -375,3 +369,2 @@ _acl_common_section_parser (enum grecs_callback_command cmd, pies_acl_t acl; - grecs_locus_t defn_loc; const char *tag = NULL; @@ -414,11 +407,4 @@ _acl_common_section_parser (enum grecs_callback_command cmd, acl = pies_acl_create (tag, locus); - if (tag && pies_acl_install (acl, &defn_loc)) - { - grecs_error (locus, 0, - _("redefinition of ACL %s"), - value->v.string); - grecs_error (&defn_loc, 0, - _("location of the previous definition")); - return 1; - } + if (tag && (acl = pies_acl_install (acl)) == NULL) + return 1; if (pacl) @@ -572,7 +558,6 @@ _acl_check (struct acl_entry *ent, struct acl_input *input) { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (ent->groups); - while (result && gl_list_iterator_next (&itr, &p, NULL)) - result = match_group (input->groups, p); - gl_list_iterator_free (&itr); + struct grecs_list_entry *ep; + + for (ep = ent->groups->head; result && ep; ep = ep->next) + result = match_group (input->groups, ep->data); if (!result) @@ -587,8 +572,8 @@ _acl_check (struct acl_entry *ent, struct acl_input *input) { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (ent->sockaddrs); + struct grecs_list_entry *ep; + result = 0; - while (gl_list_iterator_next (&itr, &p, NULL)) + for (ep = ent->sockaddrs->head; ep; ep = ep->next) { - result = _check_sockaddr ((struct pies_sockaddr *)p, input); + result = _check_sockaddr ((struct pies_sockaddr *)ep->data, input); if (result) @@ -596,3 +581,2 @@ _acl_check (struct acl_entry *ent, struct acl_input *input) } - gl_list_iterator_free (&itr); } @@ -606,3 +590,3 @@ _acl_check_cb (struct acl_entry *ent, struct acl_input *input, int *pres) int result = _acl_check (ent, input); - debug (1, ("%s:%d: %s", ent->locus.file, ent->locus.line, + debug (1, ("%s:%d: %s", ent->locus.beg.file, ent->locus.beg.line, /* TRANSLATORS: `MATCHES' is the verb `match' in 2nd person. @@ -624,8 +608,7 @@ pies_acl_check (pies_acl_t acl, struct acl_input *input, int result) { - const void *p; - gl_list_iterator_t itr = gl_list_iterator (acl->list); - while (gl_list_iterator_next (&itr, &p, NULL) - && !_acl_check_cb ((struct acl_entry *)p, input, &result)) - ; - gl_list_iterator_free (&itr); + struct grecs_list_entry *ep; + + for (ep = acl->list->head; ep; ep = ep->next) + if (_acl_check_cb ((struct acl_entry *)ep->data, input, &result)) + break; } @@ -637,10 +620,10 @@ pies_acl_check (pies_acl_t acl, struct acl_input *input, int result) -static Hash_table *acl_table; +static struct grecs_symtab *acl_table; /* Calculate the hash of a string. */ -static size_t -acl_hasher (void const *data, size_t n_buckets) +static unsigned +acl_hasher (void *data, unsigned long n_buckets) { const struct pies_acl *p = data; - return hash_string (p->name, n_buckets); + return grecs_hash_string (p->name, n_buckets); } @@ -648,3 +631,3 @@ acl_hasher (void const *data, size_t n_buckets) /* Compare two strings for equality. */ -static bool +static int acl_compare (void const *data1, void const *data2) @@ -653,23 +636,58 @@ acl_compare (void const *data1, void const *data2) const struct pies_acl *p2 = data2; - return strcasecmp (p1->name, p2->name) == 0; + return strcasecmp (p1->name, p2->name); } -int -pies_acl_install (pies_acl_t acl, grecs_locus_t * locus) +static int +acl_copy (void *a, void *b) +{ + const struct pies_acl *pb = b; + + memcpy (a, b, sizeof (struct pies_acl)); + memset (b, 0, sizeof (struct pies_acl)); + return 0; +} + +static void +acl_free_entry (void *p) +{ + pies_acl_free (p); +} + +pies_acl_t +pies_acl_install (pies_acl_t acl) { pies_acl_t ret; - if (!((acl_table - || (acl_table = hash_initialize (0, 0, - acl_hasher, - acl_compare, 0))) - && (ret = hash_insert (acl_table, acl)))) - xalloc_die (); - - if (ret != acl) + int install = 1; + + if (!acl_table) { - if (locus) - *locus = ret->locus; - return 1; + acl_table = grecs_symtab_create(sizeof (struct pies_acl), + acl_hasher, + acl_compare, + acl_copy, + NULL, + acl_free_entry); + if (!acl_table) + xalloc_die (); } - return 0; + + ret = grecs_symtab_lookup_or_install (acl_table, acl, &install); + + if (!ret) + { + logmsg (LOG_ERR, _("cannot install acl: %s"), strerror (errno)); + exit (1); + } + + if (!install) + { + grecs_error (&acl->locus, 0, + _("redefinition of ACL %s"), + ret->name); + grecs_error (&ret->locus, 0, + _("location of the previous definition")); + ret = NULL; + } + pies_acl_free (acl); + return ret; } @@ -683,3 +701,3 @@ pies_acl_lookup (const char *name) samp.name = (char *) name; - return hash_lookup (acl_table, &samp); + return grecs_symtab_lookup_or_install (acl_table, &samp, NULL); } @@ -1,3 +1,3 @@ /* This file is part of GNU Pies - Copyright (C) 2009, 2010 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -32,3 +32,3 @@ int parse_acl_line (grecs_locus_t *locus, int allow, pies_acl_t acl, pies_acl_t pies_acl_lookup (const char *name); -int pies_acl_install (pies_acl_t acl, grecs_locus_t * locus); +pies_acl_t pies_acl_install (pies_acl_t acl); diff --git a/src/cmdline.opt b/src/cmdline.opt new file mode 100644 index 0000000..31fcf20 --- /dev/null +++ b/src/cmdline.opt @@ -0,0 +1,193 @@ +/* This file is part of GNU Pies. -*- c -*- + Copyright (C) 2008, 2009, 2010, 2011 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/>. */ + +OPTIONS_BEGIN("pies", + [<process invocation and execution supervisor>], + [<>], + [<gnu>], + [<copyright_year=2011>], + [<copyright_holder=Sergey Poznyakoff>]) + +GROUP(Operation Mode) + +OPTION(config-file,c,FILE, + [<use FILE instead of the default configuration>]) +BEGIN + add_config (current_syntax, optarg); +END + +OPTION(config-help,,, + [<show configuration file summary>]) +BEGIN + config_help (); + exit (0); +END + +OPTION(,E,, + [<preprocess config and exit>]) +BEGIN + preprocess_only = 1; +END + +OPTION(force,,, + [<force startup even if another instance may be running>]) +BEGIN + force_option = 1; +END + +OPTION(foreground,,, + [<remain in foreground>]) +BEGIN + log_to_stderr_only = 1; + foreground = 1; +END + +OPTION(inetd,i,, + [<run in inetd mode>]) +BEGIN + if (!instance) + instance = "inetd"; + current_syntax = CONF_INETD; + inetd_mode = 1; +END + +OPTION(instance,,NAME, + [<set instance name>]) +BEGIN + instance = optarg; +END + +OPTION(rate,,NUMBER, + [<set default maximum rate for inetd-style components>]) +BEGIN + char *p; + default_max_rate = strtoul (optarg, &p, 10); + if (*p) + { + logmsg (LOG_ERR, _("not a number: %s"), optarg); + exit (EX_USAGE); + } +END + +OPTION(stderr,,, + [<log to stderr>]) +BEGIN + log_to_stderr_only = 1; +END + +OPTION(syntax,,[<{pies|inetd|meta1}>], + [<expect configuration files in the given syntax>]) +BEGIN + if (str_to_config_syntax (optarg, ¤t_syntax)) + { + logmsg (LOG_ERR, _("unknown syntax type: %s"), optarg); + exit (EX_USAGE); + } +END + +OPTION(syslog,,, + [<log to syslog>]) +BEGIN + log_to_stderr_only = 0; +END + +OPTION(lint,t,, + [<parse configuration file and exit>]) +BEGIN + log_to_stderr_only = 1; + lint_mode = 1; +END + +GROUP(Preprocessor) + +OPTION(define,D,[<NAME[=VALUE]>], + [<define a preprocessor symbol NAME as having VALUE or empty>]) +BEGIN + add_pp_option ("-D", optarg); +END + +OPTION(undefine,U,NAME, + [<undefine a preprocessor symbol NAME>]) +BEGIN + add_pp_option ("-U", optarg); +END + +GROUP(Component Management) + +OPTION(reload,r,, + [<reload the running instance of pies>]) +ALIAS(hup) +BEGIN + log_to_stderr_only = 1; + command = COM_RELOAD; +END + +OPTION(restart-component,R,, + [<restart components named in the command line>]) +BEGIN + log_to_stderr_only = 1; + command = COM_RESTART; +END + +OPTION(status,s,, + [<display info about the running instance>]) +BEGIN + log_to_stderr_only = 1; + command = COM_STATUS; +END + +OPTION(stop,S,, + [<stop the running instance>]) +BEGIN + log_to_stderr_only = 1; + command = COM_STOP; +END + +GROUP(Debugging and Additional Diagnostics) + +OPTION(dump-depmap,,, + [<dump dependency map>]) +BEGIN + log_to_stderr_only = 1; + command = COM_DUMP_DEPMAP; +END + +OPTION(dump-prereq,,, + [<dump prerequisite charts>]) +BEGIN + log_to_stderr_only = 1; + command = COM_DUMP_PREREQ; +END + +OPTION(source-info,,, + [<show source info with debugging messages>]) +BEGIN + source_info_option = 1; +END + +OPTION(debug,x,LEVEL, + [<set debug verbosity level>]) +BEGIN + debug_level = strtoul (optarg, NULL, 0); +END + +OPTIONS_END + +void +parse_options(int argc, char *argv[], int *index) +{ + GETOPT(argc, argv, *index) +} @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2009, 2010 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -127,11 +127,39 @@ grecs_print_diag (grecs_locus_t *locus, int err, int errcode, const char *msg) { + char *locstr = NULL; + if (locus) { + size_t size = 0; + + if (locus->beg.col == 0) + grecs_asprintf (&locstr, &size, "%s:%u", + locus->beg.file, + locus->beg.line); + else if (strcmp (locus->beg.file, locus->end.file)) + grecs_asprintf (&locstr, &size, "%s:%u.%u-%s:%u.%u", + locus->beg.file, + locus->beg.line, locus->beg.col, + locus->end.file, + locus->end.line, locus->end.col); + else if (locus->beg.line != locus->end.line) + grecs_asprintf (&locstr, &size, "%s:%u.%u-%u.%u", + locus->beg.file, + locus->beg.line, locus->beg.col, + locus->end.line, locus->end.col); + else + grecs_asprintf (&locstr, &size, "%s:%u.%u-%u", + locus->beg.file, + locus->beg.line, locus->beg.col, + locus->end.col); + } + + if (locstr) + { if (errcode) - logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s: %s", - locus->file, (unsigned long)locus->line, msg, - strerror (errcode)); + logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s: %s", + locstr, msg, strerror (errcode)); else - logmsg (err ? LOG_ERR : LOG_WARNING, "%s:%lu: %s", - locus->file, (unsigned long)locus->line, msg); + logmsg (err ? LOG_ERR : LOG_WARNING, "%s: %s", + locstr, msg); + free (locstr); } diff --git a/src/inetd.c b/src/inetd.c index 012266a..1d7798d 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2009, 2010 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -30,7 +30,7 @@ -/* FIXME: Duplicated in grex-lex.l */ +/* FIXME: Copied from grecs/src/tree.c */ static void -listel_dispose(const void *el) +listel_dispose(void *el) { - free((void*)el); + free(el); } @@ -283,9 +283,5 @@ inetd_conf_file (const char *file) { - comp->privs.groups = - gl_list_create_empty (&gl_linked_list_implementation, - NULL, - NULL, - listel_dispose, - true); - gl_list_add_last (comp->privs.groups, xstrdup (group)); + comp->privs.groups = grecs_list_create (); + comp->privs.groups->free_entry = listel_dispose; + grecs_list_append (comp->privs.groups, xstrdup (group)); } diff --git a/src/meta1gram.y b/src/meta1gram.y index 6256448..deaf382 100644 --- a/src/meta1gram.y +++ b/src/meta1gram.y @@ -2,3 +2,3 @@ /* MeTA1 configuration parser for GNU Pies. - Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff @@ -22,4 +22,6 @@ #include "pies.h" +#include "grecs-locus.h" #include "meta1lex.h" - +#include "meta1gram.h" + #define META1_QUEUE_DIR() \ @@ -53,3 +55,3 @@ meta1_stmt_create (enum meta1_stmt_type type, const char *ident) p->ident = ident; - p->locus = meta1_locus; + p->locus = meta1lloc; return p; @@ -86,5 +88,8 @@ static void meta1_translate (struct meta1_stmt *); +%error-verbose +%locations + %union { char *string; - gl_list_t list; + struct grecs_list *list; grecs_value_t *value; @@ -170,9 +175,9 @@ string : META1_IDENT { - const void *p; - gl_list_iterator_t itr = gl_list_iterator ($1); - + struct grecs_list_entry *ep; meta1_line_begin (); - while (gl_list_iterator_next (&itr, &p, NULL)) - meta1_line_add (p, strlen (p)); - gl_list_iterator_free (&itr); + for (ep = $1->head; ep; ep = ep->next) + { + const char *p = ep->data; + meta1_line_add (p, strlen (p)); + } $$ = meta1_line_finish (); @@ -183,8 +188,4 @@ slist : META1_STRING { - $$ = gl_list_create_empty (&gl_linked_list_implementation, - NULL, - NULL, - NULL, - true); - gl_list_add_last ($$, $1); + $$ = grecs_list_create (); + grecs_list_append ($$, $1); } @@ -192,3 +193,3 @@ slist : META1_STRING { - gl_list_add_last ($1, $2); + grecs_list_append ($1, $2); $$ = $1; @@ -209,8 +210,4 @@ values : value { - $$ = gl_list_create_empty (&gl_linked_list_implementation, - NULL, - NULL, - NULL, - true); - gl_list_add_last ($$, $1); + $$ = grecs_list_create (); + grecs_list_append ($$, $1); } @@ -218,3 +215,3 @@ values : value { - gl_list_add_last ($1, $3); + grecs_list_append ($1, $3); $$ = $1; @@ -231,3 +228,3 @@ yyerror (char *s) { - meta1_parse_error ("%s", s); + grecs_error (&yylloc, 0, "%s", s); return 0; diff --git a/src/meta1lex.h b/src/meta1lex.h index 0f7c75d..213fb40 100644 --- a/src/meta1lex.h +++ b/src/meta1lex.h @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2009, 2010, 2009 Sergey Poznyakoff + Copyright (C) 2009, 2010, 2011 Sergey Poznyakoff @@ -16,3 +16,2 @@ -extern grecs_locus_t meta1_locus; extern size_t meta1_error_count; diff --git a/src/meta1lex.l b/src/meta1lex.l index 4eca9e2..7faaf41 100644 --- a/src/meta1lex.l +++ b/src/meta1lex.l @@ -3,3 +3,3 @@ /* MeTA1 configuration lexer for GNU Pies. - Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff @@ -28,2 +28,3 @@ #include "pies.h" +#include "grecs-locus.h" #include "meta1gram.h" @@ -31,4 +32,3 @@ -grecs_locus_t meta1_locus; -size_t meta1_error_count; +static struct grecs_locus_point meta1_locus_point; struct obstack meta1_stk; @@ -36,4 +36,15 @@ int meta1_stk_init; char *meta1_queue_dir; - #define yylval meta1lval + +#define YY_USER_ACTION do \ + { \ + if (YYSTATE == 0) \ + { \ + meta1lloc.beg = meta1_locus_point; \ + meta1lloc.beg.col++; \ + } \ + meta1_locus_point.col += yyleng; \ + meta1lloc.end = meta1_locus_point; \ + } \ + while (0); %} @@ -47,6 +58,6 @@ X [0-9a-fA-F] <COMMENT>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ -<COMMENT>\n ++meta1_locus.line; +<COMMENT>\n grecs_locus_point_advance_line(meta1_locus_point); <COMMENT>"*"+"/" BEGIN (INITIAL); /* End-of-line comments */ -#.*\n { meta1_locus.line++; } +#.*\n grecs_locus_point_advance_line(meta1_locus_point); #.* /* end-of-file comment */; @@ -84,3 +95,3 @@ X [0-9a-fA-F] <STR>[^\\"\n]*\n { BEGIN (INITIAL); - meta1_parse_error (_("newline in a string")); + grecs_error (&meta1lloc, 0, _("newline in a string")); meta1_line_add (yytext, yyleng - 1); @@ -90,8 +101,8 @@ X [0-9a-fA-F] [ \t\f][ \t\f]* ; -\n { meta1_locus.line++; } +\n grecs_locus_point_advance_line(meta1_locus_point); [,;{}=] return yytext[0]; . { if (isascii (yytext[0]) && isprint (yytext[0])) - meta1_parse_error (_("stray character %c"), yytext[0]); + grecs_error (&meta1lloc, 0, _("stray character %c"), yytext[0]); else - meta1_parse_error (_("stray character \\%03o"), + grecs_error (&meta1lloc, 0, _("stray character \\%03o"), (unsigned char) yytext[0]); } @@ -137,3 +148,3 @@ unescape_to_line (int c) if (t == c && t != '\\' && t != '\"') - meta1_parse_error (_("unknown escape sequence '\\%c'"), c); + grecs_error (&meta1lloc, 0, _("unknown escape sequence '\\%c'"), c); } @@ -184,16 +195,2 @@ meta1_string (const char *str, size_t len) void -meta1_parse_error (const char *fmt, ...) -{ - va_list ap; - - logmsg_printf (LOG_ERR, "%s:%lu: ", meta1_locus.file, - (unsigned long) meta1_locus.line); - va_start (ap, fmt); - logmsg_vprintf (LOG_ERR, fmt, ap); - va_end (ap); - logmsg_printf (LOG_ERR, "\n"); - meta1_error_count++; -} - -void meta1_lexer_set_debug () @@ -219,4 +216,5 @@ meta1_config_parse (const char *name) } - meta1_locus.file = meta1_string (name, strlen (name)); - meta1_locus.line = 1; + meta1_locus_point.file = meta1_string (name, strlen (name)); + meta1_locus_point.line = 1; + meta1_locus_point.col = 0; meta1_lexer_set_debug (); @@ -225,5 +223,6 @@ meta1_config_parse (const char *name) yyrestart (fp); + grecs_error_count = 0; rc = meta1parse (); fclose (fp); - if (meta1_error_count) + if (grecs_error_count) rc = 1; @@ -1,3 +1,3 @@ /* This file is part of GNU Pies. - Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff + Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff @@ -28,3 +28,14 @@ struct pies_privs pies_privs; int foreground; -int command; + +enum pies_command { + COM_START, + COM_RESTART, + COM_RELOAD, + COM_STATUS, + COM_STOP, + COM_DUMP_PREREQ, + COM_DUMP_DEPMAP +}; + +enum pies_command command; char *statedir = DEFAULT_STATE_DIR; @@ -147,5 +158,2 @@ stderr_closed_p () -#define GRECS_VALUE_IS_EMPTY(val) \ - (!(val) || ((val)->type == GRECS_TYPE_STRING && !(val)->v.string)) - int @@ -154,3 +162,3 @@ assert_grecs_value_type (grecs_locus_t *locus, { - if (GRECS_VALUE_IS_EMPTY (value)) + if (GRECS_VALUE_EMPTY_P (value)) { @@ -414,5 +422,5 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus) { - if (assert_grecs_value_type (locus, &val->v.arg.v[num], + if (assert_grecs_value_type (locus, val->v.arg.v[num], GRECS_TYPE_STRING) == 0) - return val->v.arg.v[num].v.string; + return val->v.arg.v[num]->v.string; } @@ -424,3 +432,3 @@ _get_list_arg (grecs_value_t *val, int num, grecs_locus_t *locus) { - grecs_value_t *elt = (grecs_value_t *) gl_list_get_at (val->v.list, num); + grecs_value_t *elt = (grecs_value_t *) grecs_list_index (val->v.list, num); if (!elt) @@ -447,3 +455,3 @@ return_code_section_parser (enum grecs_callback_command cmd, case grecs_callback_section_begin: - if (GRECS_VALUE_IS_EMPTY (value)) + if (GRECS_VALUE_EMPTY_P (value)) { @@ -465,3 +473,3 @@ return_code_section_parser (enum grecs_callback_command cmd, case GRECS_TYPE_LIST: - count = gl_list_size (value->v.list); + count = grecs_list_size (value->v.list); act = create_action (comp, locus, value, count, _get_list_arg); @@ -499,5 +507,5 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc) { - if (assert_grecs_value_type (locus, &val->v.arg.v[i], GRECS_TYPE_STRING) + 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++] = xstrdup (val->v.arg.v[i]->v.string); } @@ -704,8 +712,8 @@ _cb_redir (enum grecs_callback_command cmd, case GRECS_TYPE_ARRAY: - if (assert_grecs_value_type (locus, &value->v.arg.v[0], + if (assert_grecs_value_type (locus, value->v.arg.v[0], GRECS_TYPE_STRING)) return 0; - if (strtotok (redirtab, value->v.arg.v[0].v.string, &res)) + if (strtotok (redirtab, value->v.arg.v[0]->v.string, &res)) grecs_error (locus, 0, _("%s: unrecognised redirector type"), - value->v.arg.v[0].v.string); + value->v.arg.v[0]->v.string); else @@ -719,3 +727,3 @@ _cb_redir (enum grecs_callback_command cmd, } - if (assert_grecs_value_type (locus, &value->v.arg.v[1], + if (assert_grecs_value_type (locus, value->v.arg.v[1], GRECS_TYPE_STRING)) @@ -729,3 +737,3 @@ _cb_redir (enum grecs_callback_command cmd, case redir_syslog: - if (string_to_syslog_priority (value->v.arg.v[1].v.string, + if (string_to_syslog_priority (value->v.arg.v[1]->v.string, &rp->v.prio)) @@ -734,3 +742,3 @@ _cb_redir (enum grecs_callback_command cmd, _("unknown syslog priority `%s'"), - value->v.arg.v[1].v.string); + value->v.arg.v[1]->v.string); return 0; @@ -740,3 +748,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 = xstrdup (value->v.arg.v[1]->v.string); break; @@ -912,8 +920,7 @@ |