Merge lp:~jamesodhunt/upstart/bug-1159895 into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1480
Proposed branch: lp:~jamesodhunt/upstart/bug-1159895
Merge into: lp:upstart
Diff against target: 501 lines (+167/-56)
5 files modified
ChangeLog (+21/-0)
init/job_class.c (+11/-4)
init/job_process.c (+0/-3)
util/man/initctl.8 (+7/-4)
util/tests/test_initctl.c (+128/-45)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/bug-1159895
Reviewer Review Type Date Requested Status
Stéphane Graber (community) Approve
James Hunt Needs Resubmitting
Review via email: mp+166836@code.launchpad.net

Description of the change

= Behaviour Change =

Previously running 'initctl list-env' in a Session Init environment would only list those minimal variables added by init (PATH and TERM) along with any variables explicitly set via 'initctl set-env'. However, it now lists that set plus all variables set in inits environment at startup time.

* init/job_class.c: job_class_environment_init(): Copy inits environment
  to the default job class environment for user mode where appropriate.
* init/job_process.c: job_process_run(): Don't copy inits environment
  into the job instances environment table as those values are now
  already in the table.
* util/tests/test_initctl.c: Updates for new behaviour (where
  'list-env' will now contain the entire environment of the init
  process, not just those variables explicitly set via set-env).
* util/man/initctl.8: Update on behaviour.

To post a comment you must log in.
Revision history for this message
Stéphane Graber (stgraber) wrote :

I think this looks good.

