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

Proposed by James Hunt
Status: Merged
Merged at revision: 1552
Proposed branch: lp:~jamesodhunt/upstart/bug-1240686
Merge into: lp:upstart
Diff against target: 528 lines (+170/-40)
8 files modified
ChangeLog (+21/-1)
init/job_class.c (+8/-1)
init/job_process.c (+2/-2)
init/main.c (+8/-3)
init/tests/test_main.c (+8/-8)
test/test_util_common.c (+9/-5)
test/test_util_common.h (+4/-3)
util/tests/test_initctl.c (+110/-17)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/bug-1240686
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Approve
Review via email: mp+191771@code.launchpad.net

Description of the change

* init/job_class.c:
  - job_class_new(): Set umask for job to current value for Session
    Init by default (LP: #1240686).
* init/job_process.c: Comments.
* init/main.c: main(): Save current umask.
* test/test_util_common.c:
  - start_upstart_common(): Add extra param for inheriting environment
    rather than hard-coding '--no-inherit-env'.
  - start_upstart(: Updated call to start_upstart_common().
* init/tests/test_main.c: Updated calls to start_upstart_common().
* test/test_util_common.h: START_UPSTART(): Updated call to
  start_upstart_common().
* util/tests/test_initctl.c:
  - Updated calls to start_upstart_common().
  - test_umask(): New tests:
    - "ensure Session Init inherits umask by default"
    - "ensure Session Init defaults umask with '--no-inherit-env'"

No impact on re-exec since umask is retained across an exec.

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-10-04 21:34:25 +0000
+++ ChangeLog 2013-10-18 09:17:07 +0000
@@ -1,4 +1,24 @@
12013-01-04 Steve Langasek <steve.langasek@ubuntu.com12013-10-18 James Hunt <james.hunt@ubuntu.com>
2
3 * init/job_class.c:
4 - job_class_new(): Set umask for job to current value for Session
5 Init by default (LP: #1240686).
6 * init/job_process.c: Comments.
7 * init/main.c: main(): Save current umask.
8 * test/test_util_common.c:
9 - start_upstart_common(): Add extra param for inheriting environment
10 rather than hard-coding '--no-inherit-env'.
11 - start_upstart(: Updated call to start_upstart_common().
12 * init/tests/test_main.c: Updated calls to start_upstart_common().
13 * test/test_util_common.h: START_UPSTART(): Updated call to
14 start_upstart_common().
15 * util/tests/test_initctl.c:
16 - Updated calls to start_upstart_common().
17 - test_umask(): New tests:
18 - "ensure Session Init inherits umask by default"
19 - "ensure Session Init defaults umask with '--no-inherit-env'"
20
212013-10-04 Steve Langasek <steve.langasek@ubuntu.com
222
3 * extra/upstart-local-bridge.c: use SOCKET_PATH in our event23 * extra/upstart-local-bridge.c: use SOCKET_PATH in our event
4 environment, instead of clobbering PATH. (LP: #1235480)24 environment, instead of clobbering PATH. (LP: #1235480)
525
=== modified file 'init/job_class.c'
--- init/job_class.c 2013-07-22 00:15:43 +0000
+++ init/job_class.c 2013-10-18 09:17:07 +0000
@@ -97,6 +97,13 @@
97static char **job_environ = NULL;97static char **job_environ = NULL;
9898
99/**99/**
100 * initial_umask:
101 *
102 * Value of umask at startup.
103 **/
104mode_t initial_umask;
105
106/**
100 * job_class_init:107 * job_class_init:
101 *108 *
102 * Initialise the job classes hash table.109 * Initialise the job classes hash table.
@@ -353,7 +360,7 @@
353360
354 class->console = default_console >= 0 ? default_console : CONSOLE_LOG;361 class->console = default_console >= 0 ? default_console : CONSOLE_LOG;
355362
356 class->umask = JOB_DEFAULT_UMASK;363 class->umask = (user_mode && ! no_inherit_env) ? initial_umask : JOB_DEFAULT_UMASK;
357 class->nice = JOB_NICE_INVALID;364 class->nice = JOB_NICE_INVALID;
358 class->oom_score_adj = JOB_DEFAULT_OOM_SCORE_ADJ;365 class->oom_score_adj = JOB_DEFAULT_OOM_SCORE_ADJ;
359366
360367
=== modified file 'init/job_process.c'
--- init/job_process.c 2013-10-03 14:43:24 +0000
+++ init/job_process.c 2013-10-18 09:17:07 +0000
@@ -126,11 +126,11 @@
126/**126/**
127 * no_inherit_env:127 * no_inherit_env:
128 *128 *
129 * If TRUE, do not copy the Session Inits environment to that provided to jobs.129 * If TRUE, do not copy the Session Inits environment variables or umask
130 * to that provided to jobs.
130 **/131 **/
131int no_inherit_env = FALSE;132int no_inherit_env = FALSE;
132133
133
134/* Prototypes for static functions */134/* Prototypes for static functions */
135static void job_process_kill_timer (Job *job, NihTimer *timer);135static void job_process_kill_timer (Job *job, NihTimer *timer);
136static void job_process_terminated (Job *job, ProcessType process,136static void job_process_terminated (Job *job, ProcessType process,
137137
=== modified file 'init/main.c'
--- init/main.c 2013-07-31 09:28:48 +0000
+++ init/main.c 2013-10-18 09:17:07 +0000
@@ -128,7 +128,7 @@
128extern int default_console;128extern int default_console;
129extern int write_state_file;129extern int write_state_file;
130extern char *log_dir;130extern char *log_dir;
131131extern mode_t initial_umask;
132132
133/**133/**
134 * options:134 * options:
@@ -143,7 +143,7 @@
143 NULL, "VALUE", NULL, console_type_setter },143 NULL, "VALUE", NULL, console_type_setter },
144144
145 { 0, "no-inherit-env", N_("jobs will not inherit environment of init"),145 { 0, "no-inherit-env", N_("jobs will not inherit environment of init"),
146 NULL, NULL, &no_inherit_env ,NULL },146 NULL, NULL, &no_inherit_env , NULL },
147147
148 { 0, "logdir", N_("specify alternative directory to store job output logs in"),148 { 0, "logdir", N_("specify alternative directory to store job output logs in"),
149 NULL, "DIR", &log_dir, NULL },149 NULL, "DIR", &log_dir, NULL },
@@ -270,7 +270,7 @@
270 /* Allow devices to be created with the actual perms270 /* Allow devices to be created with the actual perms
271 * specified.271 * specified.
272 */272 */
273 (void)umask (0);273 initial_umask = umask (0);
274274
275 /* Check if key /dev entries already exist; if they do,275 /* Check if key /dev entries already exist; if they do,
276 * we should assume we don't need to mount /dev.276 * we should assume we don't need to mount /dev.
@@ -385,6 +385,11 @@
385 (int)getuid (), (int)getpid (), (int)getppid ());385 (int)getuid (), (int)getpid (), (int)getppid ());
386#endif /* DEBUG */386#endif /* DEBUG */
387387
388 if (user_mode) {
389 /* Save initial value */
390 initial_umask = umask (0);
391 (void)umask (initial_umask);
392 }
388393
389 /* Reset the signal state and install the signal handler for those394 /* Reset the signal state and install the signal handler for those
390 * signals we actually want to catch; this also sets those that395 * signals we actually want to catch; this also sets those that
391396
=== modified file 'init/tests/test_main.c'
--- init/tests/test_main.c 2013-06-25 09:19:05 +0000
+++ init/tests/test_main.c 2013-10-18 09:17:07 +0000
@@ -107,7 +107,7 @@
107 CREATE_FILE (xdg_conf_dir, "bar.conf", "exec true");107 CREATE_FILE (xdg_conf_dir, "bar.conf", "exec true");
108 CREATE_FILE (xdg_conf_dir, "baz.conf", "exec true");108 CREATE_FILE (xdg_conf_dir, "baz.conf", "exec true");
109109
110 start_upstart_common (&upstart_pid, TRUE, NULL, logdir, NULL);110 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, NULL);
111111
112 /* Should be running */112 /* Should be running */
113 assert0 (kill (upstart_pid, 0));113 assert0 (kill (upstart_pid, 0));
@@ -139,7 +139,7 @@
139 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");139 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");
140 CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true");140 CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true");
141141
142 start_upstart_common (&upstart_pid, TRUE, confdir_a, logdir, NULL);142 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir_a, logdir, NULL);
143143
144 /* Should be running */144 /* Should be running */
145 assert0 (kill (upstart_pid, 0));145 assert0 (kill (upstart_pid, 0));
@@ -177,7 +177,7 @@
177 extra[4] = NULL;177 extra[4] = NULL;
178178
179 /* pass 2 confdir directories */179 /* pass 2 confdir directories */
180 start_upstart_common (&upstart_pid, TRUE, NULL, logdir, extra);180 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
181181
182 /* Should be running */182 /* Should be running */
183 assert0 (kill (upstart_pid, 0));183 assert0 (kill (upstart_pid, 0));
@@ -217,7 +217,7 @@
217 extra[4] = NULL;217 extra[4] = NULL;
218218
219 /* pass 2 confdir directories */219 /* pass 2 confdir directories */
220 start_upstart_common (&upstart_pid, TRUE, NULL, logdir, extra);220 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
221221
222 /* Should be running */222 /* Should be running */
223 assert0 (kill (upstart_pid, 0));223 assert0 (kill (upstart_pid, 0));
@@ -266,7 +266,7 @@
266 /* Disable user mode */266 /* Disable user mode */
267 test_user_mode = FALSE;267 test_user_mode = FALSE;
268268
269 start_upstart_common (&upstart_pid, FALSE, NULL, logdir, NULL);269 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, NULL);
270270
271 /* Should be running */271 /* Should be running */
272 assert0 (kill (upstart_pid, 0));272 assert0 (kill (upstart_pid, 0));
@@ -296,7 +296,7 @@
296 CREATE_FILE (confdir_a, "bar.conf", "exec true");296 CREATE_FILE (confdir_a, "bar.conf", "exec true");
297 CREATE_FILE (confdir_b, "baz.conf", "exec true");297 CREATE_FILE (confdir_b, "baz.conf", "exec true");
298298
299 start_upstart_common (&upstart_pid, FALSE, confdir_b, logdir, NULL);299 start_upstart_common (&upstart_pid, FALSE, FALSE, confdir_b, logdir, NULL);
300300
301 /* Should be running */301 /* Should be running */
302 assert0 (kill (upstart_pid, 0));302 assert0 (kill (upstart_pid, 0));
@@ -333,7 +333,7 @@
333 extra[3] = confdir_b;333 extra[3] = confdir_b;
334 extra[4] = NULL;334 extra[4] = NULL;
335335
336 start_upstart_common (&upstart_pid, FALSE, NULL, logdir, extra);336 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
337337
338 /* Should be running */338 /* Should be running */
339 assert0 (kill (upstart_pid, 0));339 assert0 (kill (upstart_pid, 0));
@@ -376,7 +376,7 @@
376 extra[3] = confdir_b;376 extra[3] = confdir_b;
377 extra[4] = NULL;377 extra[4] = NULL;
378378
379 start_upstart_common (&upstart_pid, FALSE, NULL, logdir, extra);379 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
380380
381 /* Should be running */381 /* Should be running */
382 assert0 (kill (upstart_pid, 0));382 assert0 (kill (upstart_pid, 0));
383383
=== modified file 'test/test_util_common.c'
--- test/test_util_common.c 2013-10-02 08:59:20 +0000
+++ test/test_util_common.c 2013-10-18 09:17:07 +0000
@@ -420,6 +420,7 @@
420 * @pid: PID of running instance,420 * @pid: PID of running instance,
421 * @user: TRUE if upstart should run in User Session mode (FALSE to421 * @user: TRUE if upstart should run in User Session mode (FALSE to
422 * use the users D-Bus session bus),422 * use the users D-Bus session bus),
423 * @inherit_env: if TRUE, inherit parent environment,
423 * @confdir: full path to configuration directory,424 * @confdir: full path to configuration directory,
424 * @logdir: full path to log directory,425 * @logdir: full path to log directory,
425 * @extra: optional extra arguments.426 * @extra: optional extra arguments.
@@ -427,8 +428,9 @@
427 * Wrapper round _start_upstart() which specifies common options.428 * Wrapper round _start_upstart() which specifies common options.
428 **/429 **/
429void430void
430start_upstart_common (pid_t *pid, int user, const char *confdir,431start_upstart_common (pid_t *pid, int user, int inherit_env,
431 const char *logdir, char * const *extra)432 const char *confdir, const char *logdir,
433 char * const *extra)
432{434{
433 nih_local char **args = NULL;435 nih_local char **args = NULL;
434436
@@ -449,8 +451,10 @@
449 NIH_MUST (nih_str_array_add (&args, NULL, NULL,451 NIH_MUST (nih_str_array_add (&args, NULL, NULL,
450 "--no-sessions"));452 "--no-sessions"));
451453
452 NIH_MUST (nih_str_array_add (&args, NULL, NULL,454 if (! inherit_env) {
453 "--no-inherit-env"));455 NIH_MUST (nih_str_array_add (&args, NULL, NULL,
456 "--no-inherit-env"));
457 }
454458
455 if (confdir) {459 if (confdir) {
456 NIH_MUST (nih_str_array_add (&args, NULL, NULL,460 NIH_MUST (nih_str_array_add (&args, NULL, NULL,
@@ -483,7 +487,7 @@
483void487void
484start_upstart (pid_t *pid)488start_upstart (pid_t *pid)
485{489{
486 start_upstart_common (pid, FALSE, NULL, NULL, NULL);490 start_upstart_common (pid, FALSE, FALSE, NULL, NULL, NULL);
487}491}
488492
489/**493/**
490494
=== modified file 'test/test_util_common.h'
--- test/test_util_common.h 2013-09-26 16:33:07 +0000
+++ test/test_util_common.h 2013-10-18 09:17:07 +0000
@@ -341,7 +341,7 @@
341 * Start an instance of Upstart and return PID in @pid.341 * Start an instance of Upstart and return PID in @pid.
342 **/342 **/
343#define START_UPSTART(pid, user_mode) \343#define START_UPSTART(pid, user_mode) \
344 start_upstart_common (&(pid), user_mode, NULL, NULL, NULL)344 start_upstart_common (&(pid), user_mode, FALSE, NULL, NULL, NULL)
345345
346/**346/**
347 * KILL_UPSTART:347 * KILL_UPSTART:
@@ -700,8 +700,9 @@
700700
701void _start_upstart (pid_t *pid, int user, char * const *args);701void _start_upstart (pid_t *pid, int user, char * const *args);
702702
703void start_upstart_common (pid_t *pid, int user, const char *confdir,703void start_upstart_common (pid_t *pid, int user, int inherit_env,
704 const char *logdir, char * const *extra);704 const char *confdir, const char *logdir,
705 char * const *extra);
705706
706void start_upstart (pid_t *pid);707void start_upstart (pid_t *pid);
707708
708709
=== modified file 'util/tests/test_initctl.c'
--- util/tests/test_initctl.c 2013-09-26 16:33:07 +0000
+++ util/tests/test_initctl.c 2013-10-18 09:17:07 +0000
@@ -10839,7 +10839,7 @@
10839 /*******************************************************************/10839 /*******************************************************************/
10840 TEST_FEATURE ("single job producing output across a re-exec");10840 TEST_FEATURE ("single job producing output across a re-exec");
1084110841
10842 start_upstart_common (&upstart_pid, FALSE, confdir, logdir, NULL);10842 start_upstart_common (&upstart_pid, FALSE, FALSE, confdir, logdir, NULL);
1084310843
10844 contents = nih_sprintf (NULL, 10844 contents = nih_sprintf (NULL,
10845 "pre-start exec echo pre-start\n"10845 "pre-start exec echo pre-start\n"
@@ -11059,7 +11059,7 @@
11059 /* Reset initctl global from previous tests */11059 /* Reset initctl global from previous tests */
11060 dest_name = NULL;11060 dest_name = NULL;
1106111061
11062 start_upstart_common (&upstart_pid, TRUE, NULL, NULL, NULL);11062 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, NULL, NULL);
1106311063
11064 session_file = get_session_file (dirname, upstart_pid);11064 session_file = get_session_file (dirname, upstart_pid);
1106511065
@@ -11168,7 +11168,7 @@
11168 /*******************************************************************/11168 /*******************************************************************/
11169 TEST_FEATURE ("system shutdown: no jobs");11169 TEST_FEATURE ("system shutdown: no jobs");
1117011170
11171 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11171 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1117211172
11173 /* Should be running */11173 /* Should be running */
11174 assert0 (kill (upstart_pid, 0));11174 assert0 (kill (upstart_pid, 0));
@@ -11194,7 +11194,7 @@
11194 CREATE_FILE (confdir, "long-running.conf",11194 CREATE_FILE (confdir, "long-running.conf",
11195 "exec sleep 999");11195 "exec sleep 999");
1119611196
11197 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11197 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1119811198
11199 /* Should be running */11199 /* Should be running */
11200 assert0 (kill (upstart_pid, 0));11200 assert0 (kill (upstart_pid, 0));
@@ -11276,7 +11276,7 @@
11276 " sleep 999\n"11276 " sleep 999\n"
11277 "end script");11277 "end script");
1127811278
11279 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11279 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1128011280
11281 /* Should be running */11281 /* Should be running */
11282 assert0 (kill (upstart_pid, 0));11282 assert0 (kill (upstart_pid, 0));
@@ -11329,7 +11329,7 @@
1132911329
11330 CREATE_FILE (confdir, "session-end.conf", job);11330 CREATE_FILE (confdir, "session-end.conf", job);
1133111331
11332 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11332 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1133311333
11334 /* Should be running */11334 /* Should be running */
11335 assert0 (kill (upstart_pid, 0));11335 assert0 (kill (upstart_pid, 0));
@@ -11392,7 +11392,7 @@
1139211392
11393 CREATE_FILE (confdir, "session-end-term.conf", job);11393 CREATE_FILE (confdir, "session-end-term.conf", job);
1139411394
11395 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11395 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1139611396
11397 /* Should be running */11397 /* Should be running */
11398 assert0 (kill (upstart_pid, 0));11398 assert0 (kill (upstart_pid, 0));
@@ -11460,7 +11460,7 @@
1146011460
11461 CREATE_FILE (confdir, "session-end-term.conf", job);11461 CREATE_FILE (confdir, "session-end-term.conf", job);
1146211462
11463 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11463 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1146411464
11465 /* Should be running */11465 /* Should be running */
11466 assert0 (kill (upstart_pid, 0));11466 assert0 (kill (upstart_pid, 0));
@@ -11512,7 +11512,7 @@
11512 /*******************************************************************/11512 /*******************************************************************/
11513 TEST_FEATURE ("session shutdown: no jobs");11513 TEST_FEATURE ("session shutdown: no jobs");
1151411514
11515 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11515 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1151611516
11517 /* Further required initctl global resets. Shudder. */11517 /* Further required initctl global resets. Shudder. */
11518 user_mode = TRUE;11518 user_mode = TRUE;
@@ -11548,7 +11548,7 @@
11548 CREATE_FILE (confdir, "long-running.conf",11548 CREATE_FILE (confdir, "long-running.conf",
11549 "exec sleep 999");11549 "exec sleep 999");
1155011550
11551 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11551 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1155211552
11553 cmd = nih_sprintf (NULL, "%s start %s 2>&1",11553 cmd = nih_sprintf (NULL, "%s start %s 2>&1",
11554 get_initctl (), "long-running");11554 get_initctl (), "long-running");
@@ -11596,7 +11596,7 @@
11596 "start on startup\n"11596 "start on startup\n"
11597 "exec sleep 999");11597 "exec sleep 999");
1159811598
11599 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11599 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1160011600
11601 upstart = upstart_open (NULL);11601 upstart = upstart_open (NULL);
11602 TEST_NE_P (upstart, NULL);11602 TEST_NE_P (upstart, NULL);
@@ -11641,7 +11641,7 @@
11641 " sleep 999\n"11641 " sleep 999\n"
11642 "end script");11642 "end script");
1164311643
11644 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11644 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1164511645
11646 cmd = nih_sprintf (NULL, "%s start %s 2>&1",11646 cmd = nih_sprintf (NULL, "%s start %s 2>&1",
11647 get_initctl (), "long-running-term");11647 get_initctl (), "long-running-term");
@@ -11697,7 +11697,7 @@
1169711697
11698 CREATE_FILE (confdir, "session-end.conf", job);11698 CREATE_FILE (confdir, "session-end.conf", job);
1169911699
11700 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11700 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1170111701
11702 upstart = upstart_open (NULL);11702 upstart = upstart_open (NULL);
11703 TEST_NE_P (upstart, NULL);11703 TEST_NE_P (upstart, NULL);
@@ -11760,7 +11760,7 @@
1176011760
11761 CREATE_FILE (confdir, "session-end-term.conf", job);11761 CREATE_FILE (confdir, "session-end-term.conf", job);
1176211762
11763 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11763 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1176411764
11765 upstart = upstart_open (NULL);11765 upstart = upstart_open (NULL);
11766 TEST_NE_P (upstart, NULL);11766 TEST_NE_P (upstart, NULL);
@@ -11830,7 +11830,7 @@
1183011830
11831 CREATE_FILE (confdir, "session-end-term.conf", job);11831 CREATE_FILE (confdir, "session-end-term.conf", job);
1183211832
11833 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);11833 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1183411834
11835 cmd = nih_sprintf (NULL, "%s start %s 2>&1",11835 cmd = nih_sprintf (NULL, "%s start %s 2>&1",
11836 get_initctl (), "long-running-term");11836 get_initctl (), "long-running-term");
@@ -11906,6 +11906,98 @@
11906}11906}
1190711907
11908void11908void
11909test_umask (void)
11910{
11911 char confdir[PATH_MAX];
11912 char logdir[PATH_MAX];
11913 pid_t upstart_pid = 0;
11914 nih_local char *logfile = NULL;
11915 mode_t job_umask;
11916 nih_local char *job_umask_str = NULL;
11917 size_t length;
11918 int ret;
11919 mode_t original_umask;
11920 mode_t test_umask = 0111;
11921 mode_t default_umask = 022;
11922
11923 TEST_FILENAME (confdir);
11924 TEST_EQ (mkdir (confdir, 0755), 0);
11925
11926 TEST_FILENAME (logdir);
11927 TEST_EQ (mkdir (logdir, 0755), 0);
11928
11929 original_umask = umask (test_umask);
11930
11931 TEST_GROUP ("Session Init umask value");
11932
11933 /**********************************************************************/
11934 TEST_FEATURE ("ensure Session Init inherits umask by default");
11935
11936 /* Has to be a script since umask is a shell built-in */
11937 CREATE_FILE (confdir, "umask.conf",
11938 "start on startup\n"
11939 "script\n"
11940 "umask\n"
11941 "end script");
11942
11943 start_upstart_common (&upstart_pid, TRUE, TRUE, confdir, logdir, NULL);
11944
11945 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
11946 logdir,
11947 "umask.log"));
11948
11949 WAIT_FOR_FILE (logfile);
11950
11951 job_umask_str = nih_file_read (NULL, logfile, &length);
11952
11953 ret = sscanf (job_umask_str, "%o", (unsigned int *)&job_umask);
11954 TEST_EQ (ret, 1);
11955 TEST_EQ (job_umask, test_umask);
11956
11957 DELETE_FILE (confdir, "umask.conf");
11958 assert0 (unlink (logfile));
11959
11960 STOP_UPSTART (upstart_pid);
11961
11962 /**********************************************************************/
11963 TEST_FEATURE ("ensure Session Init defaults umask with '--no-inherit-env'");
11964
11965 /* Has to be a script since umask is a shell built-in */
11966 CREATE_FILE (confdir, "umask.conf",
11967 "start on startup\n"
11968 "script\n"
11969 "umask\n"
11970 "end script");
11971
11972 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
11973
11974 logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s",
11975 logdir,
11976 "umask.log"));
11977
11978 WAIT_FOR_FILE (logfile);
11979
11980 job_umask_str = nih_file_read (NULL, logfile, &length);
11981
11982 ret = sscanf (job_umask_str, "%o", (unsigned int *)&job_umask);
11983 TEST_EQ (ret, 1);
11984 TEST_EQ (job_umask, default_umask);
11985
11986 DELETE_FILE (confdir, "umask.conf");
11987 assert0 (unlink (logfile));
11988
11989 STOP_UPSTART (upstart_pid);
11990
11991 /**********************************************************************/
11992
11993 /* Restore */
11994 (void)umask (original_umask);
11995
11996 assert0 (rmdir (confdir));
11997 assert0 (rmdir (logdir));
11998}
11999
12000void
11909test_show_config (void)12001test_show_config (void)
11910{12002{
11911 char dirname[PATH_MAX];12003 char dirname[PATH_MAX];
@@ -16519,7 +16611,7 @@
16519 nih_local char *session_file = NULL;16611 nih_local char *session_file = NULL;
16520 FILE *fi;16612 FILE *fi;
1652116613
16522 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, extra);16614 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, extra);
1652316615
16524 /*******************************************************************/16616 /*******************************************************************/
16525 TEST_FEATURE ("ensure list-env in '--user --no-inherit-env' environment gives expected output");16617 TEST_FEATURE ("ensure list-env in '--user --no-inherit-env' environment gives expected output");
@@ -16633,7 +16725,7 @@
16633 }16725 }
1663416726
16635 TEST_DBUS (dbus_pid);16727 TEST_DBUS (dbus_pid);
16636 start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL);16728 start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL);
1663716729
16638 cmd = nih_sprintf (NULL, "%s list-sessions 2>&1", get_initctl_binary ());16730 cmd = nih_sprintf (NULL, "%s list-sessions 2>&1", get_initctl_binary ());
16639 TEST_NE_P (cmd, NULL);16731 TEST_NE_P (cmd, NULL);
@@ -16727,6 +16819,7 @@
16727 test_reexec ();16819 test_reexec ();
16728 test_list_sessions ();16820 test_list_sessions ();
16729 test_quiesce ();16821 test_quiesce ();
16822 test_umask ();
1673016823
16731 if (in_chroot () && !dbus_configured ()) {16824 if (in_chroot () && !dbus_configured ()) {
16732 fprintf(stderr, "\n\n"16825 fprintf(stderr, "\n\n"

Subscribers

People subscribed via source and target branches