diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-12-08 15:03:49 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-12-08 15:03:49 +0200 |
commit | 0a676ac900bd7f03a9a056d2b8be64b154f8647a (patch) | |
tree | 31ffa87a5095378b880e7a4ac37d1bbf83b40592 /src | |
parent | 83513bddf4bd6c3ea5d42035bda4aaeae8086628 (diff) | |
download | pies-0a676ac900bd7f03a9a056d2b8be64b154f8647a.tar.gz pies-0a676ac900bd7f03a9a056d2b8be64b154f8647a.tar.bz2 |
Global env statement.
* NEWS: Update.
* doc/pies.texi: Document the global env statement.
* src/pies.c: Modify "env" callbacks to expect a envop_t **
as modifiable target.
Introduce global env statement.
* tests/envglobal.at: New test.
* tests/Makefile.am: Add new file.
Diffstat (limited to 'src')
-rw-r--r-- | src/pies.c | 67 |
1 files changed, 51 insertions, 16 deletions
@@ -60,6 +60,8 @@ char *default_control_url[2] = { DEFAULT_PIES_CONTROL_URL, DEFAULT_INIT_CONTROL_URL }; + +static envop_t *pies_envop; struct config_syntax { @@ -705,19 +707,19 @@ cb_env_section_parser (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; switch (cmd) { case grecs_callback_section_begin: - *(struct component **) cb_data = comp; + *(envop_t ***) cb_data = envop_ptr; break; case grecs_callback_section_end: break; case grecs_callback_set_value: - return _cb_env (&comp->envop, value, locus); + return _cb_env (envop_ptr, value, locus); } return 0; } @@ -729,7 +731,7 @@ _cb_env_clear (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; if (!GRECS_VALUE_EMPTY_P (value)) { @@ -737,7 +739,7 @@ _cb_env_clear (enum grecs_callback_command cmd, return 1; } - if (envop_entry_add (&comp->envop, envop_clear, NULL, NULL)) + if (envop_entry_add (envop_ptr, envop_clear, NULL, NULL)) grecs_error (locus, errno, "envop_entry_add"); return 0; @@ -750,7 +752,7 @@ _cb_env_keep (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; char *p; if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING)) @@ -758,9 +760,9 @@ _cb_env_keep (enum grecs_callback_command cmd, p = strchr (value->v.string, '='); if (p) *p++ = 0; - if (envop_entry_add (&comp->envop, envop_clear, NULL, NULL)) + if (envop_entry_add (envop_ptr, envop_clear, NULL, NULL)) grecs_error (locus, errno, "envop_entry_add"); - if (envop_entry_add (&comp->envop, envop_keep, value->v.string, p)) + if (envop_entry_add (envop_ptr, envop_keep, value->v.string, p)) grecs_error (locus, errno, "envop_entry_add"); return 0; } @@ -772,7 +774,7 @@ _cb_env_set (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; char *p; if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING)) @@ -780,7 +782,7 @@ _cb_env_set (enum grecs_callback_command cmd, p = strchr (value->v.string, '='); if (p) *p++ = 0; - if (envop_entry_add (&comp->envop, envop_set, value->v.string, p)) + if (envop_entry_add (envop_ptr, envop_set, value->v.string, p)) grecs_error (locus, errno, "envop_entry_add"); return 0; } @@ -792,11 +794,11 @@ _cb_env_eval (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING)) return 1; - if (envop_entry_add (&comp->envop, envop_set, NULL, value->v.string)) + if (envop_entry_add (envop_ptr, envop_set, NULL, value->v.string)) grecs_error (locus, errno, "envop_entry_add"); return 0; } @@ -808,7 +810,7 @@ _cb_env_unset (enum grecs_callback_command cmd, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; - struct component *comp = varptr; + envop_t **envop_ptr = varptr; char *p; if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING)) @@ -816,7 +818,7 @@ _cb_env_unset (enum grecs_callback_command cmd, p = strchr (value->v.string, '='); if (p) *p++ = 0; - if (envop_entry_add (&comp->envop, envop_unset, value->v.string, p)) + if (envop_entry_add (envop_ptr, envop_unset, value->v.string, p)) grecs_error (locus, errno, "envop_entry_add"); return 0; } @@ -1436,7 +1438,7 @@ struct grecs_keyword component_keywords[] = { NULL, N_("Modify program environment."), grecs_type_section, GRECS_DFLT, - NULL, 0, + NULL, offsetof (struct component, envop), cb_env_section_parser, NULL, cb_env_keywords }, {"env", @@ -1444,7 +1446,7 @@ struct grecs_keyword component_keywords[] = { N_("Modify program environment (legacy syntax).\n" "Argument is a list of quoted assignments separated by white space."), grecs_type_string, GRECS_DFLT, - NULL, 0, + NULL, offsetof (struct component, envop), cb_env_section_parser, NULL, NULL }, {"chdir", @@ -1623,6 +1625,13 @@ struct grecs_keyword pies_keywords[] = { grecs_type_section, GRECS_DFLT, NULL, 0, component_section_parser, NULL, component_keywords}, + {"env", + NULL, + N_("Modify program environment."), + grecs_type_section, GRECS_DFLT, + &pies_envop, 0, + cb_env_section_parser, NULL, cb_env_keywords + }, {"control", NULL, N_("Define control socket"), @@ -2445,6 +2454,32 @@ main (int argc, char **argv) set_state_file_names (instance); set_mailer_argcv (); + if (pies_envop) + { + environ_t *env; + + if ((env = environ_create (environ)) == NULL) + { + logmsg (LOG_CRIT, "environ_create: %s", strerror (errno)); + exit (EX_OSERR); + } + if (envop_exec (pies_envop, env)) + { + logmsg (LOG_CRIT, "environ_exec: %s", strerror (errno)); + exit (EX_OSERR); + } + environ = environ_ptr (env); + + if (debug_level >= 4) + { + int i; + logmsg_printf (LOG_DEBUG, "environment: "); + for (i = 0; environ[i]; i++) + logmsg_printf (LOG_DEBUG, "%s ", environ[i]); + logmsg_printf (LOG_DEBUG, "\n"); + } + } + if (lint_mode) exit (0); |