Do we have a test that runs upstart with no_inherit_env set and checks that the environment in that case is sane (exact match to what we'd expect)?
If we don't, we definitely should add that as your branch relaxes some of the existing tests in that regard.

lp:~jamesodhunt/upstart/bug-1159895 updated
1479. By James Hunt

* util/tests/test_initctl.c:
  - test_no_inherit_job_env(): New function to test --no-inherit-env.
  - test_job_env():
    - Move code that sets HOME+PATH if not set from
      test_default_job_env() so that test_no_inherit_job_env() can make
      use of it.
    - Session file cleanup tweaks to work with test_no_inherit_job_env().

Revision history for this message
James Hunt (jamesodhunt) wrote :

Good call - added some basic '--no-inherit-env' tests.

review: Needs Resubmitting
Revision history for this message
Stéphane Graber (stgraber) wrote :

Perfect, thanks.

Note that your changelog changes are currently failing to merge so you'll need to resolve that conflict on merge.

review: Approve
lp:~jamesodhunt/upstart/bug-1159895 updated
1480. By James Hunt

Sync with lp:upstart.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-06-05 16:18:42 +0000
+++ ChangeLog 2013-06-20 09:37:27 +0000
@@ -33,8 +33,29 @@
33 approach of detecting the format of the JSON is safer.33 approach of detecting the format of the JSON is safer.
34 * init/state.h: Remove STATE_VERSION.34 * init/state.h: Remove STATE_VERSION.
3535
362013-06-03 James Hunt <james.hunt@ubuntu.com>
37
38 * util/tests/test_initctl.c:
39 - test_no_inherit_job_env(): New function to test --no-inherit-env.
40 - test_job_env():
41 - Move code that sets HOME+PATH if not set from
42 test_default_job_env() so that test_no_inherit_job_env() can make
43 use of it.
44 - Session file cleanup tweaks to work with test_no_inherit_job_env().
45
362013-05-31 James Hunt <james.hunt@ubuntu.com>462013-05-31 James Hunt <james.hunt@ubuntu.com>
3747
48 * init/job_class.c: job_class_environment_init(): Copy inits environment
49 to the default job class environment for user mode where appropriate.
50 (LP: #1159895).
51 * init/job_process.c: job_process_run(): Don't copy inits environment
52 into the job instances environment table as those values are now
53 already in the table.
54 * util/tests/test_initctl.c: Updates for new behaviour (where
55 'list-env' will now contain the entire environment of the init
56 process, not just those variables explicitly set via set-env).
57 * util/man/initctl.8: Update on behaviour.
58
38 [ Eric S. Raymond <esr@thyrsus.com> ]59 [ Eric S. Raymond <esr@thyrsus.com> ]
39 * init/man/init.5: Fix unliftable markup (LP: #1185108).60 * init/man/init.5: Fix unliftable markup (LP: #1185108).
4061
4162
=== modified file 'init/job_class.c'
--- init/job_class.c 2013-05-29 10:36:36 +0000
+++ init/job_class.c 2013-06-20 09:37:27 +0000
@@ -62,6 +62,9 @@
62#include <json.h>62#include <json.h>
6363
64extern json_object *json_classes;64extern json_object *json_classes;
65extern int user_mode;
66extern int no_inherit_env;
67extern char **environ;
6568
66/* Prototypes for static functions */69/* Prototypes for static functions */
67static void job_class_add (JobClass *class);70static void job_class_add (JobClass *class);
@@ -115,10 +118,14 @@
115{118{
116 char * const default_environ[] = { JOB_DEFAULT_ENVIRONMENT, NULL };119 char * const default_environ[] = { JOB_DEFAULT_ENVIRONMENT, NULL };
117120
118 if (! job_environ) {121 if (job_environ)
119 job_environ = NIH_MUST (nih_str_array_new (NULL));122 return;
120 NIH_MUST (environ_append (&job_environ, NULL, 0, TRUE, default_environ));123
121 }124 job_environ = NIH_MUST (nih_str_array_new (NULL));
125 NIH_MUST (environ_append (&job_environ, NULL, 0, TRUE, default_environ));
126
127 if (user_mode && ! no_inherit_env)
128 NIH_MUST(environ_append (&job_environ, NULL, 0, TRUE, environ));
122}129}
123130
124/**131/**
125132
=== modified file 'init/job_process.c'
--- init/job_process.c 2013-05-24 17:21:47 +0000
+++ init/job_process.c 2013-06-20 09:37:27 +0000
@@ -283,9 +283,6 @@
283 envc = 0;283 envc = 0;
284 env = NIH_MUST (nih_str_array_new (NULL));284 env = NIH_MUST (nih_str_array_new (NULL));
285285
286 if (user_mode && ! no_inherit_env)
287 NIH_MUST(environ_append (&env, NULL, &envc, TRUE, environ));
288
289 if (job->env)286 if (job->env)
290 NIH_MUST(environ_append (&env, NULL, &envc, TRUE, job->env));287 NIH_MUST(environ_append (&env, NULL, &envc, TRUE, job->env));
291288
292289
=== modified file 'util/man/initctl.8'
--- util/man/initctl.8 2013-02-15 14:07:05 +0000
+++ util/man/initctl.8 2013-06-20 09:37:27 +0000
@@ -565,10 +565,13 @@
565job-specific environment table; otherwise the global environment table565job-specific environment table; otherwise the global environment table
566that is applied to all jobs when they first start is queried.566that is applied to all jobs when they first start is queried.
567567
568Note that the global job environment table only includes the minimal set568Note that the global job environment table comprises those variables
569of standard system variables added by the569already set in the
570.BR init (8)570.BR init (8)
571daemon along with any variables set using571daemons environment at startup, the minimal set of standard system
572variables added by the
573.BR init (8)
574daemon, and any variables set using
572.BR set\-env "."575.BR set\-env "."
573See576See
574.BR init (5)577.BR init (5)
575578
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2013-02-27 11:46:04 +0000
+++ util/tests/test_initctl.c 2013-06-20 09:37:27 +0000
@@ -16436,21 +16436,6 @@
16436 assert (upstart_pid);16436 assert (upstart_pid);
16437 assert (dbus_pid);16437 assert (dbus_pid);
1643816438
16439 /*******************************************************************/
16440 /* Ensure basic variables are set in the current environment */
16441
16442 if (! getenv ("TERM")) {
16443 fprintf (stderr, "WARNING: setting TERM to '%s' as not set\n",
16444 TEST_INITCTL_DEFAULT_TERM);
16445 assert0 (setenv ("TERM", TEST_INITCTL_DEFAULT_TERM, 1));
16446 }
16447
16448 if (! getenv ("PATH")) {
16449 fprintf (stderr, "WARNING: setting PATH to '%s' as not set\n",
16450 TEST_INITCTL_DEFAULT_PATH);
16451 assert0 (setenv ("PATH", TEST_INITCTL_DEFAULT_PATH, 1));
16452 }
16453
16454 cmd = nih_sprintf (NULL, "%s reset-env 2>&1", get_initctl ());16439 cmd = nih_sprintf (NULL, "%s reset-env 2>&1", get_initctl ());
16455 TEST_NE_P (cmd, NULL);16440 TEST_NE_P (cmd, NULL);
16456 RUN_COMMAND (NULL, cmd, &output, &line_count);16441 RUN_COMMAND (NULL, cmd, &output, &line_count);
@@ -16463,9 +16448,9 @@
16463 TEST_NE_P (cmd, NULL);16448 TEST_NE_P (cmd, NULL);
16464 RUN_COMMAND (NULL, cmd, &output, &line_count);16449 RUN_COMMAND (NULL, cmd, &output, &line_count);
1646516450
16466 TEST_EQ (line_count, 2);16451 TEST_GE (line_count, 2);
16467 TEST_STR_MATCH (output[0], "PATH=*");16452 TEST_STR_ARRAY_CONTAINS (output, "PATH=*");
16468 TEST_STR_MATCH (output[1], "TERM=*");16453 TEST_STR_ARRAY_CONTAINS (output, "TERM=*");
16469 nih_free (output);16454 nih_free (output);
1647016455
16471 /*******************************************************************/16456 /*******************************************************************/
@@ -16475,9 +16460,9 @@
16475 TEST_NE_P (cmd, NULL);16460 TEST_NE_P (cmd, NULL);
16476 RUN_COMMAND (NULL, cmd, &output, &line_count);16461 RUN_COMMAND (NULL, cmd, &output, &line_count);
1647716462
16478 TEST_EQ (line_count, 2);16463 TEST_GE (line_count, 2);
16479 TEST_STR_MATCH (output[0], "PATH=*");16464 TEST_STR_ARRAY_CONTAINS (output, "PATH=*");
16480 TEST_STR_MATCH (output[1], "TERM=*");16465 TEST_STR_ARRAY_CONTAINS (output, "TERM=*");
16481 nih_free (output);16466 nih_free (output);
1648216467
16483 /*******************************************************************/16468 /*******************************************************************/
@@ -16542,17 +16527,15 @@
1654216527
16543 fi = fopen (logfile, "r");16528 fi = fopen (logfile, "r");
16544 TEST_NE_P (fi, NULL);16529 TEST_NE_P (fi, NULL);
16545 TEST_FILE_MATCH (fi, "PATH=*");16530 TEST_FILE_CONTAINS (fi, "PATH=*");
16546 TEST_FILE_MATCH (fi, "TERM=*");16531 TEST_FILE_CONTAINS (fi, "TERM=*");
1654716532
16548 /* asterisk required to match '\r\n' */16533 /* asterisk required to match '\r\n' */
16549 TEST_FILE_MATCH (fi, "UPSTART_JOB=foo*");16534 TEST_FILE_CONTAINS (fi, "UPSTART_JOB=foo*");
16550 TEST_FILE_MATCH (fi, "UPSTART_INSTANCE=*");16535 TEST_FILE_CONTAINS (fi, "UPSTART_INSTANCE=*");
16551 TEST_FILE_MATCH (fi, "UPSTART_SESSION=*");16536 TEST_FILE_CONTAINS (fi, "UPSTART_SESSION=*");
16552 TEST_FILE_END (fi);
16553 fclose (fi);16537 fclose (fi);
1655416538
16555
16556 DELETE_FILE (confdir, "foo.conf");16539 DELETE_FILE (confdir, "foo.conf");
16557 TEST_EQ (unlink (logfile), 0);16540 TEST_EQ (unlink (logfile), 0);
1655816541
@@ -16729,6 +16712,7 @@
16729 cmd = nih_sprintf (NULL, "%s reset-env 2>&1", get_initctl ());16712 cmd = nih_sprintf (NULL, "%s reset-env 2>&1", get_initctl ());
16730 TEST_NE_P (cmd, NULL);16713 TEST_NE_P (cmd, NULL);
16731 RUN_COMMAND (NULL, cmd, &output, &line_count);16714 RUN_COMMAND (NULL, cmd, &output, &line_count);
16715 TEST_EQ (line_count, 0);
16732 nih_free (output);16716 nih_free (output);
1673316717
16734 /* Ensure nothing changed */16718 /* Ensure nothing changed */
@@ -16746,7 +16730,7 @@
16746 name, value);16730 name, value);
16747 TEST_NE_P (cmd, NULL);16731 TEST_NE_P (cmd, NULL);
16748 RUN_COMMAND (NULL, cmd, &output, &line_count);16732 RUN_COMMAND (NULL, cmd, &output, &line_count);
16749 nih_free (output);16733 TEST_EQ (line_count, 0);
1675016734
16751 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16735 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
16752 name);16736 name);
@@ -16767,6 +16751,7 @@
16767 RUN_COMMAND (NULL, cmd, &output, &line_count);16751 RUN_COMMAND (NULL, cmd, &output, &line_count);
16768 TEST_EQ (line_count, 1);16752 TEST_EQ (line_count, 1);
16769 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16753 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16754 nih_free (output);
1677016755
16771 /*******************************************************************/16756 /*******************************************************************/
16772 TEST_FEATURE ("set-env in 'name=' form");16757 TEST_FEATURE ("set-env in 'name=' form");
@@ -16777,6 +16762,7 @@
16777 name);16762 name);
16778 TEST_NE_P (cmd, NULL);16763 TEST_NE_P (cmd, NULL);
16779 RUN_COMMAND (NULL, cmd, &output, &line_count);16764 RUN_COMMAND (NULL, cmd, &output, &line_count);
16765 TEST_EQ (line_count, 0);
16780 nih_free (output);16766 nih_free (output);
1678116767
16782 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16768 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
@@ -16802,6 +16788,7 @@
16802 RUN_COMMAND (NULL, cmd, &output, &line_count);16788 RUN_COMMAND (NULL, cmd, &output, &line_count);
16803 TEST_EQ (line_count, 1);16789 TEST_EQ (line_count, 1);
16804 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16790 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16791 nih_free (output);
1680516792
16806 /*******************************************************************/16793 /*******************************************************************/
16807 TEST_FEATURE ("set-env in 'name' form");16794 TEST_FEATURE ("set-env in 'name' form");
@@ -16837,6 +16824,7 @@
16837 RUN_COMMAND (NULL, cmd, &output, &line_count);16824 RUN_COMMAND (NULL, cmd, &output, &line_count);
16838 TEST_EQ (line_count, 1);16825 TEST_EQ (line_count, 1);
16839 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16826 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16827 nih_free (output);
1684016828
16841 /*******************************************************************/16829 /*******************************************************************/
16842 TEST_FEATURE ("set-env for already set variable");16830 TEST_FEATURE ("set-env for already set variable");
@@ -16849,7 +16837,7 @@
16849 name, value);16837 name, value);
16850 TEST_NE_P (cmd, NULL);16838 TEST_NE_P (cmd, NULL);
16851 RUN_COMMAND (NULL, cmd, &output, &line_count);16839 RUN_COMMAND (NULL, cmd, &output, &line_count);
16852 nih_free (output);16840 TEST_EQ (line_count, 0);
1685316841
16854 /* check it */16842 /* check it */
16855 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16843 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
@@ -16866,7 +16854,7 @@
16866 name, value);16854 name, value);
16867 TEST_NE_P (cmd, NULL);16855 TEST_NE_P (cmd, NULL);
16868 RUN_COMMAND (NULL, cmd, &output, &line_count);16856 RUN_COMMAND (NULL, cmd, &output, &line_count);
16869 nih_free (output);16857 TEST_EQ (line_count, 0);
1687016858
16871 /* check it again */16859 /* check it again */
16872 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16860 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
@@ -16889,6 +16877,7 @@
16889 RUN_COMMAND (NULL, cmd, &output, &line_count);16877 RUN_COMMAND (NULL, cmd, &output, &line_count);
16890 TEST_EQ (line_count, 1);16878 TEST_EQ (line_count, 1);
16891 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16879 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16880 nih_free (output);
1689216881
16893 /*******************************************************************/16882 /*******************************************************************/
16894 TEST_FEATURE ("set-env --retain");16883 TEST_FEATURE ("set-env --retain");
@@ -16901,7 +16890,7 @@
16901 name, value);16890 name, value);
16902 TEST_NE_P (cmd, NULL);16891 TEST_NE_P (cmd, NULL);
16903 RUN_COMMAND (NULL, cmd, &output, &line_count);16892 RUN_COMMAND (NULL, cmd, &output, &line_count);
16904 nih_free (output);16893 TEST_EQ (line_count, 0);
1690516894
16906 /* check it */16895 /* check it */
16907 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16896 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
@@ -16917,7 +16906,7 @@
16917 get_initctl (), name, "HELLO");16906 get_initctl (), name, "HELLO");
16918 TEST_NE_P (cmd, NULL);16907 TEST_NE_P (cmd, NULL);
16919 RUN_COMMAND (NULL, cmd, &output, &line_count);16908 RUN_COMMAND (NULL, cmd, &output, &line_count);
16920 nih_free (output);16909 TEST_EQ (line_count, 0);
1692116910
16922 /* check that value did *NOT* change */16911 /* check that value did *NOT* change */
16923 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16912 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
@@ -16939,6 +16928,7 @@
16939 RUN_COMMAND (NULL, cmd, &output, &line_count);16928 RUN_COMMAND (NULL, cmd, &output, &line_count);
16940 TEST_EQ (line_count, 1);16929 TEST_EQ (line_count, 1);
16941 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16930 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16931 nih_free (output);
1694216932
16943 /*******************************************************************/16933 /*******************************************************************/
16944 TEST_FEATURE ("set-env with space within value and trailing tab");16934 TEST_FEATURE ("set-env with space within value and trailing tab");
@@ -16950,7 +16940,7 @@
16950 name, value);16940 name, value);
16951 TEST_NE_P (cmd, NULL);16941 TEST_NE_P (cmd, NULL);
16952 RUN_COMMAND (NULL, cmd, &output, &line_count);16942 RUN_COMMAND (NULL, cmd, &output, &line_count);
16953 nih_free (output);16943 TEST_EQ (line_count, 0);
1695416944
16955 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),16945 cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (),
16956 name);16946 name);
@@ -16971,6 +16961,7 @@
16971 RUN_COMMAND (NULL, cmd, &output, &line_count);16961 RUN_COMMAND (NULL, cmd, &output, &line_count);
16972 TEST_EQ (line_count, 1);16962 TEST_EQ (line_count, 1);
16973 TEST_EQ_STR (output[0], "initctl: No such variable: foo");16963 TEST_EQ_STR (output[0], "initctl: No such variable: foo");
16964 nih_free (output);
1697416965
16975 /*******************************************************************/16966 /*******************************************************************/
16976 TEST_FEATURE ("list-env output order");16967 TEST_FEATURE ("list-env output order");
@@ -16981,19 +16972,19 @@
16981 "zygote", "cell");16972 "zygote", "cell");
16982 TEST_NE_P (cmd, NULL);16973 TEST_NE_P (cmd, NULL);
16983 RUN_COMMAND (NULL, cmd, &output, &line_count);16974 RUN_COMMAND (NULL, cmd, &output, &line_count);
16984 nih_free (output);16975 TEST_EQ (line_count, 0);
1698516976
16986 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),16977 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),
16987 "median", "middle");16978 "median", "middle");
16988 TEST_NE_P (cmd, NULL);16979 TEST_NE_P (cmd, NULL);
16989 RUN_COMMAND (NULL, cmd, &output, &line_count);16980 RUN_COMMAND (NULL, cmd, &output, &line_count);
16990 nih_free (output);16981 TEST_EQ (line_count, 0);
1699116982
16992 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),16983 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),
16993 "aardvark", "mammal");16984 "aardvark", "mammal");
16994 TEST_NE_P (cmd, NULL);16985 TEST_NE_P (cmd, NULL);
16995 RUN_COMMAND (NULL, cmd, &output, &line_count);16986 RUN_COMMAND (NULL, cmd, &output, &line_count);
16996 nih_free (output);16987 TEST_EQ (line_count, 0);
1699716988
16998 cmd = nih_sprintf (NULL, "%s list-env 2>&1", get_initctl ());16989 cmd = nih_sprintf (NULL, "%s list-env 2>&1", get_initctl ());
16999 TEST_NE_P (cmd, NULL);16990 TEST_NE_P (cmd, NULL);
@@ -17037,13 +17028,13 @@
17037 "aardvark", "mammal");17028 "aardvark", "mammal");
17038 TEST_NE_P (cmd, NULL);17029 TEST_NE_P (cmd, NULL);
17039 RUN_COMMAND (NULL, cmd, &output, &line_count);17030 RUN_COMMAND (NULL, cmd, &output, &line_count);
17040 nih_free (output);17031 TEST_EQ (line_count, 0);
1704117032
17042 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),17033 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),
17043 "zygote", "cell");17034 "zygote", "cell");
17044 TEST_NE_P (cmd, NULL);17035 TEST_NE_P (cmd, NULL);
17045 RUN_COMMAND (NULL, cmd, &output, &line_count);17036 RUN_COMMAND (NULL, cmd, &output, &line_count);
17046 nih_free (output);17037 TEST_EQ (line_count, 0);
1704717038
17048 cmd = nih_sprintf (NULL, "%s list-env 2>&1", get_initctl ());17039 cmd = nih_sprintf (NULL, "%s list-env 2>&1", get_initctl ());
17049 TEST_NE_P (cmd, NULL);17040 TEST_NE_P (cmd, NULL);
@@ -17067,25 +17058,26 @@
17067 "aardvark", "mammal");17058 "aardvark", "mammal");
17068 TEST_NE_P (cmd, NULL);17059 TEST_NE_P (cmd, NULL);
17069 RUN_COMMAND (NULL, cmd, &output, &line_count);17060 RUN_COMMAND (NULL, cmd, &output, &line_count);
17070 nih_free (output);17061 TEST_EQ (line_count, 0);
1707117062
17072 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),17063 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),
17073 "FOO", "BAR");17064 "FOO", "BAR");
17074 TEST_NE_P (cmd, NULL);17065 TEST_NE_P (cmd, NULL);
17075 RUN_COMMAND (NULL, cmd, &output, &line_count);17066 RUN_COMMAND (NULL, cmd, &output, &line_count);
17076 nih_free (output);17067 TEST_EQ (line_count, 0);
1707717068
17078 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),17069 cmd = nih_sprintf (NULL, "%s set-env %s='%s' 2>&1", get_initctl (),
17079 "_________", "_________");17070 "_________", "_________");
17080 TEST_NE_P (cmd, NULL);17071 TEST_NE_P (cmd, NULL);
17081 RUN_COMMAND (NULL, cmd, &output, &line_count);17072 RUN_COMMAND (NULL, cmd, &output, &line_count);
17082 nih_free (output);17073 TEST_EQ (line_count, 0);
1708317074
17084 CREATE_FILE (confdir, "modified-env.conf", "exec env");17075 CREATE_FILE (confdir, "modified-env.conf", "exec env");
1708517076
17086 cmd = nih_sprintf (NULL, "%s start modified-env 2>&1", get_initctl ());17077 cmd = nih_sprintf (NULL, "%s start modified-env 2>&1", get_initctl ());
17087 TEST_NE_P (cmd, NULL);17078 TEST_NE_P (cmd, NULL);
17088 RUN_COMMAND (NULL, cmd, &output, &line_count);17079 RUN_COMMAND (NULL, cmd, &output, &line_count);
17080 TEST_EQ (line_count, 1);
17089 nih_free (output);17081 nih_free (output);
1709017082
17091 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",17083 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
@@ -17211,6 +17203,7 @@
17211 TEST_NE_P (cmd, NULL);17203 TEST_NE_P (cmd, NULL);
1721217204
17213 RUN_COMMAND (NULL, cmd, &output, &line_count);17205 RUN_COMMAND (NULL, cmd, &output, &line_count);
17206 TEST_EQ (line_count, 1);
17214 nih_free (output);17207 nih_free (output);
1721517208
17216 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",17209 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
@@ -17254,6 +17247,7 @@
17254 cmd = nih_sprintf (NULL, "%s start foo 2>&1", get_initctl ());17247 cmd = nih_sprintf (NULL, "%s start foo 2>&1", get_initctl ());
17255 TEST_NE_P (cmd, NULL);17248 TEST_NE_P (cmd, NULL);
17256 RUN_COMMAND (NULL, cmd, &output, &line_count);17249 RUN_COMMAND (NULL, cmd, &output, &line_count);
17250 TEST_EQ (line_count, 1);
17257 nih_free (output);17251 nih_free (output);
1725817252
17259 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",17253 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
@@ -17333,6 +17327,73 @@
17333 /*******************************************************************/17327 /*******************************************************************/
17334}17328}
1733517329
17330void
17331test_no_inherit_job_env (const char *runtimedir, const char *confdir, const char *logdir)
17332{
17333 nih_local char *cmd = NULL;
17334 char **output;
17335 size_t lines;
17336 pid_t upstart_pid = 0;
17337 char *extra[] = { "--no-inherit-env", NULL };
17338 nih_local char *logfile = NULL;
17339 nih_local char *session_file = NULL;
17340 FILE *fi;
17341
17342 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, extra);
17343
17344 /*******************************************************************/
17345 TEST_FEATURE ("ensure list-env in '--user --no-inherit-env' environment gives expected output");
17346
17347 cmd = nih_sprintf (NULL, "%s list-env 2>&1", get_initctl ());
17348 TEST_NE_P (cmd, NULL);
17349 RUN_COMMAND (NULL, cmd, &output, &lines);
17350
17351 /* environment should comprise the default environment only */
17352 TEST_EQ (lines, 2);
17353 TEST_STR_MATCH (output[0], "PATH=*");
17354 TEST_STR_MATCH (output[1], "TERM=*");
17355 nih_free (output);
17356
17357 /*******************************************************************/
17358 TEST_FEATURE ("ensure '--user --no-inherit-env' provides expected job environment");
17359
17360 CREATE_FILE (confdir, "foo.conf", "exec env");
17361
17362 cmd = nih_sprintf (NULL, "%s start foo 2>&1", get_initctl ());
17363 TEST_NE_P (cmd, NULL);
17364 RUN_COMMAND (NULL, cmd, &output, &lines);
17365 nih_free (output);
17366
17367 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
17368 logdir,
17369 "foo.log"));
17370
17371 WAIT_FOR_FILE (logfile);
17372
17373 fi = fopen (logfile, "r");
17374 TEST_NE_P (fi, NULL);
17375 TEST_FILE_CONTAINS (fi, "PATH=*");
17376 TEST_FILE_CONTAINS (fi, "TERM=*");
17377
17378 /* asterisk required to match '\r\n' */
17379 TEST_FILE_CONTAINS (fi, "UPSTART_JOB=foo*");
17380 TEST_FILE_CONTAINS (fi, "UPSTART_INSTANCE=*");
17381 TEST_FILE_CONTAINS (fi, "UPSTART_SESSION=*");
17382 fclose (fi);
17383
17384 DELETE_FILE (confdir, "foo.conf");
17385 TEST_EQ (unlink (logfile), 0);
17386
17387 /*******************************************************************/
17388
17389 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
17390 runtimedir, (int)upstart_pid));
17391
17392 STOP_UPSTART (upstart_pid);
17393
17394 unlink (session_file);
17395}
17396
17336/*17397/*
17337 * Test all the commands which affect the job environment table together17398 * Test all the commands which affect the job environment table together
17338 * as they are so closely related.17399 * as they are so closely related.
@@ -17376,6 +17437,21 @@
1737617437
17377 TEST_EQ (setenv ("XDG_RUNTIME_DIR", runtimedir, 1), 0);17438 TEST_EQ (setenv ("XDG_RUNTIME_DIR", runtimedir, 1), 0);
1737817439
17440 /*******************************************************************/
17441 /* Ensure basic variables are set in the current environment */
17442
17443 if (! getenv ("TERM")) {
17444 fprintf (stderr, "WARNING: setting TERM to '%s' as not set\n",
17445 TEST_INITCTL_DEFAULT_TERM);
17446 assert0 (setenv ("TERM", TEST_INITCTL_DEFAULT_TERM, 1));
17447 }
17448
17449 if (! getenv ("PATH")) {
17450 fprintf (stderr, "WARNING: setting PATH to '%s' as not set\n",
17451 TEST_INITCTL_DEFAULT_PATH);
17452 assert0 (setenv ("PATH", TEST_INITCTL_DEFAULT_PATH, 1));
17453 }
17454
17379 TEST_DBUS (dbus_pid);17455 TEST_DBUS (dbus_pid);
17380 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);17456 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);
1738117457
@@ -17410,14 +17486,21 @@
17410 /*******************************************************************/17486 /*******************************************************************/
1741117487
17412 STOP_UPSTART (upstart_pid);17488 STOP_UPSTART (upstart_pid);
17489 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
17490 runtimedir, (int)upstart_pid));
17491 unlink (session_file);
17492
17493 /*******************************************************************/
17494
17495 test_no_inherit_job_env (runtimedir, confdir, logdir);
17496
17497 /*******************************************************************/
17498
17413 TEST_DBUS_END (dbus_pid);17499 TEST_DBUS_END (dbus_pid);
17414 assert0 (unsetenv ("UPSTART_CONFDIR"));17500 assert0 (unsetenv ("UPSTART_CONFDIR"));
17415 assert0 (unsetenv ("UPSTART_LOGDIR"));17501 assert0 (unsetenv ("UPSTART_LOGDIR"));
17416 assert0 (unsetenv ("UPSTART_SESSION"));17502 assert0 (unsetenv ("UPSTART_SESSION"));
1741717503
17418 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions/%d.session",
17419 runtimedir, (int)upstart_pid));
17420 unlink (session_file);
17421 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", runtimedir));17504 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", runtimedir));
17422 TEST_EQ (rmdir (session_file), 0);17505 TEST_EQ (rmdir (session_file), 0);
17423 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart", runtimedir));17506 session_file = NIH_MUST (nih_sprintf (NULL, "%s/upstart", runtimedir));

Subscribers

People subscribed via source and target branches