I need this to test half-installed socket-activated python
script, which requires PYTHONPATH and LD_LIBRARY_PATH set.
I assume that other people might find it useful to.
-E VAR passes through VAR from the environment, while
-E VAR=value sets VAR=value.
systemd-activate -E PYTHONPATH=/var/tmp/inst1/usr/lib64/python3.3/site-packages -E LD_LIBRARY_PATH=/var/tmp/inst1/usr/lib -l 2000 python3 -c 'from systemd.daemon import listen_fds; print(listen_fds())'
</varlistentry>
<varlistentry>
</varlistentry>
<varlistentry>
- <term><option>-l</option></term>
+ <term><option>-l <replaceable>address</replaceable></option></term>
<term><option>--listen=<replaceable>address</replaceable></option></term>
<listitem><para>Listen on this <replaceable>address</replaceable>.
<term><option>--listen=<replaceable>address</replaceable></option></term>
<listitem><para>Listen on this <replaceable>address</replaceable>.
connection and pass the connection socket as standard input
and standard output.</para></listitem>
</varlistentry>
connection and pass the connection socket as standard input
and standard output.</para></listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><option>-E <replaceable>VAR</replaceable><optional>=<replaceable>VALUE</replaceable></optional></option></term>
+ <term><option>--environment=<replaceable>VAR</replaceable><optional>=<replaceable>VALUE</replaceable></optional></option></term>
+
+ <listitem><para>Add this variable to the environment of the
+ launched process. If <replaceable>VAR</replaceable> is
+ followed by <literal>=</literal> assume that it is a
+ variable–value pair. Otherwise obtain the value from the
+ environment of <command>systemd-activate</command> itself.
+ </para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
</variablelist>
</refsect1>
static char** arg_listen = NULL;
static bool arg_accept = false;
static char** arg_args = NULL;
static char** arg_listen = NULL;
static bool arg_accept = false;
static char** arg_args = NULL;
+static char** arg_environ = NULL;
static int add_epoll(int epoll_fd, int fd) {
int r;
static int add_epoll(int epoll_fd, int fd) {
int r;
}
static int launch(char* name, char **argv, char **environ, int fds) {
}
static int launch(char* name, char **argv, char **environ, int fds) {
- unsigned n_env = 0;
- char* envp[7] = {NULL}; /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID */
+ unsigned n_env = 0, length;
+ char **envp = NULL, **s;
static const char* tocopy[] = {"TERM=", "PATH=", "USER=", "HOME="};
char _cleanup_free_ *tmp = NULL;
unsigned i;
static const char* tocopy[] = {"TERM=", "PATH=", "USER=", "HOME="};
char _cleanup_free_ *tmp = NULL;
unsigned i;
+ length = strv_length(arg_environ);
+ /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID, NULL */
+ envp = new(char *, length + 7);
+
+ STRV_FOREACH(s, arg_environ) {
+ if (strchr(*s, '='))
+ envp[n_env++] = *s;
+ else {
+ char _cleanup_free_ *p = strappend(*s, "=");
+ if (!p)
+ return log_oom();
+ envp[n_env] = strv_find_prefix(environ, p);
+ if (envp[n_env])
+ n_env ++;
+ }
+ }
+
for (i = 0; i < ELEMENTSOF(tocopy); i++) {
envp[n_env] = strv_find_prefix(environ, tocopy[i]);
if (envp[n_env])
for (i = 0; i < ELEMENTSOF(tocopy); i++) {
envp[n_env] = strv_find_prefix(environ, tocopy[i]);
if (envp[n_env])
{ "version", no_argument, NULL, ARG_VERSION },
{ "listen", required_argument, NULL, 'l' },
{ "accept", no_argument, NULL, 'a' },
{ "version", no_argument, NULL, ARG_VERSION },
{ "listen", required_argument, NULL, 'l' },
{ "accept", no_argument, NULL, 'a' },
+ { "environment", required_argument, NULL, 'E' },
assert(argc >= 0);
assert(argv);
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+hl:sa", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "+hl:saE:", options, NULL)) >= 0)
switch(c) {
case 'h':
help();
switch(c) {
case 'h':
help();
arg_accept = true;
break;
arg_accept = true;
break;
+ case 'E': {
+ int r = strv_extend(&arg_environ, optarg);
+ if (r < 0)
+ return r;
+
+ break;
+ }
+
case '?':
return -EINVAL;
case '?':
return -EINVAL;