[PATCH] weston-launch exports listed environment variables
José Bollo
jobol at nonadev.net
Mon Sep 23 01:57:44 PDT 2013
Enable weston-launch to export the environment
variables listed with the invocation option
--export (shortened as -e).
The values of the variables are read from the
environment of weston-launch to ensure they
aren't displayed by the unix command 'ps'.
Example:
weston-launch --export=DBUS_SESSION_BUS_ADDRESS
In the above example, the environment variable
DBUS_SESSION_BUS_ADDRESS is passed to weston.
Note: weston-launch launches the process within
a login shell. So most of the environment variables
are set through the standard process. Then the
option --export is intended to be used only when
the standard way is missing some contextual point.
---
src/weston-launch.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/weston-launch.c b/src/weston-launch.c
index 525c61c..ea59e05 100644
--- a/src/weston-launch.c
+++ b/src/weston-launch.c
@@ -85,6 +85,13 @@ struct weston_launch {
union cmsg_data { unsigned char b[4]; int fd; };
+struct reexport {
+ struct reexport * next;
+ char * name, * value;
+};
+
+static struct reexport * reexport_head = NULL;
+
static gid_t *
read_groups(void)
{
@@ -527,6 +534,7 @@ setup_session(struct weston_launch *wl)
char **env;
char *term;
int i;
+ struct reexport * reexport = reexport_head;
if (wl->tty != STDIN_FILENO) {
if (setsid() < 0)
@@ -537,6 +545,10 @@ setup_session(struct weston_launch *wl)
term = getenv("TERM");
clearenv();
+ while (reexport != NULL) {
+ setenv(reexport->name, reexport->value, 1);
+ reexport = reexport->next;
+ }
if (term)
setenv("TERM", term, 1);
setenv("USER", wl->pw->pw_name, 1);
@@ -610,6 +622,7 @@ help(const char *name)
fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
fprintf(stderr, " -u, --user Start session as specified username
\n");
fprintf(stderr, " -t, --tty Start session on alternative tty
\n");
+ fprintf(stderr, " -e, --export (re-)Export the given environment
variable\n");
fprintf(stderr, " -v, --verbose Be verbose\n");
fprintf(stderr, " -h, --help Display this help message\n");
}
@@ -620,9 +633,11 @@ main(int argc, char *argv[])
struct weston_launch wl;
int i, c;
char *tty = NULL;
+ struct reexport **reexport = &reexport_head;
struct option opts[] = {
{ "user", required_argument, NULL, 'u' },
{ "tty", required_argument, NULL, 't' },
+ { "export", required_argument, NULL, 'e' },
{ "verbose", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, NULL, 0 }
@@ -630,7 +645,7 @@ main(int argc, char *argv[])
memset(&wl, 0, sizeof wl);
- while ((c = getopt_long(argc, argv, "u:t::vh", opts, &i)) != -1) {
+ while ((c = getopt_long(argc, argv, "u:t::e:vh", opts, &i)) != -1) {
switch (c) {
case 'u':
wl.new_user = optarg;
@@ -640,6 +655,21 @@ main(int argc, char *argv[])
case 't':
tty = optarg;
break;
+ case 'e':
+ if (getenv(optarg) == NULL)
+ error(1, 0, "Environment variable '%s' not found.", optarg);
+ else {
+ *reexport = malloc(sizeof (struct reexport));
+ if (*reexport == NULL) {
+ error(1, 0, "Memory depletion.");
+ exit(EXIT_FAILURE);
+ }
+ (*reexport)->name = optarg;
+ (*reexport)->value = getenv(optarg);
+ reexport = &((*reexport)->next);
+ *reexport = NULL;
+ }
+ break;
case 'v':
wl.verbose = 1;
break;
--
1.8.1.4
More information about the wayland-devel
mailing list