Merge lp:~jamesodhunt/upstart/init--inherit-env into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1428
Proposed branch: lp:~jamesodhunt/upstart/init--inherit-env
Merge into: lp:upstart
Diff against target: 82 lines (+27/-1)
4 files modified
ChangeLog (+7/-0)
init/job_process.c (+5/-1)
init/main.c (+10/-0)
init/man/init.8 (+5/-0)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/init--inherit-env
Reviewer Review Type Date Requested Status
Upstart Reviewers Pending
Review via email: mp+147421@code.launchpad.net

Description of the change

Add ability for jobs supervised by a Session Init to inherit the init enviromnent to simplify Session handling.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

Looks ok, so merging. However, have you considered whether this should be the default behavior for user init, without having to specify an additional option? Is there ever a case where we *don't* want the user session's process environment to be inherited?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-02-02 16:09:52 +0000
3+++ ChangeLog 2013-02-08 17:02:37 +0000
4@@ -1,3 +1,10 @@
5+2013-02-08 James Hunt <james.hunt@ubuntu.com>
6+
7+ * init/job_process.c: job_process_run(): Copy parent environment if
8+ inherit_env in operation for a Session Init.
9+ * init/main.c: Added 'inherit-env' command-line option.
10+ * init/man/init.8: Documented --inherit-env.
11+
12 2013-02-02 James Hunt <james.hunt@ubuntu.com>
13
14 * util/initctl.c: Remove ability to specify explicitly job and/or job
15
16=== modified file 'init/job_process.c'
17--- init/job_process.c 2013-01-25 09:08:09 +0000
18+++ init/job_process.c 2013-02-08 17:02:37 +0000
19@@ -128,7 +128,8 @@
20 static void job_process_trace_fork (Job *job, ProcessType process);
21 static void job_process_trace_exec (Job *job, ProcessType process);
22
23-extern int user_mode;
24+extern int user_mode;
25+extern int inherit_env;
26 extern char *control_server_address;
27
28 /**
29@@ -269,6 +270,9 @@
30 env = NIH_MUST (nih_str_array_new (NULL));
31 }
32
33+ if (user_mode && inherit_env)
34+ NIH_MUST(environ_append (&env, NULL, &envc, TRUE, environ));
35+
36 if (job->stop_env
37 && ((process == PROCESS_PRE_STOP)
38 || (process == PROCESS_POST_STOP)))
39
40=== modified file 'init/main.c'
41--- init/main.c 2013-01-31 17:23:55 +0000
42+++ init/main.c 2013-02-08 17:02:37 +0000
43@@ -120,6 +120,13 @@
44 **/
45 static int disable_startup_event = FALSE;
46
47+/**
48+ * inherit_env:
49+ *
50+ * If TRUE, copy inits environment to that provided to jobs.
51+ **/
52+int inherit_env = FALSE;
53+
54 extern int user_mode;
55 extern int disable_sessions;
56 extern int disable_job_logging;
57@@ -140,6 +147,9 @@
58 { 0, "default-console", N_("default value for console stanza"),
59 NULL, "VALUE", NULL, console_type_setter },
60
61+ { 0, "inherit-env", N_("jobs will inherit environment of init"),
62+ NULL, NULL, &inherit_env ,NULL },
63+
64 { 0, "logdir", N_("specify alternative directory to store job output logs in"),
65 NULL, "DIR", &log_dir, NULL },
66
67
68=== modified file 'init/man/init.8'
69--- init/man/init.8 2013-01-18 15:26:17 +0000
70+++ init/man/init.8 2013-02-08 17:02:37 +0000
71@@ -81,6 +81,11 @@
72 .BR console "."
73 .\"
74 .TP
75+.B \-\-inherit\-env
76+Make jobs inherit the initial environment. Impotent when running as
77+process id 1.
78+.\"
79+.TP
80 .B \-\-logdir \fIdirectory\fP
81 Write job output log files to a directory other than
82 \fI/var/log/upstart\fP (system mode) or \fI$XDG_CACHE_HOME/upstart\fP

Subscribers

People subscribed via source and target branches