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,5 +1,5 @@
/* 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
@@ -26,7 +26,18 @@ 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;
@@ -145,14 +156,11 @@ stderr_closed_p ()
}
-#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));
@@ -412,9 +420,9 @@ _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;
}
@@ -422,7 +430,7 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
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"));
@@ -445,7 +453,7 @@ return_code_section_parser (enum grecs_callback_command cmd,
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;
@@ -463,7 +471,7 @@ return_code_section_parser (enum grecs_callback_command cmd,
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;
@@ -497,9 +505,9 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc)
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)
@@ -702,12 +710,12 @@ _cb_redir (enum grecs_callback_command cmd,
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)
@@ -717,7 +725,7 @@ _cb_redir (enum grecs_callback_command cmd,
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;
@@ -727,18 +735,18 @@ _cb_redir (enum grecs_callback_command cmd,
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;
}
}
@@ -910,12 +918,11 @@ _cb_flags (enum grecs_callback_command cmd,
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))
@@ -1560,7 +1567,6 @@ struct grecs_keyword pies_keywords[] = {
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;
@@ -1579,219 +1585,14 @@ config_help ()
/* 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
@@ -2156,34 +1957,6 @@ 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 *
mkfilename (const char *dir, const char *name, const char *suf)
{
@@ -2248,10 +2021,8 @@ main (int argc, char **argv)
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, '/');
@@ -2289,10 +2060,14 @@ main (int argc, char **argv)
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);
@@ -2317,7 +2092,7 @@ main (int argc, char **argv)
/* 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);
@@ -2326,26 +2101,26 @@ main (int argc, char **argv)
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);

Return to:

Send suggestions and report system problems to the System administrator.