Merge lp:~jamesodhunt/upstart/bug-1324096 into lp:upstart
- bug-1324096
- Merge into trunk
Proposed by
James Hunt
Status: | Merged |
---|---|
Merged at revision: | 1632 |
Proposed branch: | lp:~jamesodhunt/upstart/bug-1324096 |
Merge into: | lp:upstart |
Diff against target: |
1394 lines (+986/-145) (has conflicts) 7 files modified
ChangeLog (+37/-0) dbus/com.ubuntu.Upstart.xml (+13/-0) init/control.c (+188/-105) init/control.h (+13/-0) util/initctl.c (+8/-14) util/man/initctl.8 (+8/-7) util/tests/test_initctl.c (+719/-19) Text conflict in ChangeLog |
To merge this branch: | bzr merge lp:~jamesodhunt/upstart/bug-1324096 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Approve | ||
Review via email: mp+221743@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote : | # |
Revision history for this message
Dimitri John Ledkov (xnox) wrote : | # |
Asserts in test_control.c, since empty strings may not be added into a nih_str_array. Fix proposed here https:/
- 1624. By James Hunt
-
* Merge of lp:~xnox/upstart/bug-1324096.
- 1625. By James Hunt
-
* Formatting.
Revision history for this message
Dimitri John Ledkov (xnox) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2014-06-04 17:37:59 +0000 |
3 | +++ ChangeLog 2014-06-05 09:40:19 +0000 |
4 | @@ -1,3 +1,4 @@ |
5 | +<<<<<<< TREE |
6 | 2014-05-21 James Hunt <james.hunt@ubuntu.com> |
7 | |
8 | * init/main.c: Add support for '--prepend-confdir'. |
9 | @@ -13,6 +14,42 @@ |
10 | * init/tests/test_main.c: New Session and System init tests for |
11 | '--append-confdir'. |
12 | |
13 | +======= |
14 | +2014-06-04 James Hunt <james.hunt@ubuntu.com> |
15 | + |
16 | + * dbus/com.ubuntu.Upstart.xml: Renamed SetEnvMulti to SetEnvList and |
17 | + UnsetEnvMulti to UnsetEnvList for clarity. |
18 | + * init/control.c: |
19 | + - control_set_env_list(): Renamed from control_set_env_multi(). |
20 | + - control_unset_env_list(): Renamed from control_unset_env_multi(). |
21 | + - control_unset_env(): Actually make it call control_unset_env_list(). |
22 | + * util/initctl.c: Updated to call renamed functions. |
23 | + |
24 | +2014-06-02 James Hunt <james.hunt@ubuntu.com> |
25 | + |
26 | + * dbus/com.ubuntu.Upstart.xml: Added 'SetEnvMulti' and 'UnsetEnvMulti' |
27 | + methods to allow multiple job environment variables to be |
28 | + set/unset simultaneously (LP: #1324096). |
29 | + * init/control.c: |
30 | + - control_set_env_multi(): Implementation for 'SetEnvMulti'. |
31 | + - control_set_env(): Retained 'SetEnv' implementation that now calls |
32 | + control_set_env_multi(). |
33 | + - control_unset_env_multi(): Implementation for 'UnSetEnvMulti'. |
34 | + * util/initctl.c: |
35 | + - set_env_action(): Updated to call set_env_multi_sync(). |
36 | + - unset_env_action(): Updated to call unset_env_multi_sync(). |
37 | + * util/man/initctl.8: Updated to document ability for 'set-env' and |
38 | + 'unset-env' to set and unset multiple variables simultaneously. |
39 | + * util/tests/test_initctl.c: Added new tests: |
40 | + - "multiple set-env in 'name=value' form" |
41 | + - "multiple set-env in 'name=' form" |
42 | + - "multiple set-env in 'name' form" |
43 | + - "set-env for multiple already set variables" |
44 | + - "set-env with multiple variables, some already set" |
45 | + - "set-env with multiple variables in different forms" |
46 | + - "set-env --retain with multiple variables, some already set" |
47 | + |
48 | +>>>>>>> MERGE-SOURCE |
49 | 2014-05-09 Dimitri John Ledkov <xnox@ubuntu.com> |
50 | |
51 | * util/reboot.c: only use rebootcommand code path in runlevels 0, |
52 | |
53 | === modified file 'dbus/com.ubuntu.Upstart.xml' |
54 | --- dbus/com.ubuntu.Upstart.xml 2013-10-25 13:49:49 +0000 |
55 | +++ dbus/com.ubuntu.Upstart.xml 2014-06-05 09:40:19 +0000 |
56 | @@ -48,17 +48,30 @@ |
57 | <arg name="value" type="s" direction="out" /> |
58 | </method> |
59 | |
60 | + <!-- Deprecated - use SetEnvList instead --> |
61 | <method name="SetEnv"> |
62 | <arg name="job_details" type="as" direction="in" /> |
63 | <arg name="var" type="s" direction="in" /> |
64 | <arg name="replace" type="b" direction="in" /> |
65 | </method> |
66 | |
67 | + <method name="SetEnvList"> |
68 | + <arg name="job_details" type="as" direction="in" /> |
69 | + <arg name="vars" type="as" direction="in" /> |
70 | + <arg name="replace" type="b" direction="in" /> |
71 | + </method> |
72 | + |
73 | + <!-- Deprecated - use UnsetEnvList instead --> |
74 | <method name="UnsetEnv"> |
75 | <arg name="job_details" type="as" direction="in" /> |
76 | <arg name="name" type="s" direction="in" /> |
77 | </method> |
78 | |
79 | + <method name="UnsetEnvList"> |
80 | + <arg name="job_details" type="as" direction="in" /> |
81 | + <arg name="name" type="as" direction="in" /> |
82 | + </method> |
83 | + |
84 | <method name="ListEnv"> |
85 | <arg name="job_details" type="as" direction="in" /> |
86 | <arg name="env" type="as" direction="out" /> |
87 | |
88 | === modified file 'init/control.c' |
89 | --- init/control.c 2014-03-06 15:21:54 +0000 |
90 | +++ init/control.c 2014-06-05 09:40:19 +0000 |
91 | @@ -1253,6 +1253,119 @@ |
92 | } |
93 | |
94 | /** |
95 | + * control_set_env_list: |
96 | + * |
97 | + * @data: not used, |
98 | + * @message: D-Bus connection and message received, |
99 | + * @job_details: name and instance of job to apply operation to, |
100 | + * @vars: array of name[/value] pairs of environment variables to set, |
101 | + * @replace: TRUE if @name should be overwritten if already set, else |
102 | + * FALSE. |
103 | + * |
104 | + * Implements the SetEnvList method of the com.ubuntu.Upstart |
105 | + * interface. |
106 | + * |
107 | + * Called to request Upstart store one or more name/value pairs. |
108 | + * |
109 | + * If @job_details is empty, change will be applied to all job |
110 | + * environments, else only apply changes to specific job environment |
111 | + * encoded within @job_details. |
112 | + * |
113 | + * Returns: zero on success, negative value on raised error. |
114 | + **/ |
115 | +int |
116 | +control_set_env_list (void *data, |
117 | + NihDBusMessage *message, |
118 | + char * const *job_details, |
119 | + char * const *vars, |
120 | + int replace) |
121 | +{ |
122 | + Session *session; |
123 | + Job *job = NULL; |
124 | + char *job_name = NULL; |
125 | + char *instance = NULL; |
126 | + char * const *var; |
127 | + |
128 | + nih_assert (message); |
129 | + nih_assert (job_details); |
130 | + nih_assert (vars); |
131 | + |
132 | + if (! control_check_permission (message)) { |
133 | + nih_dbus_error_raise_printf ( |
134 | + DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", |
135 | + _("You do not have permission to modify job environment")); |
136 | + return -1; |
137 | + } |
138 | + |
139 | + if (job_details[0]) { |
140 | + job_name = job_details[0]; |
141 | + |
142 | + /* this can be a null value */ |
143 | + instance = job_details[1]; |
144 | + } else if (getpid () == 1) { |
145 | + nih_dbus_error_raise_printf ( |
146 | + DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", |
147 | + _("Not permissible to modify PID 1 job environment")); |
148 | + return -1; |
149 | + } |
150 | + |
151 | + /* Verify that job name is valid */ |
152 | + if (job_name && ! strlen (job_name)) { |
153 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
154 | + _("Job may not be empty string")); |
155 | + return -1; |
156 | + } |
157 | + |
158 | + /* Get the relevant session */ |
159 | + session = session_from_dbus (NULL, message); |
160 | + |
161 | + /* Chroot sessions must not be able to influence |
162 | + * the outside system. |
163 | + */ |
164 | + if (session && session->chroot) { |
165 | + nih_warn (_("Ignoring set env request from chroot session")); |
166 | + return 0; |
167 | + } |
168 | + |
169 | + /* Lookup the job */ |
170 | + control_get_job (session, job, job_name, instance); |
171 | + |
172 | + for (var = vars; var && *var; var++) { |
173 | + nih_local char *envvar = NULL; |
174 | + |
175 | + if (! *var) { |
176 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
177 | + _("Variable may not be empty string")); |
178 | + return -1; |
179 | + } |
180 | + |
181 | + /* If variable does not contain a delimiter, add one to ensure |
182 | + * it gets entered into the job environment table. Without the |
183 | + * delimiter, the variable will be silently ignored unless it's |
184 | + * already set in inits environment. But in that case there is |
185 | + * no point in setting such a variable to its already existing |
186 | + * value. |
187 | + */ |
188 | + if (! strchr (*var, '=')) { |
189 | + envvar = NIH_MUST (nih_sprintf (NULL, "%s=", *var)); |
190 | + } else { |
191 | + envvar = NIH_MUST (nih_strdup (NULL, *var)); |
192 | + } |
193 | + |
194 | + if (job) { |
195 | + /* Modify job-specific environment */ |
196 | + nih_assert (job->env); |
197 | + |
198 | + NIH_MUST (environ_add (&job->env, job, NULL, replace, envvar)); |
199 | + } else if (job_class_environment_set (envvar, replace) < 0) { |
200 | + nih_return_no_memory_error (-1); |
201 | + } |
202 | + } |
203 | + |
204 | + return 0; |
205 | +} |
206 | + |
207 | +/** |
208 | * control_set_env: |
209 | * |
210 | * @data: not used, |
211 | @@ -1280,14 +1393,52 @@ |
212 | const char *var, |
213 | int replace) |
214 | { |
215 | + nih_local char **vars = NULL; |
216 | + |
217 | + if (! var) { |
218 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
219 | + _("Variable may not be empty string")); |
220 | + return -1; |
221 | + } |
222 | + |
223 | + vars = NIH_MUST (nih_str_array_new (NULL)); |
224 | + |
225 | + NIH_MUST (nih_str_array_add (&vars, NULL, NULL, var)); |
226 | + |
227 | + return control_set_env_list (data, message, job_details, vars, replace); |
228 | +} |
229 | + |
230 | +/** |
231 | + * control_unset_env_list: |
232 | + * |
233 | + * @data: not used, |
234 | + * @message: D-Bus connection and message received, |
235 | + * @job_details: name and instance of job to apply operation to, |
236 | + * @names: array of variables to clear from the job environment array. |
237 | + * |
238 | + * Implements the UnsetEnvList method of the com.ubuntu.Upstart |
239 | + * interface. |
240 | + * |
241 | + * Called to request Upstart remove one or more variables from the job |
242 | + * environment array. |
243 | + * |
244 | + * Returns: zero on success, negative value on raised error. |
245 | + **/ |
246 | +int |
247 | +control_unset_env_list (void *data, |
248 | + NihDBusMessage *message, |
249 | + char * const *job_details, |
250 | + char * const *names) |
251 | +{ |
252 | Session *session; |
253 | Job *job = NULL; |
254 | char *job_name = NULL; |
255 | char *instance = NULL; |
256 | - nih_local char *envvar = NULL; |
257 | + char * const *name; |
258 | |
259 | nih_assert (message); |
260 | nih_assert (job_details); |
261 | + nih_assert (names); |
262 | |
263 | if (! control_check_permission (message)) { |
264 | nih_dbus_error_raise_printf ( |
265 | @@ -1308,12 +1459,6 @@ |
266 | return -1; |
267 | } |
268 | |
269 | - if (! var || ! *var) { |
270 | - nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
271 | - _("Variable may not be empty string")); |
272 | - return -1; |
273 | - } |
274 | - |
275 | /* Verify that job name is valid */ |
276 | if (job_name && ! strlen (job_name)) { |
277 | nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
278 | @@ -1328,38 +1473,38 @@ |
279 | * the outside system. |
280 | */ |
281 | if (session && session->chroot) { |
282 | - nih_warn (_("Ignoring set env request from chroot session")); |
283 | + nih_warn (_("Ignoring unset env request from chroot session")); |
284 | return 0; |
285 | } |
286 | |
287 | /* Lookup the job */ |
288 | control_get_job (session, job, job_name, instance); |
289 | |
290 | - /* If variable does not contain a delimiter, add one to ensure |
291 | - * it gets entered into the job environment table. Without the |
292 | - * delimiter, the variable will be silently ignored unless it's |
293 | - * already set in inits environment. But in that case there is |
294 | - * no point in setting such a variable to its already existing |
295 | - * value. |
296 | - */ |
297 | - if (! strchr (var, '=')) |
298 | - envvar = NIH_MUST (nih_sprintf (NULL, "%s=", var)); |
299 | - else |
300 | - envvar = NIH_MUST (nih_strdup (NULL, var)); |
301 | - |
302 | - if (job) { |
303 | - /* Modify job-specific environment */ |
304 | - |
305 | - nih_assert (job->env); |
306 | - |
307 | - NIH_MUST (environ_add (&job->env, job, NULL, replace, envvar)); |
308 | - return 0; |
309 | + for (name = names; name && *name; name++) { |
310 | + if (! *name) { |
311 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
312 | + _("Variable may not be empty string")); |
313 | + return -1; |
314 | + } |
315 | + |
316 | + if (job) { |
317 | + /* Modify job-specific environment */ |
318 | + nih_assert (job->env); |
319 | + |
320 | + if (! environ_remove (&job->env, job, NULL, *name)) |
321 | + return -1; |
322 | + } else if (job_class_environment_unset (*name) < 0) { |
323 | + goto error; |
324 | + } |
325 | } |
326 | |
327 | - if (job_class_environment_set (envvar, replace) < 0) |
328 | - nih_return_no_memory_error (-1); |
329 | - |
330 | return 0; |
331 | + |
332 | +error: |
333 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
334 | + "%s: %s", |
335 | + _("No such variable"), *name); |
336 | + return -1; |
337 | } |
338 | |
339 | /** |
340 | @@ -1384,81 +1529,19 @@ |
341 | char * const *job_details, |
342 | const char *name) |
343 | { |
344 | - Session *session; |
345 | - Job *job = NULL; |
346 | - char *job_name = NULL; |
347 | - char *instance = NULL; |
348 | - |
349 | - nih_assert (message); |
350 | - nih_assert (job_details); |
351 | - |
352 | - if (! control_check_permission (message)) { |
353 | - nih_dbus_error_raise_printf ( |
354 | - DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", |
355 | - _("You do not have permission to modify job environment")); |
356 | - return -1; |
357 | - } |
358 | - |
359 | - if (! name || ! *name) { |
360 | - nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
361 | - _("Variable may not be empty string")); |
362 | - return -1; |
363 | - } |
364 | - |
365 | - if (job_details[0]) { |
366 | - job_name = job_details[0]; |
367 | - |
368 | - /* this can be a null value */ |
369 | - instance = job_details[1]; |
370 | - } else if (getpid () == 1) { |
371 | - nih_dbus_error_raise_printf ( |
372 | - DBUS_INTERFACE_UPSTART ".Error.PermissionDenied", |
373 | - _("Not permissible to modify PID 1 job environment")); |
374 | - return -1; |
375 | - } |
376 | - |
377 | - /* Verify that job name is valid */ |
378 | - if (job_name && ! strlen (job_name)) { |
379 | - nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
380 | - _("Job may not be empty string")); |
381 | - return -1; |
382 | - } |
383 | - |
384 | - /* Get the relevant session */ |
385 | - session = session_from_dbus (NULL, message); |
386 | - |
387 | - /* Chroot sessions must not be able to influence |
388 | - * the outside system. |
389 | - */ |
390 | - if (session && session->chroot) { |
391 | - nih_warn (_("Ignoring unset env request from chroot session")); |
392 | - return 0; |
393 | - } |
394 | - |
395 | - /* Lookup the job */ |
396 | - control_get_job (session, job, job_name, instance); |
397 | - |
398 | - if (job) { |
399 | - /* Modify job-specific environment */ |
400 | - |
401 | - nih_assert (job->env); |
402 | - |
403 | - if (! environ_remove (&job->env, job, NULL, name)) |
404 | - return -1; |
405 | - |
406 | - return 0; |
407 | - } |
408 | - |
409 | - if (job_class_environment_unset (name) < 0) |
410 | - goto error; |
411 | - |
412 | - return 0; |
413 | - |
414 | -error: |
415 | - nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
416 | - "%s: %s", |
417 | - _("No such variable"), name); |
418 | - return -1; |
419 | + nih_local char **names = NULL; |
420 | + |
421 | + if (! name) { |
422 | + nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS, |
423 | + _("Variable may not be empty string")); |
424 | + return -1; |
425 | + } |
426 | + |
427 | + names = NIH_MUST (nih_str_array_new (NULL)); |
428 | + |
429 | + NIH_MUST (nih_str_array_add (&names, NULL, NULL, name)); |
430 | + |
431 | + return control_unset_env_list (data, message, job_details, names); |
432 | } |
433 | |
434 | /** |
435 | |
436 | === modified file 'init/control.h' |
437 | --- init/control.h 2014-03-06 15:21:54 +0000 |
438 | +++ init/control.h 2014-06-05 09:40:19 +0000 |
439 | @@ -170,6 +170,13 @@ |
440 | const char *address) |
441 | __attribute__ ((warn_unused_result)); |
442 | |
443 | +int control_set_env_multi (void *data, |
444 | + NihDBusMessage *message, |
445 | + char * const *job_details, |
446 | + char * const *vars, |
447 | + int replace) |
448 | + __attribute__ ((warn_unused_result)); |
449 | + |
450 | int control_set_env (void *data, |
451 | NihDBusMessage *message, |
452 | char * const *job_details, |
453 | @@ -195,6 +202,12 @@ |
454 | char * const *job_details) |
455 | __attribute__ ((warn_unused_result)); |
456 | |
457 | +int control_unset_env_multi (void *data, |
458 | + NihDBusMessage *message, |
459 | + char * const *job_details, |
460 | + char * const *names) |
461 | + __attribute__ ((warn_unused_result)); |
462 | + |
463 | int control_unset_env (void *data, |
464 | NihDBusMessage *message, |
465 | char * const *job_details, |
466 | |
467 | === modified file 'util/initctl.c' |
468 | --- util/initctl.c 2014-04-17 14:56:06 +0000 |
469 | +++ util/initctl.c 2014-06-05 09:40:19 +0000 |
470 | @@ -1451,7 +1451,6 @@ |
471 | { |
472 | nih_local NihDBusProxy *upstart = NULL; |
473 | NihError *err; |
474 | - char *envvar; |
475 | nih_local char **job_details = NULL; |
476 | int ret; |
477 | |
478 | @@ -1468,14 +1467,12 @@ |
479 | if (! job_details) |
480 | return 1; |
481 | |
482 | - envvar = args[0]; |
483 | - |
484 | upstart = upstart_open (NULL); |
485 | if (! upstart) |
486 | return 1; |
487 | |
488 | - ret = upstart_set_env_sync (NULL, upstart, job_details, |
489 | - envvar, ! retain_var); |
490 | + ret = upstart_set_env_list_sync (NULL, upstart, job_details, |
491 | + args, ! retain_var); |
492 | |
493 | if (ret < 0) |
494 | goto error; |
495 | @@ -1504,15 +1501,12 @@ |
496 | { |
497 | nih_local NihDBusProxy *upstart = NULL; |
498 | NihError *err; |
499 | - char *name; |
500 | nih_local char **job_details = NULL; |
501 | |
502 | nih_assert (command != NULL); |
503 | nih_assert (args != NULL); |
504 | |
505 | - name = args[0]; |
506 | - |
507 | - if (! name) { |
508 | + if (! args[0]) { |
509 | fprintf (stderr, _("%s: missing variable name\n"), program_name); |
510 | nih_main_suggest_help (); |
511 | return 1; |
512 | @@ -1526,7 +1520,7 @@ |
513 | if (! upstart) |
514 | return 1; |
515 | |
516 | - if (upstart_unset_env_sync (NULL, upstart, job_details, name) < 0) |
517 | + if (upstart_unset_env_list_sync (NULL, upstart, job_details, args) < 0) |
518 | goto error; |
519 | |
520 | return 0; |
521 | @@ -3247,13 +3241,13 @@ |
522 | &env_group, reset_env_options, reset_env_action }, |
523 | |
524 | { "set-env", N_("VARIABLE[=VALUE]"), |
525 | - N_("Set a job environment variable."), |
526 | - N_("Adds or updates a variable in the job environment table."), |
527 | + N_("Set one or more job environment variables."), |
528 | + N_("Adds or updates variables in the job environment table."), |
529 | &env_group, set_env_options, set_env_action }, |
530 | |
531 | { "unset-env", N_("VARIABLE"), |
532 | - N_("Remove a job environment variable."), |
533 | - N_("Discards the specified variable from the job environment table."), |
534 | + N_("Remove one or more job environment variables."), |
535 | + N_("Discards variables from the job environment table."), |
536 | &env_group, unset_env_options, unset_env_action }, |
537 | |
538 | { "usage", N_("JOB"), |
539 | |
540 | === modified file 'util/man/initctl.8' |
541 | --- util/man/initctl.8 2013-12-20 17:37:26 +0000 |
542 | +++ util/man/initctl.8 2014-06-05 09:40:19 +0000 |
543 | @@ -655,9 +655,9 @@ |
544 | .\" |
545 | .TP |
546 | .B set\-env |
547 | -.RI [ OPTIONS "] " VARIABLE[=VALUE] |
548 | +.RI [ OPTIONS "] " VARIABLE[=VALUE] " ..." |
549 | |
550 | -Adds or updates a variable in a job environment table. Variables set |
551 | +Adds or updates one or more variables in a job environment table. Variables set |
552 | in this way will apply to all the subsequently-starting processes for a |
553 | job. |
554 | |
555 | @@ -670,7 +670,7 @@ |
556 | .B OPTIONS |
557 | .RS |
558 | .IP "\fB\-r\fP, \fB\-\-retain\fP" |
559 | -If the specified variable is already set, do not modify it. |
560 | +If any of the specified variables are already set, do not modify them. |
561 | .RE |
562 | .RS |
563 | .IP "\fB\-g\fP, \fB\-\-global\fP" |
564 | @@ -688,10 +688,11 @@ |
565 | .\" |
566 | .TP |
567 | .B unset\-env |
568 | -.RI [ OPTIONS "] " VARIABLE |
569 | +.RI [ OPTIONS "] " VARIABLE " ..." |
570 | |
571 | -Remove the specified variable from a job environment table. If the |
572 | -variable does not already exist in the table, no change will be made. |
573 | +Remove the specified variables from a job environment table. If any of |
574 | +the variables specified do not already exist in the table, those |
575 | +variables will be ignored. |
576 | |
577 | This command is only permitted when running in |
578 | .B User Session Mode. |
579 | @@ -702,7 +703,7 @@ |
580 | .B OPTIONS |
581 | .RS |
582 | .IP "\fB\-r\fP, \fB\-\-retain\fP" |
583 | -If the specified variable is already set, do not modify it. |
584 | +If any of the specified variables are already set, do not unset them. |
585 | .RE |
586 | .RS |
587 | .IP "\fB\-g\fP, \fB\-\-global\fP" |
588 | |
589 | === modified file 'util/tests/test_initctl.c' |
590 | --- util/tests/test_initctl.c 2014-06-04 17:37:59 +0000 |
591 | +++ util/tests/test_initctl.c 2014-06-05 09:40:19 +0000 |
592 | @@ -16292,6 +16292,17 @@ |
593 | TEST_EQ (line_count, 1); |
594 | TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
595 | |
596 | + /* ensure unset-env (multiple variables) tolerates empty environment */ |
597 | + cmd = nih_sprintf (NULL, "%s unset-env %s %s 2>&1", get_initctl (), "foo", "bar"); |
598 | + TEST_NE_P (cmd, NULL); |
599 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
600 | + |
601 | + /* Although 2 variables have been specified, since neither is |
602 | + * set, we only expect 1 error for the first variable. |
603 | + */ |
604 | + TEST_EQ (line_count, 1); |
605 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
606 | + |
607 | /*******************************************************************/ |
608 | TEST_FEATURE ("ensure job runs in empty environment"); |
609 | |
610 | @@ -16352,6 +16363,12 @@ |
611 | nih_local char *cmd = NULL; |
612 | nih_local char *name = NULL; |
613 | nih_local char *value = NULL; |
614 | + nih_local char *name2 = NULL; |
615 | + nih_local char *value2 = NULL; |
616 | + nih_local char *name3 = NULL; |
617 | + nih_local char *value3 = NULL; |
618 | + nih_local char *name4 = NULL; |
619 | + nih_local char *value4 = NULL; |
620 | char **output; |
621 | nih_local char *logfile = NULL; |
622 | size_t line_count; |
623 | @@ -16381,6 +16398,8 @@ |
624 | |
625 | name = NIH_MUST (nih_strdup (NULL, "foo")); |
626 | value = NIH_MUST (nih_strdup (NULL, "bar")); |
627 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
628 | + value2 = NIH_MUST (nih_strdup (NULL, "qux")); |
629 | |
630 | cmd = nih_sprintf (NULL, "%s set-env %s=%s 2>&1", get_initctl (), |
631 | name, value); |
632 | @@ -16388,25 +16407,98 @@ |
633 | RUN_COMMAND (NULL, cmd, &output, &line_count); |
634 | TEST_EQ (line_count, 0); |
635 | |
636 | - cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
637 | - name); |
638 | - TEST_NE_P (cmd, NULL); |
639 | - RUN_COMMAND (NULL, cmd, &output, &line_count); |
640 | - TEST_EQ (line_count, 1); |
641 | - TEST_EQ_STR (output[0], value); |
642 | - nih_free (output); |
643 | - |
644 | - cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
645 | - TEST_NE_P (cmd, NULL); |
646 | - RUN_COMMAND (NULL, cmd, &output, &line_count); |
647 | - TEST_EQ (line_count, 0); |
648 | - |
649 | - cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
650 | - name); |
651 | - TEST_NE_P (cmd, NULL); |
652 | - RUN_COMMAND (NULL, cmd, &output, &line_count); |
653 | - TEST_EQ (line_count, 1); |
654 | - TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
655 | + cmd = nih_sprintf (NULL, "%s set-env %s=%s 2>&1", get_initctl (), |
656 | + name2, value2); |
657 | + TEST_NE_P (cmd, NULL); |
658 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
659 | + TEST_EQ (line_count, 0); |
660 | + |
661 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
662 | + name); |
663 | + TEST_NE_P (cmd, NULL); |
664 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
665 | + TEST_EQ (line_count, 1); |
666 | + TEST_EQ_STR (output[0], value); |
667 | + nih_free (output); |
668 | + |
669 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
670 | + name2); |
671 | + TEST_NE_P (cmd, NULL); |
672 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
673 | + TEST_EQ (line_count, 1); |
674 | + TEST_EQ_STR (output[0], value2); |
675 | + nih_free (output); |
676 | + |
677 | + cmd = nih_sprintf (NULL, "%s unset-env %s %s 2>&1", get_initctl (), name, name2); |
678 | + TEST_NE_P (cmd, NULL); |
679 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
680 | + TEST_EQ (line_count, 0); |
681 | + |
682 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
683 | + name); |
684 | + TEST_NE_P (cmd, NULL); |
685 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
686 | + TEST_EQ (line_count, 1); |
687 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
688 | + nih_free (output); |
689 | + |
690 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
691 | + name2); |
692 | + TEST_NE_P (cmd, NULL); |
693 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
694 | + TEST_EQ (line_count, 1); |
695 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
696 | + nih_free (output); |
697 | + |
698 | + /*******************************************************************/ |
699 | + TEST_FEATURE ("multiple set-env in 'name=value' form"); |
700 | + |
701 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
702 | + value = NIH_MUST (nih_strdup (NULL, "bar")); |
703 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
704 | + value2 = NIH_MUST (nih_strdup (NULL, "qux")); |
705 | + |
706 | + cmd = nih_sprintf (NULL, "%s set-env %s=%s %s=%s 2>&1", get_initctl (), |
707 | + name, value, name2, value2); |
708 | + TEST_NE_P (cmd, NULL); |
709 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
710 | + TEST_EQ (line_count, 0); |
711 | + |
712 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
713 | + name); |
714 | + TEST_NE_P (cmd, NULL); |
715 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
716 | + TEST_EQ (line_count, 1); |
717 | + TEST_EQ_STR (output[0], value); |
718 | + nih_free (output); |
719 | + |
720 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
721 | + name2); |
722 | + TEST_NE_P (cmd, NULL); |
723 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
724 | + TEST_EQ (line_count, 1); |
725 | + TEST_EQ_STR (output[0], value2); |
726 | + nih_free (output); |
727 | + |
728 | + cmd = nih_sprintf (NULL, "%s unset-env %s %s 2>&1", get_initctl (), name, name2); |
729 | + TEST_NE_P (cmd, NULL); |
730 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
731 | + TEST_EQ (line_count, 0); |
732 | + |
733 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
734 | + name); |
735 | + TEST_NE_P (cmd, NULL); |
736 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
737 | + TEST_EQ (line_count, 1); |
738 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
739 | + nih_free (output); |
740 | + |
741 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
742 | + name2); |
743 | + TEST_NE_P (cmd, NULL); |
744 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
745 | + TEST_EQ (line_count, 1); |
746 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
747 | nih_free (output); |
748 | |
749 | /*******************************************************************/ |
750 | @@ -16447,6 +16539,67 @@ |
751 | nih_free (output); |
752 | |
753 | /*******************************************************************/ |
754 | + TEST_FEATURE ("multiple set-env in 'name=' form"); |
755 | + |
756 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
757 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
758 | + |
759 | + cmd = nih_sprintf (NULL, "%s set-env %s= %s= 2>&1", get_initctl (), |
760 | + name, name2); |
761 | + TEST_NE_P (cmd, NULL); |
762 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
763 | + TEST_EQ (line_count, 0); |
764 | + nih_free (output); |
765 | + |
766 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
767 | + name); |
768 | + TEST_NE_P (cmd, NULL); |
769 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
770 | + TEST_EQ (line_count, 1); |
771 | + |
772 | + /* nul string value expected if none specified when set */ |
773 | + TEST_EQ_STR (output[0], ""); |
774 | + |
775 | + nih_free (output); |
776 | + |
777 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
778 | + name2); |
779 | + TEST_NE_P (cmd, NULL); |
780 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
781 | + TEST_EQ (line_count, 1); |
782 | + |
783 | + /* nul string value expected if none specified when set */ |
784 | + TEST_EQ_STR (output[0], ""); |
785 | + |
786 | + nih_free (output); |
787 | + |
788 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
789 | + TEST_NE_P (cmd, NULL); |
790 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
791 | + TEST_EQ (line_count, 0); |
792 | + |
793 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
794 | + name); |
795 | + TEST_NE_P (cmd, NULL); |
796 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
797 | + TEST_EQ (line_count, 1); |
798 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
799 | + nih_free (output); |
800 | + |
801 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
802 | + TEST_NE_P (cmd, NULL); |
803 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
804 | + TEST_EQ (line_count, 0); |
805 | + |
806 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
807 | + name2); |
808 | + TEST_NE_P (cmd, NULL); |
809 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
810 | + TEST_EQ (line_count, 1); |
811 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
812 | + nih_free (output); |
813 | + |
814 | + /*******************************************************************/ |
815 | TEST_FEATURE ("set-env in 'name' form"); |
816 | |
817 | name = NIH_MUST (nih_strdup (NULL, "foo")); |
818 | @@ -16483,6 +16636,68 @@ |
819 | nih_free (output); |
820 | |
821 | /*******************************************************************/ |
822 | + TEST_FEATURE ("multiple set-env in 'name' form"); |
823 | + |
824 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
825 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
826 | + |
827 | + cmd = nih_sprintf (NULL, "%s set-env %s %s 2>&1", get_initctl (), |
828 | + name, name2); |
829 | + TEST_NE_P (cmd, NULL); |
830 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
831 | + nih_free (output); |
832 | + |
833 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
834 | + name); |
835 | + TEST_NE_P (cmd, NULL); |
836 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
837 | + |
838 | + TEST_EQ (line_count, 1); |
839 | + |
840 | + /* nul string value expected if none specified when set */ |
841 | + TEST_EQ_STR (output[0], ""); |
842 | + |
843 | + nih_free (output); |
844 | + |
845 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
846 | + name2); |
847 | + TEST_NE_P (cmd, NULL); |
848 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
849 | + |
850 | + TEST_EQ (line_count, 1); |
851 | + |
852 | + /* nul string value expected if none specified when set */ |
853 | + TEST_EQ_STR (output[0], ""); |
854 | + |
855 | + nih_free (output); |
856 | + |
857 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
858 | + TEST_NE_P (cmd, NULL); |
859 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
860 | + TEST_EQ (line_count, 0); |
861 | + |
862 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
863 | + name); |
864 | + TEST_NE_P (cmd, NULL); |
865 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
866 | + TEST_EQ (line_count, 1); |
867 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
868 | + nih_free (output); |
869 | + |
870 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
871 | + TEST_NE_P (cmd, NULL); |
872 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
873 | + TEST_EQ (line_count, 0); |
874 | + |
875 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
876 | + name2); |
877 | + TEST_NE_P (cmd, NULL); |
878 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
879 | + TEST_EQ (line_count, 1); |
880 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
881 | + nih_free (output); |
882 | + |
883 | + /*******************************************************************/ |
884 | TEST_FEATURE ("set-env for already set variable"); |
885 | |
886 | name = NIH_MUST (nih_strdup (NULL, "foo")); |
887 | @@ -16536,6 +16751,344 @@ |
888 | nih_free (output); |
889 | |
890 | /*******************************************************************/ |
891 | + TEST_FEATURE ("set-env for multiple already set variables"); |
892 | + |
893 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
894 | + value = NIH_MUST (nih_strdup (NULL, "bar")); |
895 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
896 | + value2 = NIH_MUST (nih_strdup (NULL, "qux")); |
897 | + |
898 | + /* set them */ |
899 | + cmd = nih_sprintf (NULL, "%s set-env %s=%s %s=%s 2>&1", get_initctl (), |
900 | + name, value, name2, value2); |
901 | + TEST_NE_P (cmd, NULL); |
902 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
903 | + TEST_EQ (line_count, 0); |
904 | + |
905 | + /* check them */ |
906 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
907 | + name); |
908 | + TEST_NE_P (cmd, NULL); |
909 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
910 | + TEST_EQ (line_count, 1); |
911 | + |
912 | + TEST_EQ_STR (output[0], value); |
913 | + nih_free (output); |
914 | + |
915 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
916 | + name2); |
917 | + TEST_NE_P (cmd, NULL); |
918 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
919 | + TEST_EQ (line_count, 1); |
920 | + |
921 | + TEST_EQ_STR (output[0], value2); |
922 | + nih_free (output); |
923 | + |
924 | + /* set them again */ |
925 | + cmd = nih_sprintf (NULL, "%s set-env %s=%s %s=%s 2>&1", get_initctl (), |
926 | + name, value, name2, value2); |
927 | + TEST_NE_P (cmd, NULL); |
928 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
929 | + TEST_EQ (line_count, 0); |
930 | + |
931 | + /* check again */ |
932 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
933 | + name); |
934 | + TEST_NE_P (cmd, NULL); |
935 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
936 | + TEST_EQ (line_count, 1); |
937 | + |
938 | + TEST_EQ_STR (output[0], value); |
939 | + nih_free (output); |
940 | + |
941 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
942 | + name2); |
943 | + TEST_NE_P (cmd, NULL); |
944 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
945 | + TEST_EQ (line_count, 1); |
946 | + |
947 | + TEST_EQ_STR (output[0], value2); |
948 | + nih_free (output); |
949 | + |
950 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
951 | + TEST_NE_P (cmd, NULL); |
952 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
953 | + TEST_EQ (line_count, 0); |
954 | + |
955 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
956 | + TEST_NE_P (cmd, NULL); |
957 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
958 | + TEST_EQ (line_count, 0); |
959 | + |
960 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
961 | + name); |
962 | + TEST_NE_P (cmd, NULL); |
963 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
964 | + TEST_EQ (line_count, 1); |
965 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
966 | + nih_free (output); |
967 | + |
968 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
969 | + name2); |
970 | + TEST_NE_P (cmd, NULL); |
971 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
972 | + TEST_EQ (line_count, 1); |
973 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
974 | + nih_free (output); |
975 | + |
976 | + /*******************************************************************/ |
977 | + TEST_FEATURE ("set-env with multiple variables, some already set"); |
978 | + |
979 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
980 | + value = NIH_MUST (nih_strdup (NULL, "bar")); |
981 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
982 | + value2 = NIH_MUST (nih_strdup (NULL, "qux")); |
983 | + name3 = NIH_MUST (nih_strdup (NULL, "hello")); |
984 | + value3 = NIH_MUST (nih_strdup (NULL, "world")); |
985 | + name4 = NIH_MUST (nih_strdup (NULL, "bonjour")); |
986 | + value4 = NIH_MUST (nih_strdup (NULL, "tout le monde")); |
987 | + |
988 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
989 | + name3); |
990 | + TEST_NE_P (cmd, NULL); |
991 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
992 | + TEST_EQ (line_count, 1); |
993 | + TEST_EQ_STR (output[0], "initctl: No such variable: hello"); |
994 | + nih_free (output); |
995 | + |
996 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
997 | + name4); |
998 | + TEST_NE_P (cmd, NULL); |
999 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1000 | + TEST_EQ (line_count, 1); |
1001 | + TEST_EQ_STR (output[0], "initctl: No such variable: bonjour"); |
1002 | + nih_free (output); |
1003 | + |
1004 | + /* set 2 variables initially */ |
1005 | + cmd = nih_sprintf (NULL, "%s set-env %s='%s' %s='%s' 2>&1", get_initctl (), |
1006 | + name3, value3, name4, value4); |
1007 | + TEST_NE_P (cmd, NULL); |
1008 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1009 | + TEST_EQ (line_count, 0); |
1010 | + |
1011 | + /* check them */ |
1012 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1013 | + name3); |
1014 | + TEST_NE_P (cmd, NULL); |
1015 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1016 | + TEST_EQ (line_count, 1); |
1017 | + |
1018 | + TEST_EQ_STR (output[0], value3); |
1019 | + nih_free (output); |
1020 | + |
1021 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1022 | + name4); |
1023 | + TEST_NE_P (cmd, NULL); |
1024 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1025 | + TEST_EQ (line_count, 1); |
1026 | + |
1027 | + TEST_EQ_STR (output[0], value4); |
1028 | + nih_free (output); |
1029 | + |
1030 | + /* set them all */ |
1031 | + cmd = nih_sprintf (NULL, "%s set-env %s='%s' %s='%s' %s='%s' %s='%s' 2>&1", get_initctl (), |
1032 | + name, value, name3, value3, name2, value2, name4, value4); |
1033 | + TEST_NE_P (cmd, NULL); |
1034 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1035 | + TEST_EQ (line_count, 0); |
1036 | + |
1037 | + /* check again */ |
1038 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1039 | + name); |
1040 | + TEST_NE_P (cmd, NULL); |
1041 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1042 | + TEST_EQ (line_count, 1); |
1043 | + TEST_EQ_STR (output[0], value); |
1044 | + nih_free (output); |
1045 | + |
1046 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1047 | + name2); |
1048 | + TEST_NE_P (cmd, NULL); |
1049 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1050 | + TEST_EQ (line_count, 1); |
1051 | + TEST_EQ_STR (output[0], value2); |
1052 | + nih_free (output); |
1053 | + |
1054 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1055 | + name3); |
1056 | + TEST_NE_P (cmd, NULL); |
1057 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1058 | + TEST_EQ (line_count, 1); |
1059 | + TEST_EQ_STR (output[0], value3); |
1060 | + nih_free (output); |
1061 | + |
1062 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1063 | + name4); |
1064 | + TEST_NE_P (cmd, NULL); |
1065 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1066 | + TEST_EQ (line_count, 1); |
1067 | + TEST_EQ_STR (output[0], value4); |
1068 | + nih_free (output); |
1069 | + |
1070 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
1071 | + TEST_NE_P (cmd, NULL); |
1072 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1073 | + TEST_EQ (line_count, 0); |
1074 | + |
1075 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
1076 | + TEST_NE_P (cmd, NULL); |
1077 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1078 | + TEST_EQ (line_count, 0); |
1079 | + |
1080 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name3); |
1081 | + TEST_NE_P (cmd, NULL); |
1082 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1083 | + TEST_EQ (line_count, 0); |
1084 | + |
1085 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name4); |
1086 | + TEST_NE_P (cmd, NULL); |
1087 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1088 | + TEST_EQ (line_count, 0); |
1089 | + |
1090 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1091 | + name); |
1092 | + TEST_NE_P (cmd, NULL); |
1093 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1094 | + TEST_EQ (line_count, 1); |
1095 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
1096 | + nih_free (output); |
1097 | + |
1098 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1099 | + name2); |
1100 | + TEST_NE_P (cmd, NULL); |
1101 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1102 | + TEST_EQ (line_count, 1); |
1103 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
1104 | + nih_free (output); |
1105 | + |
1106 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1107 | + name3); |
1108 | + TEST_NE_P (cmd, NULL); |
1109 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1110 | + TEST_EQ (line_count, 1); |
1111 | + TEST_EQ_STR (output[0], "initctl: No such variable: hello"); |
1112 | + nih_free (output); |
1113 | + |
1114 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1115 | + name4); |
1116 | + TEST_NE_P (cmd, NULL); |
1117 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1118 | + TEST_EQ (line_count, 1); |
1119 | + TEST_EQ_STR (output[0], "initctl: No such variable: bonjour"); |
1120 | + nih_free (output); |
1121 | + |
1122 | + /*******************************************************************/ |
1123 | + TEST_FEATURE ("set-env with multiple variables in different forms"); |
1124 | + |
1125 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
1126 | + value = NIH_MUST (nih_strdup (NULL, "bar")); |
1127 | + name2 = NIH_MUST (nih_strdup (NULL, "baz")); |
1128 | + value2 = NIH_MUST (nih_strdup (NULL, "qux")); |
1129 | + |
1130 | + name3 = NIH_MUST (nih_strdup (NULL, "name-equals")); |
1131 | + name4 = NIH_MUST (nih_strdup (NULL, "just-name")); |
1132 | + |
1133 | + /* set them all */ |
1134 | + cmd = nih_sprintf (NULL, "%s set-env %s='%s' %s= %s %s='%s' 2>&1", get_initctl (), |
1135 | + name, value, name3, name4, name2, value2); |
1136 | + TEST_NE_P (cmd, NULL); |
1137 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1138 | + TEST_EQ (line_count, 0); |
1139 | + |
1140 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1141 | + name); |
1142 | + TEST_NE_P (cmd, NULL); |
1143 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1144 | + TEST_EQ (line_count, 1); |
1145 | + TEST_EQ_STR (output[0], value); |
1146 | + nih_free (output); |
1147 | + |
1148 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1149 | + name2); |
1150 | + TEST_NE_P (cmd, NULL); |
1151 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1152 | + TEST_EQ (line_count, 1); |
1153 | + TEST_EQ_STR (output[0], value2); |
1154 | + nih_free (output); |
1155 | + |
1156 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1157 | + name3); |
1158 | + TEST_NE_P (cmd, NULL); |
1159 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1160 | + TEST_EQ (line_count, 1); |
1161 | + |
1162 | + /* nul string value expected if none specified when set */ |
1163 | + TEST_EQ_STR (output[0], ""); |
1164 | + nih_free (output); |
1165 | + |
1166 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1167 | + name4); |
1168 | + TEST_NE_P (cmd, NULL); |
1169 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1170 | + TEST_EQ (line_count, 1); |
1171 | + |
1172 | + /* nul string value expected if none specified when set */ |
1173 | + TEST_EQ_STR (output[0], ""); |
1174 | + nih_free (output); |
1175 | + |
1176 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
1177 | + TEST_NE_P (cmd, NULL); |
1178 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1179 | + TEST_EQ (line_count, 0); |
1180 | + |
1181 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
1182 | + TEST_NE_P (cmd, NULL); |
1183 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1184 | + TEST_EQ (line_count, 0); |
1185 | + |
1186 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name3); |
1187 | + TEST_NE_P (cmd, NULL); |
1188 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1189 | + TEST_EQ (line_count, 0); |
1190 | + |
1191 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name4); |
1192 | + TEST_NE_P (cmd, NULL); |
1193 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1194 | + TEST_EQ (line_count, 0); |
1195 | + |
1196 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1197 | + name); |
1198 | + TEST_NE_P (cmd, NULL); |
1199 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1200 | + TEST_EQ (line_count, 1); |
1201 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
1202 | + nih_free (output); |
1203 | + |
1204 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1205 | + name2); |
1206 | + TEST_NE_P (cmd, NULL); |
1207 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1208 | + TEST_EQ (line_count, 1); |
1209 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
1210 | + nih_free (output); |
1211 | + |
1212 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1213 | + name3); |
1214 | + TEST_NE_P (cmd, NULL); |
1215 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1216 | + TEST_EQ (line_count, 1); |
1217 | + TEST_EQ_STR (output[0], "initctl: No such variable: name-equals"); |
1218 | + nih_free (output); |
1219 | + |
1220 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1221 | + name4); |
1222 | + TEST_NE_P (cmd, NULL); |
1223 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1224 | + TEST_EQ (line_count, 1); |
1225 | + TEST_EQ_STR (output[0], "initctl: No such variable: just-name"); |
1226 | + nih_free (output); |
1227 | + |
1228 | + /*******************************************************************/ |
1229 | TEST_FEATURE ("set-env --retain"); |
1230 | |
1231 | name = NIH_MUST (nih_strdup (NULL, "foo")); |
1232 | @@ -16587,6 +17140,151 @@ |
1233 | nih_free (output); |
1234 | |
1235 | /*******************************************************************/ |
1236 | + TEST_FEATURE ("set-env --retain with multiple variables, some already set"); |
1237 | + |
1238 | + name = NIH_MUST (nih_strdup (NULL, "foo")); |
1239 | + value = NIH_MUST (nih_strdup (NULL, "bar")); |
1240 | + name3 = NIH_MUST (nih_strdup (NULL, "hello")); |
1241 | + value3 = NIH_MUST (nih_strdup (NULL, "world")); |
1242 | + name4 = NIH_MUST (nih_strdup (NULL, "bonjour")); |
1243 | + value4 = NIH_MUST (nih_strdup (NULL, "tout le monde")); |
1244 | + |
1245 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1246 | + name3); |
1247 | + TEST_NE_P (cmd, NULL); |
1248 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1249 | + TEST_EQ (line_count, 1); |
1250 | + TEST_EQ_STR (output[0], "initctl: No such variable: hello"); |
1251 | + nih_free (output); |
1252 | + |
1253 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1254 | + name4); |
1255 | + TEST_NE_P (cmd, NULL); |
1256 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1257 | + TEST_EQ (line_count, 1); |
1258 | + TEST_EQ_STR (output[0], "initctl: No such variable: bonjour"); |
1259 | + nih_free (output); |
1260 | + |
1261 | + /* set 2 variables initially */ |
1262 | + cmd = nih_sprintf (NULL, "%s set-env %s='%s' %s='%s' 2>&1", get_initctl (), |
1263 | + name3, value3, name4, value4); |
1264 | + TEST_NE_P (cmd, NULL); |
1265 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1266 | + TEST_EQ (line_count, 0); |
1267 | + |
1268 | + /* check them */ |
1269 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1270 | + name3); |
1271 | + TEST_NE_P (cmd, NULL); |
1272 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1273 | + TEST_EQ (line_count, 1); |
1274 | + |
1275 | + TEST_EQ_STR (output[0], value3); |
1276 | + nih_free (output); |
1277 | + |
1278 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1279 | + name4); |
1280 | + TEST_NE_P (cmd, NULL); |
1281 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1282 | + TEST_EQ (line_count, 1); |
1283 | + |
1284 | + TEST_EQ_STR (output[0], value4); |
1285 | + nih_free (output); |
1286 | + |
1287 | + /* set them all */ |
1288 | + cmd = nih_sprintf (NULL, "%s set-env --retain %s='%s' %s='%s' %s='%s' %s='%s' 2>&1", |
1289 | + get_initctl (), name, value, name3, "AAAA", name2, value2, name4, "BBBB"); |
1290 | + TEST_NE_P (cmd, NULL); |
1291 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1292 | + TEST_EQ (line_count, 0); |
1293 | + |
1294 | + /* check that the original values did *NOT* change */ |
1295 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1296 | + name3); |
1297 | + TEST_NE_P (cmd, NULL); |
1298 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1299 | + TEST_EQ (line_count, 1); |
1300 | + TEST_EQ_STR (output[0], value3); |
1301 | + nih_free (output); |
1302 | + |
1303 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1304 | + name4); |
1305 | + TEST_NE_P (cmd, NULL); |
1306 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1307 | + TEST_EQ (line_count, 1); |
1308 | + TEST_EQ_STR (output[0], value4); |
1309 | + nih_free (output); |
1310 | + |
1311 | + /* Check that the initially-not set variables were set */ |
1312 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1313 | + name); |
1314 | + TEST_NE_P (cmd, NULL); |
1315 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1316 | + TEST_EQ (line_count, 1); |
1317 | + TEST_EQ_STR (output[0], value); |
1318 | + nih_free (output); |
1319 | + |
1320 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1321 | + name2); |
1322 | + TEST_NE_P (cmd, NULL); |
1323 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1324 | + TEST_EQ (line_count, 1); |
1325 | + TEST_EQ_STR (output[0], value2); |
1326 | + nih_free (output); |
1327 | + |
1328 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name); |
1329 | + TEST_NE_P (cmd, NULL); |
1330 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1331 | + TEST_EQ (line_count, 0); |
1332 | + |
1333 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name2); |
1334 | + TEST_NE_P (cmd, NULL); |
1335 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1336 | + TEST_EQ (line_count, 0); |
1337 | + |
1338 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name3); |
1339 | + TEST_NE_P (cmd, NULL); |
1340 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1341 | + TEST_EQ (line_count, 0); |
1342 | + |
1343 | + cmd = nih_sprintf (NULL, "%s unset-env %s 2>&1", get_initctl (), name4); |
1344 | + TEST_NE_P (cmd, NULL); |
1345 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1346 | + TEST_EQ (line_count, 0); |
1347 | + |
1348 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1349 | + name); |
1350 | + TEST_NE_P (cmd, NULL); |
1351 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1352 | + TEST_EQ (line_count, 1); |
1353 | + TEST_EQ_STR (output[0], "initctl: No such variable: foo"); |
1354 | + nih_free (output); |
1355 | + |
1356 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1357 | + name2); |
1358 | + TEST_NE_P (cmd, NULL); |
1359 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1360 | + TEST_EQ (line_count, 1); |
1361 | + TEST_EQ_STR (output[0], "initctl: No such variable: baz"); |
1362 | + nih_free (output); |
1363 | + |
1364 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1365 | + name3); |
1366 | + TEST_NE_P (cmd, NULL); |
1367 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1368 | + TEST_EQ (line_count, 1); |
1369 | + TEST_EQ_STR (output[0], "initctl: No such variable: hello"); |
1370 | + nih_free (output); |
1371 | + |
1372 | + cmd = nih_sprintf (NULL, "%s get-env %s 2>&1", get_initctl (), |
1373 | + name4); |
1374 | + TEST_NE_P (cmd, NULL); |
1375 | + RUN_COMMAND (NULL, cmd, &output, &line_count); |
1376 | + TEST_EQ (line_count, 1); |
1377 | + TEST_EQ_STR (output[0], "initctl: No such variable: bonjour"); |
1378 | + nih_free (output); |
1379 | + |
1380 | + /*******************************************************************/ |
1381 | TEST_FEATURE ("set-env with space within value and trailing tab"); |
1382 | |
1383 | name = NIH_MUST (nih_strdup (NULL, "foo")); |
1384 | @@ -17422,8 +18120,10 @@ |
1385 | test_version_action (); |
1386 | test_log_priority_action (); |
1387 | test_usage (); |
1388 | + |
1389 | test_job_env (); |
1390 | test_reexec (); |
1391 | + |
1392 | test_list_sessions (); |
1393 | if (have_timed_waitpid ()) { |
1394 | test_quiesce (); |
I'm going to change SetEnvMulti to SetEnvList and UnsetEnvMulti to UnsetEnvList as suggested by slangasek since the new names offer more of a hint as to what the methods actually do :)