aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
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,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 @@ _cb_flags (enum grecs_callback_command cmd,
{
- 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))
@@ -1562,3 +1569,2 @@ config_init ()
{
- grecs_set_keywords (pies_keywords);
grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR,
@@ -1581,215 +1587,10 @@ config_help ()
"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
@@ -2158,30 +1959,2 @@ set_mailer_argcv ()
-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 *
@@ -2250,6 +2023,4 @@ main (int argc, char **argv)
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)
@@ -2291,6 +2062,10 @@ main (int argc, char **argv)
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:
@@ -2319,3 +2094,3 @@ main (int argc, char **argv)
- if (argc != index && command != 'R')
+ if (argc != index && command != COM_RESTART)
{
@@ -2328,3 +2103,3 @@ main (int argc, char **argv)
{
- case OPT_RESTART:
+ case COM_RESTART:
pies_priv_setup (&pies_privs);
@@ -2334,12 +2109,12 @@ main (int argc, char **argv)
- 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 ();
@@ -2347,3 +2122,3 @@ main (int argc, char **argv)
- case OPT_DUMP_DEPMAP:
+ case COM_DUMP_DEPMAP:
progman_dump_depmap ();

Return to:

Send suggestions and report system problems to the System administrator.