aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-22 23:03:24 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-10-23 00:42:30 +0300
commit21ffba77b92f79a59c62728ede4ad7a4ecb5a0ee (patch)
treec3204285a3ba57d590d815c682f1113b6f48d834 /src/pies.c
parenteb8797c9a28f3f4e238bad89b56d331492df7828 (diff)
downloadpies-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/pies.c')
-rw-r--r--src/pies.c329
1 files changed, 52 insertions, 277 deletions
diff --git a/src/pies.c b/src/pies.c
index 112bfb6..cc2c26b 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1,8 +1,8 @@
/* This file is part of GNU Pies.
- Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff
+ 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.
@@ -23,13 +23,24 @@ int preprocess_only; /* Preprocess config, do nothing more */
int lint_mode; /* Test configuration syntax and exit */
int log_to_stderr_only; /* Use only stderr for logging */
int log_facility = LOG_USER;
char *log_tag;
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;
char *instance;
char *pidfile;
char *ctlfile;
char *statfile;
char *qotdfile;
@@ -142,20 +153,17 @@ stderr_closed_p ()
return 1;
close (fd);
return fd <= 2;
}
-#define GRECS_VALUE_IS_EMPTY(val) \
- (!(val) || ((val)->type == GRECS_TYPE_STRING && !(val)->v.string))
-
int
assert_grecs_value_type (grecs_locus_t *locus,
const grecs_value_t *value, int type)
{
- if (GRECS_VALUE_IS_EMPTY (value))
+ if (GRECS_VALUE_EMPTY_P (value))
{
grecs_error (locus, 0, _("expected %s"),
grecs_data_type_string (type));
return 1;
}
if (value->type != type)
@@ -409,23 +417,23 @@ _get_string_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
const char *
_get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
{
if (num < val->v.arg.c)
{
- 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;
}
return NULL;
}
const char *
_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)
{
grecs_error (locus, 0, _("cannot get list item"));
}
else if (assert_grecs_value_type (locus, elt, GRECS_TYPE_STRING) == 0)
return elt->v.string;
@@ -442,13 +450,13 @@ return_code_section_parser (enum grecs_callback_command cmd,
size_t count;
struct action *act;
switch (cmd)
{
case grecs_callback_section_begin:
- if (GRECS_VALUE_IS_EMPTY (value))
+ if (GRECS_VALUE_EMPTY_P (value))
{
grecs_error (locus, 0, _("missing tag"));
return 1;
}
switch (value->type)
@@ -460,13 +468,13 @@ return_code_section_parser (enum grecs_callback_command cmd,
case GRECS_TYPE_ARRAY:
act = create_action (comp, locus, value,
value->v.arg.c, _get_array_arg);
break;
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);
}
*(struct component **) cb_data = comp;
if (!act)
return 1;
memset (&comp->act_temp, 0, sizeof (comp->act_temp));
@@ -494,15 +502,15 @@ 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]));
for (i = j = 0; i < argc; i++)
{
- 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);
}
argv[j] = NULL;
if (pargc)
*pargc = argc;
return argv;
}
@@ -699,49 +707,49 @@ _cb_redir (enum grecs_callback_command cmd,
value->v.string);
return 0;
}
break;
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
{
if (res != redir_null)
{
if (value->v.arg.c != 2)
{
grecs_error (locus, 0, _("wrong number of arguments"));
return 0;
}
- 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))
return 0;
switch (res)
{
case redir_null:
break;
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))
{
grecs_error (locus, 0,
_("unknown syslog priority `%s'"),
- value->v.arg.v[1].v.string);
+ value->v.arg.v[1]->v.string);
return 0;
}
break;
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;
}
}
rp->type = res;
}
break;
@@ -907,18 +915,17 @@ _cb_flags (enum grecs_callback_command cmd,
return 1;
}
break;
case GRECS_TYPE_LIST:
{
- const void *p;
- gl_list_iterator_t itr = gl_list_iterator (value->v.list);
-
- while (gl_list_iterator_next (&itr, &p, NULL))
+ struct grecs_list_entry *ep;
+
+ for (ep = value->v.list->head; ep; ep = ep->next)
{
- const grecs_value_t *vp = p;
+ const grecs_value_t *vp = ep->data;
if (assert_grecs_value_type (locus, vp, GRECS_TYPE_STRING))
return 1;
if (str_to_cf (vp->v.string, flags))
{
grecs_error (locus, 0, _("%s: unrecognised flag"),
vp->v.string);
@@ -1557,13 +1564,12 @@ struct grecs_keyword pies_keywords[] = {
{NULL}
};
void
config_init ()
{
- grecs_set_keywords (pies_keywords);
grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR,
DEFAULT_INCLUDE_DIR, NULL);
grecs_log_to_stderr = log_to_stderr_only;
if (DEFAULT_PREPROCESSOR)
{
obstack_init (&pp_stk);
@@ -1576,225 +1582,20 @@ void
config_help ()
{
static char docstring[] =
/* TRANSLATORS: do not translate words between ` and ' */
N_("Configuration file structure for pies.\n"
"For more information, use `info pies configuration'.");
- grecs_format_docstring (stdout, docstring, 0);
- grecs_format_statement_array (stdout, pies_keywords, 1, 0);
+ grecs_print_docstring (docstring, 0, stdout);
+ grecs_print_statement_array (pies_keywords, 1, 0, stdout);
}
-
-const char *program_version = "pies (" PACKAGE_STRING ")";
-const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
-static char doc[] = N_("pies -- process invocation and execution supervisor");
-static char args_doc[] = "";
-
-enum
-{
- OPT_FOREGROUND = 256,
- OPT_SYNTAX,
- OPT_SYSLOG,
- OPT_STDERR,
- OPT_DUMP_PREREQ,
- OPT_DUMP_DEPMAP,
- OPT_FORCE,
- OPT_CONFIG_HELP,
- OPT_SOURCE_INFO,
- OPT_RATE,
- OPT_INSTANCE
-};
-
-#define OPT_RESTART 'R'
-#define OPT_RELOAD 'r'
-#define OPT_STATUS 's'
-#define OPT_STOP 'S'
-
-static struct argp_option options[] = {
-#define GRP 0
- {NULL, 0, NULL, 0, N_("Operation Mode"), GRP},
- {"foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP + 1},
- {"stderr", OPT_STDERR, NULL, 0, N_("log to stderr"),},
- {"syslog", OPT_SYSLOG, NULL, 0, N_("log to syslog"),},
- {"force", OPT_FORCE, NULL, 0,
- N_("force startup even if another instance may be running"), GRP + 1},
- {"lint", 't', NULL, 0,
- N_("parse configuration file and exit"), GRP + 1},
- {NULL, 'E', NULL, 0,
- N_("preprocess config and exit"), GRP + 1},
- {"inetd", 'i', NULL, 0,
- N_("run in inetd mode"), GRP + 1},
- {"config-file", 'c', N_("FILE"), 0,
- N_("use FILE instead of the default configuration"), GRP + 1},
- {"config-help", OPT_CONFIG_HELP, NULL, 0,
- N_("show configuration file summary"), GRP + 1},
- {"syntax", OPT_SYNTAX, "{pies|inetd|meta1}", 0,
- N_("expect configuration files in the given syntax"), GRP+1 },
- {"rate", OPT_RATE, N_("NUMBER"), 0,
- N_("set default maximum rate for inetd-style components"),
- GRP + 1},
- {"instance", OPT_INSTANCE, N_("NAME"), 0,
- N_("set instance name"),
- GRP + 1},
-#undef GRP
-
-#define GRP 5
- {NULL, 0, NULL, 0, N_("Preprocessor"), GRP},
- {"define", 'D', N_("NAME[=VALUE]"), 0,
- N_("define a preprocessor symbol NAME as having VALUE, or empty"), GRP+1 },
- {"undefine", 'U', N_("NAME"), 0,
- N_("undefine a preprocessor symbol NAME"), GRP+1 },
-#undef GRP
-
-#define GRP 10
- {NULL, 0, NULL, 0, N_("Component Management"), GRP},
- {"restart-component", OPT_RESTART, NULL, 0,
- N_("restart components named in the command line"), GRP + 1},
- {"reload", OPT_RELOAD, NULL, 0,
- N_("reload the running instance of pies "), GRP + 1},
- {"hup", 0, NULL, OPTION_ALIAS},
- {"status", OPT_STATUS, NULL, 0,
- N_("display info about the running instance "), GRP + 1},
- {"stop", OPT_STOP, NULL, 0,
- N_("stop the running instance "), GRP + 1},
-#undef GRP
-
-#define GRP 20
- {NULL, 0, NULL, 0, N_("Debugging and Additional Diagnostics"), GRP},
- {"debug", 'x', N_("LEVEL"), 0,
- N_("set debug verbosity level"), GRP + 1},
- {"source-info", OPT_SOURCE_INFO, NULL, 0,
- N_("show source info with debugging messages"), GRP + 1},
- {"dump-prereq", OPT_DUMP_PREREQ, NULL, 0,
- N_("dump prerequisite charts"), GRP + 1},
- {"dump-depmap", OPT_DUMP_DEPMAP, NULL, 0,
- N_("dump dependency map"), GRP + 1},
-#undef GRP
- {NULL}
-};
-
static enum config_syntax current_syntax = CONF_PIES;
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
- char *p;
-
- switch (key)
- {
- case 'c':
- add_config (current_syntax, arg);
- break;
-
- case 'D':
- add_pp_option ("-D", arg);
- break;
-
- case 'U':
- add_pp_option ("-U", arg);
- break;
-
- case 'E':
- preprocess_only = 1;
- break;
-
- case 'i':
- if (!instance)
- instance = "inetd";
- current_syntax = CONF_INETD;
- inetd_mode = 1;
- break;
-
- case 't':
- log_to_stderr_only = 1;
- lint_mode = 1;
- break;
-
- case OPT_CONFIG_HELP:
- config_help ();
- exit (0);
-
- case OPT_FOREGROUND:
- log_to_stderr_only = 1;
- foreground = 1;
- break;
-
- case OPT_INSTANCE:
- instance = arg;
- break;
-
- case OPT_SYNTAX:
- if (str_to_config_syntax (arg, &current_syntax))
- {
- logmsg (LOG_ERR, _("unknown syntax type: %s"), arg);
- exit (EX_USAGE);
- }
- break;
-
- case OPT_RELOAD:
- case OPT_STATUS:
- case OPT_STOP:
- case OPT_RESTART:
- case OPT_DUMP_PREREQ:
- case OPT_DUMP_DEPMAP:
- log_to_stderr_only = 1;
- command = key;
- break;
-
- case OPT_SYSLOG:
- log_to_stderr_only = 0;
- break;
-
- case OPT_STDERR:
- log_to_stderr_only = 1;
- break;
-
- case 'x':
- debug_level = strtoul (arg, NULL, 0);
- break;
-
- case OPT_RATE:
- default_max_rate = strtoul (arg, &p, 10);
- if (*p)
- {
- logmsg (LOG_ERR, _("not a number: %s"), arg);
- exit (EX_USAGE);
- }
- break;
-
- case OPT_SOURCE_INFO:
- source_info_option = 1;
- break;
-
- case OPT_FORCE:
- force_option = 1;
- break;
-
- case ARGP_KEY_INIT:
- break;
-
- case ARGP_KEY_FINI:
- break;
-
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
-}
-
-static struct argp argp = {
- options,
- parse_opt,
- args_doc,
- doc,
- NULL,
- NULL,
- NULL
-};
+#include "cmdline.h"
-
#define ACTION_CONT 0
#define ACTION_STOP 1
#define ACTION_RESTART 2
#define ACTION_COMPRELOAD 3
#define ACTION_DUMPSTATS 4
@@ -2153,40 +1954,12 @@ set_mailer_argcv ()
mailer_argv[i] = xstrdup (ws.ws_wordv[i]);
mailer_argv[i] = NULL;
wordsplit_free (&ws);
}
-const char version_etc_copyright[] =
- /* Do *not* mark this string for translation. %s is a copyright
- symbol suitable for this locale */
- "Copyright %s 2009 Sergey Poznyakoff";
-
-
-static void
-version (FILE *stream, struct argp_state *state)
-{
- fprintf (stream, "%s (%s) %s\n", PACKAGE, PACKAGE_NAME, PACKAGE_VERSION);
- /* TRANSLATORS: Translate "(C)" to the copyright symbol
- (C-in-a-circle), if this symbol is available in the user's
- locale. Otherwise, do not translate "(C)"; leave it as-is. */
- fprintf (stream, version_etc_copyright, _("(C)"));
-
- fputs (_("\
-\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
-This is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law.\n\
-\n\
-"),
- stream);
-
- /* TRANSLATORS: %s denotes an author name. */
- fprintf (stream, _("Written by %s.\n"), "Sergey Poznyakoff");
-}
-
static char *
mkfilename (const char *dir, const char *name, const char *suf)
{
size_t dirlen = strlen (dir);
char *s;
@@ -2245,16 +2018,14 @@ main (int argc, char **argv)
set_quoting_style (NULL, shell_quoting_style);
/* Set default logging */
diag_setup (DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR));
config_init ();
- argp_program_version_hook = version;
- if (argp_parse (&argp, argc, argv, 0, &index, NULL))
- exit (EX_USAGE);
-
+ parse_options (argc, argv, &index);
+
if (!instance)
{
instance = strrchr (program_name, '/');
if (!instance)
instance = (char*) program_name;
else
@@ -2286,16 +2057,20 @@ main (int argc, char **argv)
else
for (file = conf_head; file; file = file->next)
{
switch (file->syntax)
{
case CONF_PIES:
- if (grecs_parse (file->name))
- exit (EX_CONFIG);
- break;
-
+ {
+ struct grecs_node *tree = grecs_parse (file->name);
+ if (!tree || grecs_tree_process (tree, pies_keywords))
+ exit (EX_CONFIG);
+ grecs_tree_free (tree);
+ break;
+ }
+
case CONF_INETD:
if (inetd_parse_conf (file->name))
exit (EX_CONFIG);
break;
case CONF_META1:
@@ -2314,41 +2089,41 @@ main (int argc, char **argv)
exit (0);
}
/* Re-setup logging: it might have been reset in the config file */
diag_setup (log_to_stderr_only ? DIAG_TO_STDERR : 0);
- if (argc != index && command != 'R')
+ if (argc != index && command != COM_RESTART)
{
logmsg (LOG_ERR, "extra command line arguments");
exit (EX_CONFIG);
}
progman_build_depmap ();
switch (command)
{
- case OPT_RESTART:
+ case COM_RESTART:
pies_priv_setup (&pies_privs);
if (pies_umask)
umask (pies_umask);
exit (request_restart_components (argv + index));
- case OPT_RELOAD:
+ case COM_RELOAD:
exit (pies_reload ());
- case OPT_STATUS:
+ case COM_STATUS:
exit (pies_status ());
- case OPT_STOP:
+ case COM_STOP:
exit (pies_stop ());
- case OPT_DUMP_PREREQ:
+ case COM_DUMP_PREREQ:
progman_dump_prereq ();
exit (0);
- case OPT_DUMP_DEPMAP:
+ case COM_DUMP_DEPMAP:
progman_dump_depmap ();
exit (0);
default:
pies_priv_setup (&pies_privs);
if (pies_umask)

Return to:

Send suggestions and report system problems to the System administrator.