aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-12-08 15:03:49 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-12-08 15:03:49 +0200
commit0a676ac900bd7f03a9a056d2b8be64b154f8647a (patch)
tree31ffa87a5095378b880e7a4ac37d1bbf83b40592
parent83513bddf4bd6c3ea5d42035bda4aaeae8086628 (diff)
downloadpies-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.
-rw-r--r--NEWS9
-rw-r--r--doc/pies.texi15
-rw-r--r--src/pies.c67
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/accept.at4
-rw-r--r--tests/builtin.at2
-rw-r--r--tests/control.at2
-rw-r--r--tests/cyclic.at2
-rw-r--r--tests/env.at2
-rw-r--r--tests/envglobal.at86
-rw-r--r--tests/envop.at2
-rw-r--r--tests/expandenv.at2
-rw-r--r--tests/inet.at2
-rw-r--r--tests/maxinst.at2
-rw-r--r--tests/passfd.at4
-rw-r--r--tests/redirect.at2
-rw-r--r--tests/respawn.at2
-rw-r--r--tests/ret-exec.at2
-rw-r--r--tests/ret-notify.at2
-rw-r--r--tests/shell.at2
-rw-r--r--tests/shutdown.at2
-rw-r--r--tests/startup.at2
-rw-r--r--tests/testsuite.at3
-rw-r--r--tests/version.at2
24 files changed, 182 insertions, 39 deletions
diff --git a/NEWS b/NEWS
index c49ae72..cffce15 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU Pies NEWS -- history of user-visible changes. 2020-12-07
+GNU Pies NEWS -- history of user-visible changes. 2020-12-08
See the end of file for copying conditions.
Please send Pies bug reports to <bug-pies@gnu.org> or
@@ -31,7 +31,7 @@ effect is issued.
* Component standard stream redirection rewritten from scratch
-In particular, redirecting stdout/stderr to syslog no longer require
+In particular, redirecting stdout/stderr to syslog no longer requires
starting an auxiliar process.
* The component.facility configuration statement is withdrawn
@@ -51,6 +51,11 @@ or the IP[:PORT] specification, e.g.
dev 172.31.255.252;
}
+* Global env section
+
+The "env" section appearing in global context modifies the environment
+for the main pies process and for all processes started by it.
+
* New control endpoint /alive
HTTP response to GET /alive/PROG reflects the current state of the
diff --git a/doc/pies.texi b/doc/pies.texi
index aeb287f..110c257 100644
--- a/doc/pies.texi
+++ b/doc/pies.texi
@@ -1067,6 +1067,12 @@ up to 1.3 and is still retained for backward compatibility. It is
described in @ref{env legacy syntax}. This subsection describes the
modern compount syntax.
+The @code{env} statement can also be used in global context, in which
+case it modifies environment for the master @command{pies} program,
+i.e. the environment that will be inherited by all components
+(@pxref{Global Configuration}). The global @code{env} is available
+only in compound syntax described here.
+
@deffn {Config: component} env @{ ... @}
The compound @code{env} statement has the following syntax:
@@ -2795,6 +2801,15 @@ component smtps @{
The statements described in this section affect @command{pies}
behavior as a whole.
+@deffn {Config} env @{ @dots{} @}
+Modifies the environment for the running @command{pies} instance. The
+modified environment will be inherited by all processes started by
+@command{pies} in the course of its normal operation.
+
+@xref{Environment}, for a detailed discussion of the @code{env}
+statement syntax.
+@end deffn
+
@anchor{syslog}
@deffn {Config} syslog @{ @dots{} @}
This block statement configures logging via syslog. It has the following
diff --git a/src/pies.c b/src/pies.c
index d0d4f3c..b6b0193 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -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);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6a9a0d8..62cdb31 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -54,6 +54,7 @@ TESTSUITE_AT = \
control.at\
cyclic.at\
env.at\
+ envglobal.at\
envop.at\
expandenv.at\
inet.at\
diff --git a/tests/accept.at b/tests/accept.at
index e12be02..417c2ba 100644
--- a/tests/accept.at
+++ b/tests/accept.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2019-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
@@ -51,4 +51,4 @@ cat log.err >&2
the time
stop
])
-AT_CLEANUP \ No newline at end of file
+AT_CLEANUP
diff --git a/tests/builtin.at b/tests/builtin.at
index 88e24d7..16208e6 100644
--- a/tests/builtin.at
+++ b/tests/builtin.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/control.at b/tests/control.at
index 5171862..e63cc66 100644
--- a/tests/control.at
+++ b/tests/control.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/cyclic.at b/tests/cyclic.at
index 1cc542d..46a3c7a 100644
--- a/tests/cyclic.at
+++ b/tests/cyclic.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2019-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/env.at b/tests/env.at
index dba80a3..9fe405e 100644
--- a/tests/env.at
+++ b/tests/env.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/envglobal.at b/tests/envglobal.at
new file mode 100644
index 0000000..8adc04d
--- /dev/null
+++ b/tests/envglobal.at
@@ -0,0 +1,86 @@
+# This file is part of GNU pies testsuite. -*- autotest -*-
+# Copyright (C) 2020 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/>.
+dnl ENVTEST(NAME,KW,ENV,OUT)
+m4_pushdef([ENVTEST],
+[AT_SETUP([$1])
+AT_KEYWORDS([env $2])
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+cat > envtest.conf <<_EOT
+env {
+ $3
+}
+component envtest {
+ command "$abs_builddir/envtest -clone";
+ chdir $PWD;
+ stdout file "$PWD/log";
+ return-code 0 {
+ action disable;
+ exec "$abs_top_builddir/src/piesctl --url unix:///$PWD/pies.ctl --no-netrc shutdown";
+ }
+}
+_EOT
+
+to 5 \
+ envtest -exec \
+ $abs_top_builddir/src/pies --foreground --stderr \
+ --config-file control.conf --config-file envtest.conf --debug 1 2>errlog
+cat log
+],
+[0],
+[$4])
+AT_CLEANUP])
+
+dnl #############################
+dnl Start tests
+dnl #############################
+
+AT_BANNER([Global environment statement])
+
+ENVTEST([clear],[clear],[clear;],[])
+
+ENVTEST([keep],[keep],[keep "LC_*";],
+[LC_ALL="C"
+LC_CTYPE="C"
+LC_MESSAGES="C"
+LC_NUMERIC="C"
+])
+
+ENVTEST([set],[set],[set "FOO=bar";],
+[FOO="bar"
+HOME="/home/user"
+LC_ALL="C"
+LC_CTYPE="C"
+LC_MESSAGES="C"
+LC_NUMERIC="C"
+LOGIN="user"
+PATH="/usr/local/bin:/usr/bin:/bin"
+PIES_INSTANCE="pies"
+PWD="/home"
+USER="user"
+])
+
+ENVTEST([unset],[unset],[unset "LC_*"; unset PWD;],
+[HOME="/home/user"
+LOGIN="user"
+PATH="/usr/local/bin:/usr/bin:/bin"
+PIES_INSTANCE="pies"
+USER="user"
+])
+
+m4_popdef([ENVTEST])
+
diff --git a/tests/envop.at b/tests/envop.at
index 5575772..ac1336e 100644
--- a/tests/envop.at
+++ b/tests/envop.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/expandenv.at b/tests/expandenv.at
index 5518472..b8ecd8d 100644
--- a/tests/expandenv.at
+++ b/tests/expandenv.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/inet.at b/tests/inet.at
index cc4fceb..e9318c9 100644
--- a/tests/inet.at
+++ b/tests/inet.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/maxinst.at b/tests/maxinst.at
index f389e0b..304f2dc 100644
--- a/tests/maxinst.at
+++ b/tests/maxinst.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2019-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/passfd.at b/tests/passfd.at
index 74d5ab3..a3ead31 100644
--- a/tests/passfd.at
+++ b/tests/passfd.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
@@ -54,4 +54,4 @@ cat log.err >&2
the time
stop
])
-AT_CLEANUP \ No newline at end of file
+AT_CLEANUP
diff --git a/tests/redirect.at b/tests/redirect.at
index 5cc5548..8421bfe 100644
--- a/tests/redirect.at
+++ b/tests/redirect.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/respawn.at b/tests/respawn.at
index 68da448..643ac88 100644
--- a/tests/respawn.at
+++ b/tests/respawn.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/ret-exec.at b/tests/ret-exec.at
index 8f6152e..1f206b0 100644
--- a/tests/ret-exec.at
+++ b/tests/ret-exec.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/ret-notify.at b/tests/ret-notify.at
index 29ff677..c35230b 100644
--- a/tests/ret-notify.at
+++ b/tests/ret-notify.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/shell.at b/tests/shell.at
index 8375e22..5bf1192 100644
--- a/tests/shell.at
+++ b/tests/shell.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/shutdown.at b/tests/shutdown.at
index d89f6f9..b640ab8 100644
--- a/tests/shutdown.at
+++ b/tests/shutdown.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2019-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/startup.at b/tests/startup.at
index 5a6b19a..98fa82d 100644
--- a/tests/startup.at
+++ b/tests/startup.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2019-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 277cf8b..0fef31a 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -77,4 +77,5 @@ m4_include([passfd.at])
m4_include([accept.at])
m4_include([envop.at])
-m4_include([env.at]) \ No newline at end of file
+m4_include([env.at])
+m4_include([envglobal.at])
diff --git a/tests/version.at b/tests/version.at
index c92cbaa..43f490a 100644
--- a/tests/version.at
+++ b/tests/version.at
@@ -1,4 +1,4 @@
-# This file is part of GNU pies testsuite. -*- Autotest -*-
+# This file is part of GNU pies testsuite. -*- autotest -*-
# Copyright (C) 2016-2020 Sergey Poznyakoff
#
# GNU pies is free software; you can redistribute it and/or modify

Return to:

Send suggestions and report system problems to the System administrator.