Merge lp:~jamesodhunt/upstart/bug-1240686 into lp:upstart
- bug-1240686
- Merge into trunk
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Approve | ||
Review via email: mp+191771@code.launchpad.net |
Commit message
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_
- start_upstart_
rather than hard-coding '--no-inherit-env'.
- start_upstart(: Updated call to start_upstart_
* init/tests/
* test/test_
start_
* util/tests/
- Updated calls to start_upstart_
- 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.
Preview Diff
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2013-10-04 21:34:25 +0000 | |||
3 | +++ ChangeLog 2013-10-18 09:17:07 +0000 | |||
4 | @@ -1,4 +1,24 @@ | |||
6 | 1 | 2013-01-04 Steve Langasek <steve.langasek@ubuntu.com | 1 | 2013-10-18 James Hunt <james.hunt@ubuntu.com> |
7 | 2 | |||
8 | 3 | * init/job_class.c: | ||
9 | 4 | - job_class_new(): Set umask for job to current value for Session | ||
10 | 5 | Init by default (LP: #1240686). | ||
11 | 6 | * init/job_process.c: Comments. | ||
12 | 7 | * init/main.c: main(): Save current umask. | ||
13 | 8 | * test/test_util_common.c: | ||
14 | 9 | - start_upstart_common(): Add extra param for inheriting environment | ||
15 | 10 | rather than hard-coding '--no-inherit-env'. | ||
16 | 11 | - start_upstart(: Updated call to start_upstart_common(). | ||
17 | 12 | * init/tests/test_main.c: Updated calls to start_upstart_common(). | ||
18 | 13 | * test/test_util_common.h: START_UPSTART(): Updated call to | ||
19 | 14 | start_upstart_common(). | ||
20 | 15 | * util/tests/test_initctl.c: | ||
21 | 16 | - Updated calls to start_upstart_common(). | ||
22 | 17 | - test_umask(): New tests: | ||
23 | 18 | - "ensure Session Init inherits umask by default" | ||
24 | 19 | - "ensure Session Init defaults umask with '--no-inherit-env'" | ||
25 | 20 | |||
26 | 21 | 2013-10-04 Steve Langasek <steve.langasek@ubuntu.com | ||
27 | 2 | 22 | ||
28 | 3 | * extra/upstart-local-bridge.c: use SOCKET_PATH in our event | 23 | * extra/upstart-local-bridge.c: use SOCKET_PATH in our event |
29 | 4 | environment, instead of clobbering PATH. (LP: #1235480) | 24 | environment, instead of clobbering PATH. (LP: #1235480) |
30 | 5 | 25 | ||
31 | === modified file 'init/job_class.c' | |||
32 | --- init/job_class.c 2013-07-22 00:15:43 +0000 | |||
33 | +++ init/job_class.c 2013-10-18 09:17:07 +0000 | |||
34 | @@ -97,6 +97,13 @@ | |||
35 | 97 | static char **job_environ = NULL; | 97 | static char **job_environ = NULL; |
36 | 98 | 98 | ||
37 | 99 | /** | 99 | /** |
38 | 100 | * initial_umask: | ||
39 | 101 | * | ||
40 | 102 | * Value of umask at startup. | ||
41 | 103 | **/ | ||
42 | 104 | mode_t initial_umask; | ||
43 | 105 | |||
44 | 106 | /** | ||
45 | 100 | * job_class_init: | 107 | * job_class_init: |
46 | 101 | * | 108 | * |
47 | 102 | * Initialise the job classes hash table. | 109 | * Initialise the job classes hash table. |
48 | @@ -353,7 +360,7 @@ | |||
49 | 353 | 360 | ||
50 | 354 | class->console = default_console >= 0 ? default_console : CONSOLE_LOG; | 361 | class->console = default_console >= 0 ? default_console : CONSOLE_LOG; |
51 | 355 | 362 | ||
53 | 356 | class->umask = JOB_DEFAULT_UMASK; | 363 | class->umask = (user_mode && ! no_inherit_env) ? initial_umask : JOB_DEFAULT_UMASK; |
54 | 357 | class->nice = JOB_NICE_INVALID; | 364 | class->nice = JOB_NICE_INVALID; |
55 | 358 | class->oom_score_adj = JOB_DEFAULT_OOM_SCORE_ADJ; | 365 | class->oom_score_adj = JOB_DEFAULT_OOM_SCORE_ADJ; |
56 | 359 | 366 | ||
57 | 360 | 367 | ||
58 | === modified file 'init/job_process.c' | |||
59 | --- init/job_process.c 2013-10-03 14:43:24 +0000 | |||
60 | +++ init/job_process.c 2013-10-18 09:17:07 +0000 | |||
61 | @@ -126,11 +126,11 @@ | |||
62 | 126 | /** | 126 | /** |
63 | 127 | * no_inherit_env: | 127 | * no_inherit_env: |
64 | 128 | * | 128 | * |
66 | 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 |
67 | 130 | * to that provided to jobs. | ||
68 | 130 | **/ | 131 | **/ |
69 | 131 | int no_inherit_env = FALSE; | 132 | int no_inherit_env = FALSE; |
70 | 132 | 133 | ||
71 | 133 | |||
72 | 134 | /* Prototypes for static functions */ | 134 | /* Prototypes for static functions */ |
73 | 135 | static void job_process_kill_timer (Job *job, NihTimer *timer); | 135 | static void job_process_kill_timer (Job *job, NihTimer *timer); |
74 | 136 | static void job_process_terminated (Job *job, ProcessType process, | 136 | static void job_process_terminated (Job *job, ProcessType process, |
75 | 137 | 137 | ||
76 | === modified file 'init/main.c' | |||
77 | --- init/main.c 2013-07-31 09:28:48 +0000 | |||
78 | +++ init/main.c 2013-10-18 09:17:07 +0000 | |||
79 | @@ -128,7 +128,7 @@ | |||
80 | 128 | extern int default_console; | 128 | extern int default_console; |
81 | 129 | extern int write_state_file; | 129 | extern int write_state_file; |
82 | 130 | extern char *log_dir; | 130 | extern char *log_dir; |
84 | 131 | 131 | extern mode_t initial_umask; | |
85 | 132 | 132 | ||
86 | 133 | /** | 133 | /** |
87 | 134 | * options: | 134 | * options: |
88 | @@ -143,7 +143,7 @@ | |||
89 | 143 | NULL, "VALUE", NULL, console_type_setter }, | 143 | NULL, "VALUE", NULL, console_type_setter }, |
90 | 144 | 144 | ||
91 | 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"), |
93 | 146 | NULL, NULL, &no_inherit_env ,NULL }, | 146 | NULL, NULL, &no_inherit_env , NULL }, |
94 | 147 | 147 | ||
95 | 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"), |
96 | 149 | NULL, "DIR", &log_dir, NULL }, | 149 | NULL, "DIR", &log_dir, NULL }, |
97 | @@ -270,7 +270,7 @@ | |||
98 | 270 | /* Allow devices to be created with the actual perms | 270 | /* Allow devices to be created with the actual perms |
99 | 271 | * specified. | 271 | * specified. |
100 | 272 | */ | 272 | */ |
102 | 273 | (void)umask (0); | 273 | initial_umask = umask (0); |
103 | 274 | 274 | ||
104 | 275 | /* Check if key /dev entries already exist; if they do, | 275 | /* Check if key /dev entries already exist; if they do, |
105 | 276 | * we should assume we don't need to mount /dev. | 276 | * we should assume we don't need to mount /dev. |
106 | @@ -385,6 +385,11 @@ | |||
107 | 385 | (int)getuid (), (int)getpid (), (int)getppid ()); | 385 | (int)getuid (), (int)getpid (), (int)getppid ()); |
108 | 386 | #endif /* DEBUG */ | 386 | #endif /* DEBUG */ |
109 | 387 | 387 | ||
110 | 388 | if (user_mode) { | ||
111 | 389 | /* Save initial value */ | ||
112 | 390 | initial_umask = umask (0); | ||
113 | 391 | (void)umask (initial_umask); | ||
114 | 392 | } | ||
115 | 388 | 393 | ||
116 | 389 | /* Reset the signal state and install the signal handler for those | 394 | /* Reset the signal state and install the signal handler for those |
117 | 390 | * signals we actually want to catch; this also sets those that | 395 | * signals we actually want to catch; this also sets those that |
118 | 391 | 396 | ||
119 | === modified file 'init/tests/test_main.c' | |||
120 | --- init/tests/test_main.c 2013-06-25 09:19:05 +0000 | |||
121 | +++ init/tests/test_main.c 2013-10-18 09:17:07 +0000 | |||
122 | @@ -107,7 +107,7 @@ | |||
123 | 107 | CREATE_FILE (xdg_conf_dir, "bar.conf", "exec true"); | 107 | CREATE_FILE (xdg_conf_dir, "bar.conf", "exec true"); |
124 | 108 | CREATE_FILE (xdg_conf_dir, "baz.conf", "exec true"); | 108 | CREATE_FILE (xdg_conf_dir, "baz.conf", "exec true"); |
125 | 109 | 109 | ||
127 | 110 | start_upstart_common (&upstart_pid, TRUE, NULL, logdir, NULL); | 110 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, NULL); |
128 | 111 | 111 | ||
129 | 112 | /* Should be running */ | 112 | /* Should be running */ |
130 | 113 | assert0 (kill (upstart_pid, 0)); | 113 | assert0 (kill (upstart_pid, 0)); |
131 | @@ -139,7 +139,7 @@ | |||
132 | 139 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); | 139 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); |
133 | 140 | CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true"); | 140 | CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true"); |
134 | 141 | 141 | ||
136 | 142 | start_upstart_common (&upstart_pid, TRUE, confdir_a, logdir, NULL); | 142 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir_a, logdir, NULL); |
137 | 143 | 143 | ||
138 | 144 | /* Should be running */ | 144 | /* Should be running */ |
139 | 145 | assert0 (kill (upstart_pid, 0)); | 145 | assert0 (kill (upstart_pid, 0)); |
140 | @@ -177,7 +177,7 @@ | |||
141 | 177 | extra[4] = NULL; | 177 | extra[4] = NULL; |
142 | 178 | 178 | ||
143 | 179 | /* pass 2 confdir directories */ | 179 | /* pass 2 confdir directories */ |
145 | 180 | start_upstart_common (&upstart_pid, TRUE, NULL, logdir, extra); | 180 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); |
146 | 181 | 181 | ||
147 | 182 | /* Should be running */ | 182 | /* Should be running */ |
148 | 183 | assert0 (kill (upstart_pid, 0)); | 183 | assert0 (kill (upstart_pid, 0)); |
149 | @@ -217,7 +217,7 @@ | |||
150 | 217 | extra[4] = NULL; | 217 | extra[4] = NULL; |
151 | 218 | 218 | ||
152 | 219 | /* pass 2 confdir directories */ | 219 | /* pass 2 confdir directories */ |
154 | 220 | start_upstart_common (&upstart_pid, TRUE, NULL, logdir, extra); | 220 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); |
155 | 221 | 221 | ||
156 | 222 | /* Should be running */ | 222 | /* Should be running */ |
157 | 223 | assert0 (kill (upstart_pid, 0)); | 223 | assert0 (kill (upstart_pid, 0)); |
158 | @@ -266,7 +266,7 @@ | |||
159 | 266 | /* Disable user mode */ | 266 | /* Disable user mode */ |
160 | 267 | test_user_mode = FALSE; | 267 | test_user_mode = FALSE; |
161 | 268 | 268 | ||
163 | 269 | start_upstart_common (&upstart_pid, FALSE, NULL, logdir, NULL); | 269 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, NULL); |
164 | 270 | 270 | ||
165 | 271 | /* Should be running */ | 271 | /* Should be running */ |
166 | 272 | assert0 (kill (upstart_pid, 0)); | 272 | assert0 (kill (upstart_pid, 0)); |
167 | @@ -296,7 +296,7 @@ | |||
168 | 296 | CREATE_FILE (confdir_a, "bar.conf", "exec true"); | 296 | CREATE_FILE (confdir_a, "bar.conf", "exec true"); |
169 | 297 | CREATE_FILE (confdir_b, "baz.conf", "exec true"); | 297 | CREATE_FILE (confdir_b, "baz.conf", "exec true"); |
170 | 298 | 298 | ||
172 | 299 | start_upstart_common (&upstart_pid, FALSE, confdir_b, logdir, NULL); | 299 | start_upstart_common (&upstart_pid, FALSE, FALSE, confdir_b, logdir, NULL); |
173 | 300 | 300 | ||
174 | 301 | /* Should be running */ | 301 | /* Should be running */ |
175 | 302 | assert0 (kill (upstart_pid, 0)); | 302 | assert0 (kill (upstart_pid, 0)); |
176 | @@ -333,7 +333,7 @@ | |||
177 | 333 | extra[3] = confdir_b; | 333 | extra[3] = confdir_b; |
178 | 334 | extra[4] = NULL; | 334 | extra[4] = NULL; |
179 | 335 | 335 | ||
181 | 336 | start_upstart_common (&upstart_pid, FALSE, NULL, logdir, extra); | 336 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); |
182 | 337 | 337 | ||
183 | 338 | /* Should be running */ | 338 | /* Should be running */ |
184 | 339 | assert0 (kill (upstart_pid, 0)); | 339 | assert0 (kill (upstart_pid, 0)); |
185 | @@ -376,7 +376,7 @@ | |||
186 | 376 | extra[3] = confdir_b; | 376 | extra[3] = confdir_b; |
187 | 377 | extra[4] = NULL; | 377 | extra[4] = NULL; |
188 | 378 | 378 | ||
190 | 379 | start_upstart_common (&upstart_pid, FALSE, NULL, logdir, extra); | 379 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); |
191 | 380 | 380 | ||
192 | 381 | /* Should be running */ | 381 | /* Should be running */ |
193 | 382 | assert0 (kill (upstart_pid, 0)); | 382 | assert0 (kill (upstart_pid, 0)); |
194 | 383 | 383 | ||
195 | === modified file 'test/test_util_common.c' | |||
196 | --- test/test_util_common.c 2013-10-02 08:59:20 +0000 | |||
197 | +++ test/test_util_common.c 2013-10-18 09:17:07 +0000 | |||
198 | @@ -420,6 +420,7 @@ | |||
199 | 420 | * @pid: PID of running instance, | 420 | * @pid: PID of running instance, |
200 | 421 | * @user: TRUE if upstart should run in User Session mode (FALSE to | 421 | * @user: TRUE if upstart should run in User Session mode (FALSE to |
201 | 422 | * use the users D-Bus session bus), | 422 | * use the users D-Bus session bus), |
202 | 423 | * @inherit_env: if TRUE, inherit parent environment, | ||
203 | 423 | * @confdir: full path to configuration directory, | 424 | * @confdir: full path to configuration directory, |
204 | 424 | * @logdir: full path to log directory, | 425 | * @logdir: full path to log directory, |
205 | 425 | * @extra: optional extra arguments. | 426 | * @extra: optional extra arguments. |
206 | @@ -427,8 +428,9 @@ | |||
207 | 427 | * Wrapper round _start_upstart() which specifies common options. | 428 | * Wrapper round _start_upstart() which specifies common options. |
208 | 428 | **/ | 429 | **/ |
209 | 429 | void | 430 | void |
212 | 430 | start_upstart_common (pid_t *pid, int user, const char *confdir, | 431 | start_upstart_common (pid_t *pid, int user, int inherit_env, |
213 | 431 | const char *logdir, char * const *extra) | 432 | const char *confdir, const char *logdir, |
214 | 433 | char * const *extra) | ||
215 | 432 | { | 434 | { |
216 | 433 | nih_local char **args = NULL; | 435 | nih_local char **args = NULL; |
217 | 434 | 436 | ||
218 | @@ -449,8 +451,10 @@ | |||
219 | 449 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, | 451 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, |
220 | 450 | "--no-sessions")); | 452 | "--no-sessions")); |
221 | 451 | 453 | ||
224 | 452 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, | 454 | if (! inherit_env) { |
225 | 453 | "--no-inherit-env")); | 455 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, |
226 | 456 | "--no-inherit-env")); | ||
227 | 457 | } | ||
228 | 454 | 458 | ||
229 | 455 | if (confdir) { | 459 | if (confdir) { |
230 | 456 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, | 460 | NIH_MUST (nih_str_array_add (&args, NULL, NULL, |
231 | @@ -483,7 +487,7 @@ | |||
232 | 483 | void | 487 | void |
233 | 484 | start_upstart (pid_t *pid) | 488 | start_upstart (pid_t *pid) |
234 | 485 | { | 489 | { |
236 | 486 | start_upstart_common (pid, FALSE, NULL, NULL, NULL); | 490 | start_upstart_common (pid, FALSE, FALSE, NULL, NULL, NULL); |
237 | 487 | } | 491 | } |
238 | 488 | 492 | ||
239 | 489 | /** | 493 | /** |
240 | 490 | 494 | ||
241 | === modified file 'test/test_util_common.h' | |||
242 | --- test/test_util_common.h 2013-09-26 16:33:07 +0000 | |||
243 | +++ test/test_util_common.h 2013-10-18 09:17:07 +0000 | |||
244 | @@ -341,7 +341,7 @@ | |||
245 | 341 | * Start an instance of Upstart and return PID in @pid. | 341 | * Start an instance of Upstart and return PID in @pid. |
246 | 342 | **/ | 342 | **/ |
247 | 343 | #define START_UPSTART(pid, user_mode) \ | 343 | #define START_UPSTART(pid, user_mode) \ |
249 | 344 | start_upstart_common (&(pid), user_mode, NULL, NULL, NULL) | 344 | start_upstart_common (&(pid), user_mode, FALSE, NULL, NULL, NULL) |
250 | 345 | 345 | ||
251 | 346 | /** | 346 | /** |
252 | 347 | * KILL_UPSTART: | 347 | * KILL_UPSTART: |
253 | @@ -700,8 +700,9 @@ | |||
254 | 700 | 700 | ||
255 | 701 | void _start_upstart (pid_t *pid, int user, char * const *args); | 701 | void _start_upstart (pid_t *pid, int user, char * const *args); |
256 | 702 | 702 | ||
259 | 703 | void start_upstart_common (pid_t *pid, int user, const char *confdir, | 703 | void start_upstart_common (pid_t *pid, int user, int inherit_env, |
260 | 704 | const char *logdir, char * const *extra); | 704 | const char *confdir, const char *logdir, |
261 | 705 | char * const *extra); | ||
262 | 705 | 706 | ||
263 | 706 | void start_upstart (pid_t *pid); | 707 | void start_upstart (pid_t *pid); |
264 | 707 | 708 | ||
265 | 708 | 709 | ||
266 | === modified file 'util/tests/test_initctl.c' | |||
267 | --- util/tests/test_initctl.c 2013-09-26 16:33:07 +0000 | |||
268 | +++ util/tests/test_initctl.c 2013-10-18 09:17:07 +0000 | |||
269 | @@ -10839,7 +10839,7 @@ | |||
270 | 10839 | /*******************************************************************/ | 10839 | /*******************************************************************/ |
271 | 10840 | TEST_FEATURE ("single job producing output across a re-exec"); | 10840 | TEST_FEATURE ("single job producing output across a re-exec"); |
272 | 10841 | 10841 | ||
274 | 10842 | start_upstart_common (&upstart_pid, FALSE, confdir, logdir, NULL); | 10842 | start_upstart_common (&upstart_pid, FALSE, FALSE, confdir, logdir, NULL); |
275 | 10843 | 10843 | ||
276 | 10844 | contents = nih_sprintf (NULL, | 10844 | contents = nih_sprintf (NULL, |
277 | 10845 | "pre-start exec echo pre-start\n" | 10845 | "pre-start exec echo pre-start\n" |
278 | @@ -11059,7 +11059,7 @@ | |||
279 | 11059 | /* Reset initctl global from previous tests */ | 11059 | /* Reset initctl global from previous tests */ |
280 | 11060 | dest_name = NULL; | 11060 | dest_name = NULL; |
281 | 11061 | 11061 | ||
283 | 11062 | start_upstart_common (&upstart_pid, TRUE, NULL, NULL, NULL); | 11062 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, NULL, NULL); |
284 | 11063 | 11063 | ||
285 | 11064 | session_file = get_session_file (dirname, upstart_pid); | 11064 | session_file = get_session_file (dirname, upstart_pid); |
286 | 11065 | 11065 | ||
287 | @@ -11168,7 +11168,7 @@ | |||
288 | 11168 | /*******************************************************************/ | 11168 | /*******************************************************************/ |
289 | 11169 | TEST_FEATURE ("system shutdown: no jobs"); | 11169 | TEST_FEATURE ("system shutdown: no jobs"); |
290 | 11170 | 11170 | ||
292 | 11171 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11171 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
293 | 11172 | 11172 | ||
294 | 11173 | /* Should be running */ | 11173 | /* Should be running */ |
295 | 11174 | assert0 (kill (upstart_pid, 0)); | 11174 | assert0 (kill (upstart_pid, 0)); |
296 | @@ -11194,7 +11194,7 @@ | |||
297 | 11194 | CREATE_FILE (confdir, "long-running.conf", | 11194 | CREATE_FILE (confdir, "long-running.conf", |
298 | 11195 | "exec sleep 999"); | 11195 | "exec sleep 999"); |
299 | 11196 | 11196 | ||
301 | 11197 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11197 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
302 | 11198 | 11198 | ||
303 | 11199 | /* Should be running */ | 11199 | /* Should be running */ |
304 | 11200 | assert0 (kill (upstart_pid, 0)); | 11200 | assert0 (kill (upstart_pid, 0)); |
305 | @@ -11276,7 +11276,7 @@ | |||
306 | 11276 | " sleep 999\n" | 11276 | " sleep 999\n" |
307 | 11277 | "end script"); | 11277 | "end script"); |
308 | 11278 | 11278 | ||
310 | 11279 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11279 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
311 | 11280 | 11280 | ||
312 | 11281 | /* Should be running */ | 11281 | /* Should be running */ |
313 | 11282 | assert0 (kill (upstart_pid, 0)); | 11282 | assert0 (kill (upstart_pid, 0)); |
314 | @@ -11329,7 +11329,7 @@ | |||
315 | 11329 | 11329 | ||
316 | 11330 | CREATE_FILE (confdir, "session-end.conf", job); | 11330 | CREATE_FILE (confdir, "session-end.conf", job); |
317 | 11331 | 11331 | ||
319 | 11332 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11332 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
320 | 11333 | 11333 | ||
321 | 11334 | /* Should be running */ | 11334 | /* Should be running */ |
322 | 11335 | assert0 (kill (upstart_pid, 0)); | 11335 | assert0 (kill (upstart_pid, 0)); |
323 | @@ -11392,7 +11392,7 @@ | |||
324 | 11392 | 11392 | ||
325 | 11393 | CREATE_FILE (confdir, "session-end-term.conf", job); | 11393 | CREATE_FILE (confdir, "session-end-term.conf", job); |
326 | 11394 | 11394 | ||
328 | 11395 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11395 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
329 | 11396 | 11396 | ||
330 | 11397 | /* Should be running */ | 11397 | /* Should be running */ |
331 | 11398 | assert0 (kill (upstart_pid, 0)); | 11398 | assert0 (kill (upstart_pid, 0)); |
332 | @@ -11460,7 +11460,7 @@ | |||
333 | 11460 | 11460 | ||
334 | 11461 | CREATE_FILE (confdir, "session-end-term.conf", job); | 11461 | CREATE_FILE (confdir, "session-end-term.conf", job); |
335 | 11462 | 11462 | ||
337 | 11463 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11463 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
338 | 11464 | 11464 | ||
339 | 11465 | /* Should be running */ | 11465 | /* Should be running */ |
340 | 11466 | assert0 (kill (upstart_pid, 0)); | 11466 | assert0 (kill (upstart_pid, 0)); |
341 | @@ -11512,7 +11512,7 @@ | |||
342 | 11512 | /*******************************************************************/ | 11512 | /*******************************************************************/ |
343 | 11513 | TEST_FEATURE ("session shutdown: no jobs"); | 11513 | TEST_FEATURE ("session shutdown: no jobs"); |
344 | 11514 | 11514 | ||
346 | 11515 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11515 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
347 | 11516 | 11516 | ||
348 | 11517 | /* Further required initctl global resets. Shudder. */ | 11517 | /* Further required initctl global resets. Shudder. */ |
349 | 11518 | user_mode = TRUE; | 11518 | user_mode = TRUE; |
350 | @@ -11548,7 +11548,7 @@ | |||
351 | 11548 | CREATE_FILE (confdir, "long-running.conf", | 11548 | CREATE_FILE (confdir, "long-running.conf", |
352 | 11549 | "exec sleep 999"); | 11549 | "exec sleep 999"); |
353 | 11550 | 11550 | ||
355 | 11551 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11551 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
356 | 11552 | 11552 | ||
357 | 11553 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", | 11553 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", |
358 | 11554 | get_initctl (), "long-running"); | 11554 | get_initctl (), "long-running"); |
359 | @@ -11596,7 +11596,7 @@ | |||
360 | 11596 | "start on startup\n" | 11596 | "start on startup\n" |
361 | 11597 | "exec sleep 999"); | 11597 | "exec sleep 999"); |
362 | 11598 | 11598 | ||
364 | 11599 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11599 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
365 | 11600 | 11600 | ||
366 | 11601 | upstart = upstart_open (NULL); | 11601 | upstart = upstart_open (NULL); |
367 | 11602 | TEST_NE_P (upstart, NULL); | 11602 | TEST_NE_P (upstart, NULL); |
368 | @@ -11641,7 +11641,7 @@ | |||
369 | 11641 | " sleep 999\n" | 11641 | " sleep 999\n" |
370 | 11642 | "end script"); | 11642 | "end script"); |
371 | 11643 | 11643 | ||
373 | 11644 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11644 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
374 | 11645 | 11645 | ||
375 | 11646 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", | 11646 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", |
376 | 11647 | get_initctl (), "long-running-term"); | 11647 | get_initctl (), "long-running-term"); |
377 | @@ -11697,7 +11697,7 @@ | |||
378 | 11697 | 11697 | ||
379 | 11698 | CREATE_FILE (confdir, "session-end.conf", job); | 11698 | CREATE_FILE (confdir, "session-end.conf", job); |
380 | 11699 | 11699 | ||
382 | 11700 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11700 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
383 | 11701 | 11701 | ||
384 | 11702 | upstart = upstart_open (NULL); | 11702 | upstart = upstart_open (NULL); |
385 | 11703 | TEST_NE_P (upstart, NULL); | 11703 | TEST_NE_P (upstart, NULL); |
386 | @@ -11760,7 +11760,7 @@ | |||
387 | 11760 | 11760 | ||
388 | 11761 | CREATE_FILE (confdir, "session-end-term.conf", job); | 11761 | CREATE_FILE (confdir, "session-end-term.conf", job); |
389 | 11762 | 11762 | ||
391 | 11763 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11763 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
392 | 11764 | 11764 | ||
393 | 11765 | upstart = upstart_open (NULL); | 11765 | upstart = upstart_open (NULL); |
394 | 11766 | TEST_NE_P (upstart, NULL); | 11766 | TEST_NE_P (upstart, NULL); |
395 | @@ -11830,7 +11830,7 @@ | |||
396 | 11830 | 11830 | ||
397 | 11831 | CREATE_FILE (confdir, "session-end-term.conf", job); | 11831 | CREATE_FILE (confdir, "session-end-term.conf", job); |
398 | 11832 | 11832 | ||
400 | 11833 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 11833 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
401 | 11834 | 11834 | ||
402 | 11835 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", | 11835 | cmd = nih_sprintf (NULL, "%s start %s 2>&1", |
403 | 11836 | get_initctl (), "long-running-term"); | 11836 | get_initctl (), "long-running-term"); |
404 | @@ -11906,6 +11906,98 @@ | |||
405 | 11906 | } | 11906 | } |
406 | 11907 | 11907 | ||
407 | 11908 | void | 11908 | void |
408 | 11909 | test_umask (void) | ||
409 | 11910 | { | ||
410 | 11911 | char confdir[PATH_MAX]; | ||
411 | 11912 | char logdir[PATH_MAX]; | ||
412 | 11913 | pid_t upstart_pid = 0; | ||
413 | 11914 | nih_local char *logfile = NULL; | ||
414 | 11915 | mode_t job_umask; | ||
415 | 11916 | nih_local char *job_umask_str = NULL; | ||
416 | 11917 | size_t length; | ||
417 | 11918 | int ret; | ||
418 | 11919 | mode_t original_umask; | ||
419 | 11920 | mode_t test_umask = 0111; | ||
420 | 11921 | mode_t default_umask = 022; | ||
421 | 11922 | |||
422 | 11923 | TEST_FILENAME (confdir); | ||
423 | 11924 | TEST_EQ (mkdir (confdir, 0755), 0); | ||
424 | 11925 | |||
425 | 11926 | TEST_FILENAME (logdir); | ||
426 | 11927 | TEST_EQ (mkdir (logdir, 0755), 0); | ||
427 | 11928 | |||
428 | 11929 | original_umask = umask (test_umask); | ||
429 | 11930 | |||
430 | 11931 | TEST_GROUP ("Session Init umask value"); | ||
431 | 11932 | |||
432 | 11933 | /**********************************************************************/ | ||
433 | 11934 | TEST_FEATURE ("ensure Session Init inherits umask by default"); | ||
434 | 11935 | |||
435 | 11936 | /* Has to be a script since umask is a shell built-in */ | ||
436 | 11937 | CREATE_FILE (confdir, "umask.conf", | ||
437 | 11938 | "start on startup\n" | ||
438 | 11939 | "script\n" | ||
439 | 11940 | "umask\n" | ||
440 | 11941 | "end script"); | ||
441 | 11942 | |||
442 | 11943 | start_upstart_common (&upstart_pid, TRUE, TRUE, confdir, logdir, NULL); | ||
443 | 11944 | |||
444 | 11945 | logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s", | ||
445 | 11946 | logdir, | ||
446 | 11947 | "umask.log")); | ||
447 | 11948 | |||
448 | 11949 | WAIT_FOR_FILE (logfile); | ||
449 | 11950 | |||
450 | 11951 | job_umask_str = nih_file_read (NULL, logfile, &length); | ||
451 | 11952 | |||
452 | 11953 | ret = sscanf (job_umask_str, "%o", (unsigned int *)&job_umask); | ||
453 | 11954 | TEST_EQ (ret, 1); | ||
454 | 11955 | TEST_EQ (job_umask, test_umask); | ||
455 | 11956 | |||
456 | 11957 | DELETE_FILE (confdir, "umask.conf"); | ||
457 | 11958 | assert0 (unlink (logfile)); | ||
458 | 11959 | |||
459 | 11960 | STOP_UPSTART (upstart_pid); | ||
460 | 11961 | |||
461 | 11962 | /**********************************************************************/ | ||
462 | 11963 | TEST_FEATURE ("ensure Session Init defaults umask with '--no-inherit-env'"); | ||
463 | 11964 | |||
464 | 11965 | /* Has to be a script since umask is a shell built-in */ | ||
465 | 11966 | CREATE_FILE (confdir, "umask.conf", | ||
466 | 11967 | "start on startup\n" | ||
467 | 11968 | "script\n" | ||
468 | 11969 | "umask\n" | ||
469 | 11970 | "end script"); | ||
470 | 11971 | |||
471 | 11972 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); | ||
472 | 11973 | |||
473 | 11974 | logfile = NIH_MUST (nih_sprintf (NULL, "%s/%s", | ||
474 | 11975 | logdir, | ||
475 | 11976 | "umask.log")); | ||
476 | 11977 | |||
477 | 11978 | WAIT_FOR_FILE (logfile); | ||
478 | 11979 | |||
479 | 11980 | job_umask_str = nih_file_read (NULL, logfile, &length); | ||
480 | 11981 | |||
481 | 11982 | ret = sscanf (job_umask_str, "%o", (unsigned int *)&job_umask); | ||
482 | 11983 | TEST_EQ (ret, 1); | ||
483 | 11984 | TEST_EQ (job_umask, default_umask); | ||
484 | 11985 | |||
485 | 11986 | DELETE_FILE (confdir, "umask.conf"); | ||
486 | 11987 | assert0 (unlink (logfile)); | ||
487 | 11988 | |||
488 | 11989 | STOP_UPSTART (upstart_pid); | ||
489 | 11990 | |||
490 | 11991 | /**********************************************************************/ | ||
491 | 11992 | |||
492 | 11993 | /* Restore */ | ||
493 | 11994 | (void)umask (original_umask); | ||
494 | 11995 | |||
495 | 11996 | assert0 (rmdir (confdir)); | ||
496 | 11997 | assert0 (rmdir (logdir)); | ||
497 | 11998 | } | ||
498 | 11999 | |||
499 | 12000 | void | ||
500 | 11909 | test_show_config (void) | 12001 | test_show_config (void) |
501 | 11910 | { | 12002 | { |
502 | 11911 | char dirname[PATH_MAX]; | 12003 | char dirname[PATH_MAX]; |
503 | @@ -16519,7 +16611,7 @@ | |||
504 | 16519 | nih_local char *session_file = NULL; | 16611 | nih_local char *session_file = NULL; |
505 | 16520 | FILE *fi; | 16612 | FILE *fi; |
506 | 16521 | 16613 | ||
508 | 16522 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, extra); | 16614 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, extra); |
509 | 16523 | 16615 | ||
510 | 16524 | /*******************************************************************/ | 16616 | /*******************************************************************/ |
511 | 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"); |
512 | @@ -16633,7 +16725,7 @@ | |||
513 | 16633 | } | 16725 | } |
514 | 16634 | 16726 | ||
515 | 16635 | TEST_DBUS (dbus_pid); | 16727 | TEST_DBUS (dbus_pid); |
517 | 16636 | start_upstart_common (&upstart_pid, TRUE, confdir, logdir, NULL); | 16728 | start_upstart_common (&upstart_pid, TRUE, FALSE, confdir, logdir, NULL); |
518 | 16637 | 16729 | ||
519 | 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 ()); |
520 | 16639 | TEST_NE_P (cmd, NULL); | 16731 | TEST_NE_P (cmd, NULL); |
521 | @@ -16727,6 +16819,7 @@ | |||
522 | 16727 | test_reexec (); | 16819 | test_reexec (); |
523 | 16728 | test_list_sessions (); | 16820 | test_list_sessions (); |
524 | 16729 | test_quiesce (); | 16821 | test_quiesce (); |
525 | 16822 | test_umask (); | ||
526 | 16730 | 16823 | ||
527 | 16731 | if (in_chroot () && !dbus_configured ()) { | 16824 | if (in_chroot () && !dbus_configured ()) { |
528 | 16732 | fprintf(stderr, "\n\n" | 16825 | fprintf(stderr, "\n\n" |
lgtm.