Merge lp:~jamesodhunt/upstart/bug-1315060 into lp:upstart
- bug-1315060
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1630 |
Proposed branch: | lp:~jamesodhunt/upstart/bug-1315060 |
Merge into: | lp:upstart |
Diff against target: |
1167 lines (+898/-43) 5 files modified
ChangeLog (+24/-0) init/main.c (+91/-25) init/man/init.5 (+1/-1) init/man/init.8 (+51/-6) init/tests/test_main.c (+731/-11) |
To merge this branch: | bzr merge lp:~jamesodhunt/upstart/bug-1315060 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dimitri John Ledkov | Approve | ||
Review via email: mp+218953@code.launchpad.net |
Commit message
Description of the change
Dimitri John Ledkov (xnox) wrote : | # |
James Hunt (jamesodhunt) wrote : | # |
Right, it does sound like we need a '--prepend-confdir' option instead:
# read jobs+overrides from /foo, then /etc/init/ (PID 1)
--prepend-confdir /foo
# read jobs+overrides from /foo, then /bar, then /etc/init/ (PID 1)
--prepend-confdir /foo --prepend-confdir /bar
# read jobs+overrides from /foo, then /bar, then /hello
--confdir /hello --prepend-confdir /foo --prepend-confdir /bar
# read jobs+overrides from /bar, then /qux, then /foo, then /bar (PID 1)
--confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux
# read jobs+overrides from /bar, then /qux, then the normal Session Init directories
--user --prepend-confdir /bar --prepend-confdir /qux
# read jobs+overrides from /bar, then /qux, then /foo, then /baz
--user --confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux
When booting in --debug mode, Upstart will display the directories it is reading jobs from in the order it reads those directories. However, I do wonder if -- to mimimize confusion -- we should add a further option that simply displays the list of directories that would be searched. If that option is specified anywhere on the command line, it would display the search order, then exit. Something like:
$ init --prepend-confdir /foo --list-confdirs
/foo
/etc/init
$ init --user --confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux --list-confdirs
/bar
/qux
/foo
/baz
Dimitri John Ledkov (xnox) wrote : | # |
On 14 May 2014 17:09, James Hunt <email address hidden> wrote:
> Right, it does sound like we need a '--prepend-confdir' option instead:
>
> # read jobs+overrides from /foo, then /etc/init/ (PID 1)
> --prepend-confdir /foo
>
> # read jobs+overrides from /foo, then /bar, then /etc/init/ (PID 1)
> --prepend-confdir /foo --prepend-confdir /bar
>
> # read jobs+overrides from /foo, then /bar, then /hello
> --confdir /hello --prepend-confdir /foo --prepend-confdir /bar
>
> # read jobs+overrides from /bar, then /qux, then /foo, then /bar (PID 1)
> --confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux
>
> # read jobs+overrides from /bar, then /qux, then the normal Session Init directories
> --user --prepend-confdir /bar --prepend-confdir /qux
>
> # read jobs+overrides from /bar, then /qux, then /foo, then /baz
> --user --confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux
>
> When booting in --debug mode, Upstart will display the directories it is reading jobs from in the order it reads those directories. However, I do wonder if -- to mimimize confusion -- we should add a further option that simply displays the list of directories that would be searched. If that option is specified anywhere on the command line, it would display the search order, then exit. Something like:
>
all looks correct.
> $ init --prepend-confdir /foo --list-confdirs
> /foo
> /etc/init
>
> $ init --user --confdir /foo --prepend-confdir /bar --confdir /baz --prepend-confdir /qux --list-confdirs
> /bar
> /qux
> /foo
> /baz
>
Hm, i wouldn't want to convert init into a client tool. Instead I'd
like to simply e.g. add $ initctl dump-state, which dumps the whole
json state. All conf-sources are serialised in that state, and one can
examine currently monitored conf sources. Or create an $ initctl
list-config-sources which prints serialized conf-sources in a nicer
format. I'd rather inspect conf-sources at runtime, since for e.g.
session init conf-sources depend on the XDG environment variables
which may not be the same if one execs a new/standalone init with the
same args, but different environment.
--
Regards,
Dimitri.
James Hunt (jamesodhunt) wrote : | # |
... and conversely we want to avoid feeping creaturism - KISS FTW. I'm not convinced that dump-state should be added as a front-end to GetState(): the method is there for those that care, but dumping internal state (particularly in JSON) is not something even an admin needs to do. However, as you say, GetState() does provide an existing way to determine the .conf ordering at runtime.
I think you are right that it isn't appropriate to add --list-confdirs though. That is in fact dangerous since due to the way the option parsing works if that option name is mis-typed, it will be ignored and a new init daemon will attempt to start.
What we could do is tweak init-checkconf as I had originally planned:
https:/
... except that rather than adding the --list-confdirs option, we can have init-checkconf run GetState(), parse out the conf_dirs and dump them in a readable (non-JSON) format. Might be worth rewriting that script in Python to simplify the JSON parsing though. Another advantage to changing inti-checkconf is that it could also be changed to not spawn a new init and connect to an existing one resulting in a tool that can show the theoretical search path or the actual search path for the running init.
James Hunt (jamesodhunt) wrote : | # |
Branch updated to also support '--prepend-
- 1622. By James Hunt
-
* init/main.c: Add support for '--prepend-
confdir' .
* init/man/init.8: Add '--prepend-confdir' .
* init/tests/test_main. c: Add tests for '--prepend- confdir' . - 1623. By James Hunt
-
* Sync with lp:upstart.
Dimitri John Ledkov (xnox) : | # |
Preview Diff
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2014-05-09 15:23:36 +0000 | |||
3 | +++ ChangeLog 2014-06-04 15:39:46 +0000 | |||
4 | @@ -1,3 +1,18 @@ | |||
5 | 1 | 2014-05-21 James Hunt <james.hunt@ubuntu.com> | ||
6 | 2 | |||
7 | 3 | * init/main.c: Add support for '--prepend-confdir'. | ||
8 | 4 | * init/man/init.8: Add '--prepend-confdir'. | ||
9 | 5 | * init/tests/test_main.c: Add tests for '--prepend-confdir'. | ||
10 | 6 | |||
11 | 7 | 2014-05-09 James Hunt <james.hunt@ubuntu.com> | ||
12 | 8 | |||
13 | 9 | * init/main.c: add '--append-confdir' command-line option (LP: #1315060). | ||
14 | 10 | * init/man/init.8: | ||
15 | 11 | - Document '--append-confdir'. | ||
16 | 12 | - Add init(5) reference for '--confdir'. | ||
17 | 13 | * init/tests/test_main.c: New Session and System init tests for | ||
18 | 14 | '--append-confdir'. | ||
19 | 15 | |||
20 | 1 | 2014-05-09 Dimitri John Ledkov <xnox@ubuntu.com> | 16 | 2014-05-09 Dimitri John Ledkov <xnox@ubuntu.com> |
21 | 2 | 17 | ||
22 | 3 | * util/reboot.c: only use rebootcommand code path in runlevels 0, | 18 | * util/reboot.c: only use rebootcommand code path in runlevels 0, |
23 | @@ -11,6 +26,15 @@ | |||
24 | 11 | * Convert calls to deprecated json_object_object_get() to | 26 | * Convert calls to deprecated json_object_object_get() to |
25 | 12 | json_object_object_get_ex(). | 27 | json_object_object_get_ex(). |
26 | 13 | 28 | ||
27 | 29 | 2014-05-02 James Hunt <james.hunt@ubuntu.com> | ||
28 | 30 | |||
29 | 31 | * init/main.c: main(): Allow System Init read from multiple | ||
30 | 32 | configuration to directories like a Session Init (LP: #1315060). | ||
31 | 33 | * init/man/init.5: Clarify default directory. | ||
32 | 34 | * init/man/init.8: Explain new behaviour. | ||
33 | 35 | * init/tests/test_main.c: test_confdir(): Update tests for new | ||
34 | 36 | '--confdir' behaviour of System init. | ||
35 | 37 | |||
36 | 14 | 2014-04-24 James Hunt <james.hunt@ubuntu.com> | 38 | 2014-04-24 James Hunt <james.hunt@ubuntu.com> |
37 | 15 | 39 | ||
38 | 16 | * init/man/init.5: | 40 | * init/man/init.5: |
39 | 17 | 41 | ||
40 | === modified file 'init/main.c' | |||
41 | --- init/main.c 2014-04-11 21:15:39 +0000 | |||
42 | +++ init/main.c 2014-06-04 15:39:46 +0000 | |||
43 | @@ -1,6 +1,6 @@ | |||
44 | 1 | /* upstart | 1 | /* upstart |
45 | 2 | * | 2 | * |
47 | 3 | * Copyright © 2009-2011 Canonical Ltd. | 3 | * Copyright 2009-2011 Canonical Ltd. |
48 | 4 | * Author: Scott James Remnant <scott@netsplit.com>. | 4 | * Author: Scott James Remnant <scott@netsplit.com>. |
49 | 5 | * | 5 | * |
50 | 6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
51 | @@ -85,10 +85,12 @@ | |||
52 | 85 | static void usr1_handler (void *data, NihSignal *signal); | 85 | static void usr1_handler (void *data, NihSignal *signal); |
53 | 86 | #endif /* DEBUG */ | 86 | #endif /* DEBUG */ |
54 | 87 | 87 | ||
59 | 88 | static void handle_confdir (void); | 88 | static void handle_confdir (void); |
60 | 89 | static void handle_logdir (void); | 89 | static void handle_logdir (void); |
61 | 90 | static int console_type_setter (NihOption *option, const char *arg); | 90 | static int console_type_setter (NihOption *option, const char *arg); |
62 | 91 | static int conf_dir_setter (NihOption *option, const char *arg); | 91 | static int conf_dir_setter (NihOption *option, const char *arg); |
63 | 92 | static int prepend_conf_dir_setter (NihOption *option, const char *arg); | ||
64 | 93 | static int append_conf_dir_setter (NihOption *option, const char *arg); | ||
65 | 92 | 94 | ||
66 | 93 | 95 | ||
67 | 94 | /** | 96 | /** |
68 | @@ -107,6 +109,22 @@ | |||
69 | 107 | static char **conf_dirs = NULL; | 109 | static char **conf_dirs = NULL; |
70 | 108 | 110 | ||
71 | 109 | /** | 111 | /** |
72 | 112 | * prepend_conf_dirs: | ||
73 | 113 | * | ||
74 | 114 | * Array of full paths to job configuration file directories that will | ||
75 | 115 | * be added to before the other values in conf_dirs. | ||
76 | 116 | **/ | ||
77 | 117 | static char **prepend_conf_dirs = NULL; | ||
78 | 118 | |||
79 | 119 | /** | ||
80 | 120 | * append_conf_dirs: | ||
81 | 121 | * | ||
82 | 122 | * Array of full paths to job configuration file directories that will | ||
83 | 123 | * be added to conf_dirs. | ||
84 | 124 | **/ | ||
85 | 125 | static char **append_conf_dirs = NULL; | ||
86 | 126 | |||
87 | 127 | /** | ||
88 | 110 | * initial_event: | 128 | * initial_event: |
89 | 111 | * | 129 | * |
90 | 112 | * Alternate event to emit at startup (rather than STARTUP_EVENT). | 130 | * Alternate event to emit at startup (rather than STARTUP_EVENT). |
91 | @@ -146,30 +164,36 @@ | |||
92 | 146 | * Command-line options we accept. | 164 | * Command-line options we accept. |
93 | 147 | **/ | 165 | **/ |
94 | 148 | static NihOption options[] = { | 166 | static NihOption options[] = { |
95 | 167 | { 0, "append-confdir", N_("specify additional directory to load configuration files from"), | ||
96 | 168 | NULL, "DIR", NULL, append_conf_dir_setter }, | ||
97 | 169 | |||
98 | 170 | { 0, "chroot-sessions", N_("enable chroot sessions"), | ||
99 | 171 | NULL, NULL, &chroot_sessions, NULL }, | ||
100 | 172 | |||
101 | 149 | { 0, "confdir", N_("specify alternative directory to load configuration files from"), | 173 | { 0, "confdir", N_("specify alternative directory to load configuration files from"), |
102 | 150 | NULL, "DIR", NULL, conf_dir_setter }, | 174 | NULL, "DIR", NULL, conf_dir_setter }, |
103 | 151 | 175 | ||
104 | 152 | { 0, "default-console", N_("default value for console stanza"), | 176 | { 0, "default-console", N_("default value for console stanza"), |
105 | 153 | NULL, "VALUE", NULL, console_type_setter }, | 177 | NULL, "VALUE", NULL, console_type_setter }, |
106 | 154 | 178 | ||
107 | 179 | { 0, "logdir", N_("specify alternative directory to store job output logs in"), | ||
108 | 180 | NULL, "DIR", &log_dir, NULL }, | ||
109 | 181 | |||
110 | 155 | { 0, "no-dbus", N_("do not connect to a D-Bus bus"), | 182 | { 0, "no-dbus", N_("do not connect to a D-Bus bus"), |
111 | 156 | NULL, NULL, &disable_dbus, NULL }, | 183 | NULL, NULL, &disable_dbus, NULL }, |
112 | 157 | 184 | ||
113 | 158 | { 0, "no-inherit-env", N_("jobs will not inherit environment of init"), | 185 | { 0, "no-inherit-env", N_("jobs will not inherit environment of init"), |
114 | 159 | NULL, NULL, &no_inherit_env , NULL }, | 186 | NULL, NULL, &no_inherit_env , NULL }, |
115 | 160 | 187 | ||
116 | 161 | { 0, "logdir", N_("specify alternative directory to store job output logs in"), | ||
117 | 162 | NULL, "DIR", &log_dir, NULL }, | ||
118 | 163 | |||
119 | 164 | { 0, "no-log", N_("disable job logging"), | 188 | { 0, "no-log", N_("disable job logging"), |
120 | 165 | NULL, NULL, &disable_job_logging, NULL }, | 189 | NULL, NULL, &disable_job_logging, NULL }, |
121 | 166 | 190 | ||
122 | 167 | { 0, "chroot-sessions", N_("enable chroot sessions"), | ||
123 | 168 | NULL, NULL, &chroot_sessions, NULL }, | ||
124 | 169 | |||
125 | 170 | { 0, "no-startup-event", N_("do not emit any startup event (for testing)"), | 191 | { 0, "no-startup-event", N_("do not emit any startup event (for testing)"), |
126 | 171 | NULL, NULL, &disable_startup_event, NULL }, | 192 | NULL, NULL, &disable_startup_event, NULL }, |
127 | 172 | 193 | ||
128 | 194 | { 0, "prepend-confdir", N_("specify additional initial directory to load configuration files from"), | ||
129 | 195 | NULL, "DIR", NULL, prepend_conf_dir_setter }, | ||
130 | 196 | |||
131 | 173 | /* Must be specified for both stateful and stateless re-exec */ | 197 | /* Must be specified for both stateful and stateless re-exec */ |
132 | 174 | { 0, "restart", N_("flag a re-exec has occurred"), | 198 | { 0, "restart", N_("flag a re-exec has occurred"), |
133 | 175 | NULL, NULL, &restart, NULL }, | 199 | NULL, NULL, &restart, NULL }, |
134 | @@ -205,6 +229,8 @@ | |||
135 | 205 | int ret; | 229 | int ret; |
136 | 206 | 230 | ||
137 | 207 | conf_dirs = NIH_MUST (nih_str_array_new (NULL)); | 231 | conf_dirs = NIH_MUST (nih_str_array_new (NULL)); |
138 | 232 | append_conf_dirs = NIH_MUST (nih_str_array_new (NULL)); | ||
139 | 233 | prepend_conf_dirs = NIH_MUST (nih_str_array_new (NULL)); | ||
140 | 208 | 234 | ||
141 | 209 | args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv)); | 235 | args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv)); |
142 | 210 | 236 | ||
143 | @@ -567,25 +593,22 @@ | |||
144 | 567 | } | 593 | } |
145 | 568 | 594 | ||
146 | 569 | /* Read configuration */ | 595 | /* Read configuration */ |
147 | 596 | if (prepend_conf_dirs[0]) { | ||
148 | 597 | for (char **d = prepend_conf_dirs; d && *d; d++) { | ||
149 | 598 | nih_debug ("Prepending configuration directory %s", *d); | ||
150 | 599 | NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR)); | ||
151 | 600 | } | ||
152 | 601 | } | ||
153 | 602 | |||
154 | 570 | if (! user_mode) { | 603 | if (! user_mode) { |
155 | 571 | char *conf_dir; | ||
156 | 572 | int len = 0; | ||
157 | 573 | |||
158 | 574 | nih_assert (conf_dirs[0]); | 604 | nih_assert (conf_dirs[0]); |
159 | 575 | 605 | ||
160 | 576 | /* Count entries */ | ||
161 | 577 | for (char **d = conf_dirs; d && *d; d++, len++) | ||
162 | 578 | ; | ||
163 | 579 | |||
164 | 580 | nih_assert (len); | ||
165 | 581 | |||
166 | 582 | /* Use last value specified */ | ||
167 | 583 | conf_dir = conf_dirs[len-1]; | ||
168 | 584 | |||
169 | 585 | NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE)); | 606 | NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE)); |
170 | 586 | 607 | ||
173 | 587 | nih_debug ("Using configuration directory %s", conf_dir); | 608 | for (char **d = conf_dirs; d && *d; d++) { |
174 | 588 | NIH_MUST (conf_source_new (NULL, conf_dir, CONF_JOB_DIR)); | 609 | nih_debug ("Using configuration directory %s", *d); |
175 | 610 | NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR)); | ||
176 | 611 | } | ||
177 | 589 | } else { | 612 | } else { |
178 | 590 | nih_local char **dirs = NULL; | 613 | nih_local char **dirs = NULL; |
179 | 591 | 614 | ||
180 | @@ -597,7 +620,16 @@ | |||
181 | 597 | } | 620 | } |
182 | 598 | } | 621 | } |
183 | 599 | 622 | ||
184 | 623 | if (append_conf_dirs[0]) { | ||
185 | 624 | for (char **d = append_conf_dirs; d && *d; d++) { | ||
186 | 625 | nih_debug ("Adding configuration directory %s", *d); | ||
187 | 626 | NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR)); | ||
188 | 627 | } | ||
189 | 628 | } | ||
190 | 629 | |||
191 | 600 | nih_free (conf_dirs); | 630 | nih_free (conf_dirs); |
192 | 631 | nih_free (prepend_conf_dirs); | ||
193 | 632 | nih_free (append_conf_dirs); | ||
194 | 601 | 633 | ||
195 | 602 | job_class_environment_init (); | 634 | job_class_environment_init (); |
196 | 603 | 635 | ||
197 | @@ -1105,3 +1137,37 @@ | |||
198 | 1105 | 1137 | ||
199 | 1106 | return 0; | 1138 | return 0; |
200 | 1107 | } | 1139 | } |
201 | 1140 | |||
202 | 1141 | /** | ||
203 | 1142 | * NihOption setter function to handle selection of configuration file | ||
204 | 1143 | * directories. | ||
205 | 1144 | * | ||
206 | 1145 | * Returns: 0 on success, -1 on invalid console type. | ||
207 | 1146 | **/ | ||
208 | 1147 | static int | ||
209 | 1148 | prepend_conf_dir_setter (NihOption *option, const char *arg) | ||
210 | 1149 | { | ||
211 | 1150 | nih_assert (prepend_conf_dirs); | ||
212 | 1151 | nih_assert (option); | ||
213 | 1152 | |||
214 | 1153 | NIH_MUST (nih_str_array_add (&prepend_conf_dirs, NULL, NULL, arg)); | ||
215 | 1154 | |||
216 | 1155 | return 0; | ||
217 | 1156 | } | ||
218 | 1157 | |||
219 | 1158 | /** | ||
220 | 1159 | * NihOption setter function to handle selection of configuration file | ||
221 | 1160 | * directories. | ||
222 | 1161 | * | ||
223 | 1162 | * Returns: 0 on success, -1 on invalid console type. | ||
224 | 1163 | **/ | ||
225 | 1164 | static int | ||
226 | 1165 | append_conf_dir_setter (NihOption *option, const char *arg) | ||
227 | 1166 | { | ||
228 | 1167 | nih_assert (append_conf_dirs); | ||
229 | 1168 | nih_assert (option); | ||
230 | 1169 | |||
231 | 1170 | NIH_MUST (nih_str_array_add (&append_conf_dirs, NULL, NULL, arg)); | ||
232 | 1171 | |||
233 | 1172 | return 0; | ||
234 | 1173 | } | ||
235 | 1108 | 1174 | ||
236 | === modified file 'init/man/init.5' | |||
237 | --- init/man/init.5 2014-04-24 12:39:18 +0000 | |||
238 | +++ init/man/init.5 2014-06-04 15:39:46 +0000 | |||
239 | @@ -22,7 +22,7 @@ | |||
240 | 22 | .BR init (8) | 22 | .BR init (8) |
241 | 23 | daemon reads its job configuration from files in the | 23 | daemon reads its job configuration from files in the |
242 | 24 | .I /etc/init/ | 24 | .I /etc/init/ |
244 | 25 | directory, and watches for future changes to these files using | 25 | directory by default, and watches for future changes to these files using |
245 | 26 | .BR inotify (7). | 26 | .BR inotify (7). |
246 | 27 | 27 | ||
247 | 28 | If Upstart was invoked as a user process with \-\-user option, it will | 28 | If Upstart was invoked as a user process with \-\-user option, it will |
248 | 29 | 29 | ||
249 | === modified file 'init/man/init.8' | |||
250 | --- init/man/init.8 2013-12-23 17:31:22 +0000 | |||
251 | +++ init/man/init.8 2014-06-04 15:39:46 +0000 | |||
252 | @@ -253,14 +253,41 @@ | |||
253 | 253 | by placing them on the kernel command-line. | 253 | by placing them on the kernel command-line. |
254 | 254 | .\" | 254 | .\" |
255 | 255 | .TP | 255 | .TP |
256 | 256 | .B \-\-append-confdir \fIdirectory\fP | ||
257 | 257 | Add the specified directory to the default directory or directories | ||
258 | 258 | that job configuration files will be read from. This option may be | ||
259 | 259 | specified multiple times which will result in job configuration files | ||
260 | 260 | being loaded from each directory specified (which must exist). | ||
261 | 261 | Directories will be searched for jobs in the specified order after the | ||
262 | 262 | default directories have been searched. | ||
263 | 263 | |||
264 | 264 | Note that if this option is used in combination with | ||
265 | 265 | .BR \-\-confdir "," | ||
266 | 266 | or | ||
267 | 267 | .BR \-\-prepend\-confdir "," | ||
268 | 268 | regardless of the order of the options on the command-line, the append | ||
269 | 269 | directories will be added | ||
270 | 270 | .I after | ||
271 | 271 | the other directories. | ||
272 | 272 | .\" | ||
273 | 273 | .TP | ||
274 | 256 | .B \-\-confdir \fIdirectory\fP | 274 | .B \-\-confdir \fIdirectory\fP |
275 | 257 | Read job configuration files from a directory other than the default | 275 | Read job configuration files from a directory other than the default |
282 | 258 | (\fI/etc/init\fP for process ID 1). | 276 | (\fI/etc/init\fP for process ID 1). This option may be specified |
283 | 259 | 277 | multiple times which will result in job configuration files being | |
284 | 260 | When running as process ID 1, the last directory specified will be used. | 278 | loaded from each directory specified (which must exist). Directories |
285 | 261 | 279 | will be searched for jobs in the specified order. | |
286 | 262 | In user session mode, multiple directories will be honoured and job | 280 | |
287 | 263 | configuration files loaded from the directories in the order specified. | 281 | In the case that multiple directories specify a job of the same name, |
288 | 282 | the first job encountered will be honoured. | ||
289 | 283 | |||
290 | 284 | See section | ||
291 | 285 | .B User Session Mode | ||
292 | 286 | in | ||
293 | 287 | .BR init (5) | ||
294 | 288 | for the ordered list of default configuration directories a | ||
295 | 289 | Session Init will consider. | ||
296 | 290 | |||
297 | 264 | .\" | 291 | .\" |
298 | 265 | .TP | 292 | .TP |
299 | 266 | .B \-\-default-console \fIvalue\fP | 293 | .B \-\-default-console \fIvalue\fP |
300 | @@ -308,6 +335,24 @@ | |||
301 | 308 | daemon from starting \fBany\fP jobs automatically. | 335 | daemon from starting \fBany\fP jobs automatically. |
302 | 309 | .\" | 336 | .\" |
303 | 310 | .TP | 337 | .TP |
304 | 338 | .B \-\-prepend-confdir \fIdirectory\fP | ||
305 | 339 | Add the specified directory to the directory or directories | ||
306 | 340 | that job configuration files will be read from. This option may be | ||
307 | 341 | specified multiple times which will result in job configuration files | ||
308 | 342 | being loaded from each directory specified (which must exist). | ||
309 | 343 | Directories will be searched for jobs in the specified order before the | ||
310 | 344 | default directories have been searched. | ||
311 | 345 | |||
312 | 346 | Note that if this option is used in combination with | ||
313 | 347 | .BR \-\-confdir "," | ||
314 | 348 | or | ||
315 | 349 | .BR \-\-append\-confdir "," | ||
316 | 350 | regardless of the order of the options on the command-line, the prepend | ||
317 | 351 | directories will be added | ||
318 | 352 | .I before | ||
319 | 353 | the other directories. | ||
320 | 354 | .\" | ||
321 | 355 | .TP | ||
322 | 311 | .B \-\-session | 356 | .B \-\-session |
323 | 312 | Connect to the D\-Bus session bus. This should only be used for testing. | 357 | Connect to the D\-Bus session bus. This should only be used for testing. |
324 | 313 | .\" | 358 | .\" |
325 | 314 | 359 | ||
326 | === modified file 'init/tests/test_main.c' | |||
327 | --- init/tests/test_main.c 2013-11-12 12:17:30 +0000 | |||
328 | +++ init/tests/test_main.c 2014-06-04 15:39:46 +0000 | |||
329 | @@ -46,6 +46,10 @@ | |||
330 | 46 | { | 46 | { |
331 | 47 | char confdir_a[PATH_MAX]; | 47 | char confdir_a[PATH_MAX]; |
332 | 48 | char confdir_b[PATH_MAX]; | 48 | char confdir_b[PATH_MAX]; |
333 | 49 | char confdir_c[PATH_MAX]; | ||
334 | 50 | char confdir_d[PATH_MAX]; | ||
335 | 51 | char confdir_e[PATH_MAX]; | ||
336 | 52 | char confdir_f[PATH_MAX]; | ||
337 | 49 | char *xdg_config_home; | 53 | char *xdg_config_home; |
338 | 50 | char *xdg_runtime_dir; | 54 | char *xdg_runtime_dir; |
339 | 51 | char logdir[PATH_MAX]; | 55 | char logdir[PATH_MAX]; |
340 | @@ -58,8 +62,10 @@ | |||
341 | 58 | nih_local char *session_file = NULL; | 62 | nih_local char *session_file = NULL; |
342 | 59 | nih_local char *path = NULL; | 63 | nih_local char *path = NULL; |
343 | 60 | 64 | ||
346 | 61 | /* space for 2 sets of confdir options and a terminator */ | 65 | /* space for 2 sets of confdir options, 2 sets of |
347 | 62 | char *extra[5]; | 66 | * prepend-confdir, 2 sets of append-confdirs and a terminator. |
348 | 67 | */ | ||
349 | 68 | char *extra[13]; | ||
350 | 63 | 69 | ||
351 | 64 | xdg_config_home = getenv ("XDG_CONFIG_HOME"); | 70 | xdg_config_home = getenv ("XDG_CONFIG_HOME"); |
352 | 65 | TEST_NE_P (xdg_config_home, NULL); | 71 | TEST_NE_P (xdg_config_home, NULL); |
353 | @@ -75,6 +81,18 @@ | |||
354 | 75 | TEST_FILENAME (confdir_b); | 81 | TEST_FILENAME (confdir_b); |
355 | 76 | assert0 (mkdir (confdir_b, 0755)); | 82 | assert0 (mkdir (confdir_b, 0755)); |
356 | 77 | 83 | ||
357 | 84 | TEST_FILENAME (confdir_c); | ||
358 | 85 | assert0 (mkdir (confdir_c, 0755)); | ||
359 | 86 | |||
360 | 87 | TEST_FILENAME (confdir_d); | ||
361 | 88 | assert0 (mkdir (confdir_d, 0755)); | ||
362 | 89 | |||
363 | 90 | TEST_FILENAME (confdir_e); | ||
364 | 91 | assert0 (mkdir (confdir_e, 0755)); | ||
365 | 92 | |||
366 | 93 | TEST_FILENAME (confdir_f); | ||
367 | 94 | assert0 (mkdir (confdir_f, 0755)); | ||
368 | 95 | |||
369 | 78 | xdg_conf_dir = nih_sprintf (NULL, "%s/%s", xdg_config_home, "upstart"); | 96 | xdg_conf_dir = nih_sprintf (NULL, "%s/%s", xdg_config_home, "upstart"); |
370 | 79 | TEST_NE_P (xdg_conf_dir, NULL); | 97 | TEST_NE_P (xdg_conf_dir, NULL); |
371 | 80 | assert0 (mkdir (xdg_conf_dir, 0755)); | 98 | assert0 (mkdir (xdg_conf_dir, 0755)); |
372 | @@ -151,6 +169,89 @@ | |||
373 | 151 | assert0 (unlink (session_file)); | 169 | assert0 (unlink (session_file)); |
374 | 152 | 170 | ||
375 | 153 | /************************************************************/ | 171 | /************************************************************/ |
376 | 172 | TEST_FEATURE ("Session Init with --prepend-confdir"); | ||
377 | 173 | |||
378 | 174 | CREATE_FILE (confdir_a, "foo.conf", "exec foo"); | ||
379 | 175 | CREATE_FILE (confdir_a, "conflict.conf", "emits prepend"); | ||
380 | 176 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits confdir"); | ||
381 | 177 | CREATE_FILE (xdg_conf_dir, "baz.conf", "exec baz"); | ||
382 | 178 | |||
383 | 179 | extra[0] = "--prepend-confdir"; | ||
384 | 180 | extra[1] = confdir_a; | ||
385 | 181 | extra[2] = NULL; | ||
386 | 182 | |||
387 | 183 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
388 | 184 | |||
389 | 185 | /* Should be running */ | ||
390 | 186 | assert0 (kill (upstart_pid, 0)); | ||
391 | 187 | |||
392 | 188 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
393 | 189 | |||
394 | 190 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
395 | 191 | TEST_NE_P (cmd, NULL); | ||
396 | 192 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
397 | 193 | |||
398 | 194 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
399 | 195 | |||
400 | 196 | TEST_EQ (lines, 3); | ||
401 | 197 | TEST_STR_MATCH (output[0], "baz stop/waiting"); | ||
402 | 198 | TEST_STR_MATCH (output[1], "conflict stop/waiting"); | ||
403 | 199 | TEST_STR_MATCH (output[2], "foo stop/waiting"); | ||
404 | 200 | nih_free (output); | ||
405 | 201 | |||
406 | 202 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
407 | 203 | TEST_NE_P (cmd, NULL); | ||
408 | 204 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
409 | 205 | |||
410 | 206 | TEST_EQ (lines, 2); | ||
411 | 207 | TEST_STR_MATCH (output[0], "conflict"); | ||
412 | 208 | TEST_STR_MATCH (output[1], " emits prepend"); | ||
413 | 209 | nih_free (output); | ||
414 | 210 | |||
415 | 211 | DELETE_FILE (confdir_a, "foo.conf"); | ||
416 | 212 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
417 | 213 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | ||
418 | 214 | DELETE_FILE (xdg_conf_dir, "baz.conf"); | ||
419 | 215 | |||
420 | 216 | STOP_UPSTART (upstart_pid); | ||
421 | 217 | assert0 (unlink (session_file)); | ||
422 | 218 | |||
423 | 219 | /************************************************************/ | ||
424 | 220 | TEST_FEATURE ("Session Init with --append-confdir"); | ||
425 | 221 | |||
426 | 222 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); | ||
427 | 223 | CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true"); | ||
428 | 224 | |||
429 | 225 | extra[0] = "--append-confdir"; | ||
430 | 226 | extra[1] = confdir_a; | ||
431 | 227 | extra[2] = NULL; | ||
432 | 228 | |||
433 | 229 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
434 | 230 | |||
435 | 231 | /* Should be running */ | ||
436 | 232 | assert0 (kill (upstart_pid, 0)); | ||
437 | 233 | |||
438 | 234 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
439 | 235 | |||
440 | 236 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
441 | 237 | TEST_NE_P (cmd, NULL); | ||
442 | 238 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
443 | 239 | |||
444 | 240 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
445 | 241 | |||
446 | 242 | /* jobs in xdg_conf_dir should be considered */ | ||
447 | 243 | TEST_EQ (lines, 2); | ||
448 | 244 | TEST_STR_MATCH (output[0], "conf_dir_job stop/waiting"); | ||
449 | 245 | TEST_STR_MATCH (output[1], "xdg_dir_job stop/waiting"); | ||
450 | 246 | nih_free (output); | ||
451 | 247 | |||
452 | 248 | DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf"); | ||
453 | 249 | DELETE_FILE (confdir_a, "conf_dir_job.conf"); | ||
454 | 250 | |||
455 | 251 | STOP_UPSTART (upstart_pid); | ||
456 | 252 | assert0 (unlink (session_file)); | ||
457 | 253 | |||
458 | 254 | /************************************************************/ | ||
459 | 154 | TEST_FEATURE ("Session Init with multiple --confdir"); | 255 | TEST_FEATURE ("Session Init with multiple --confdir"); |
460 | 155 | 256 | ||
461 | 156 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); | 257 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); |
462 | @@ -191,6 +292,88 @@ | |||
463 | 191 | assert0 (unlink (session_file)); | 292 | assert0 (unlink (session_file)); |
464 | 192 | 293 | ||
465 | 193 | /************************************************************/ | 294 | /************************************************************/ |
466 | 295 | TEST_FEATURE ("Session Init with multiple --prepend-confdir"); | ||
467 | 296 | |||
468 | 297 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); | ||
469 | 298 | CREATE_FILE (confdir_a, "conf_dir_a_job.conf", "exec true"); | ||
470 | 299 | CREATE_FILE (confdir_b, "conf_dir_b_job.conf", "exec true"); | ||
471 | 300 | |||
472 | 301 | extra[0] = "--prepend-confdir"; | ||
473 | 302 | extra[1] = confdir_a; | ||
474 | 303 | extra[2] = "--prepend-confdir"; | ||
475 | 304 | extra[3] = confdir_b; | ||
476 | 305 | extra[4] = NULL; | ||
477 | 306 | |||
478 | 307 | /* pass 2 confdir directories */ | ||
479 | 308 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
480 | 309 | |||
481 | 310 | /* Should be running */ | ||
482 | 311 | assert0 (kill (upstart_pid, 0)); | ||
483 | 312 | |||
484 | 313 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
485 | 314 | |||
486 | 315 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
487 | 316 | TEST_NE_P (cmd, NULL); | ||
488 | 317 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
489 | 318 | |||
490 | 319 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
491 | 320 | |||
492 | 321 | /* jobs in xdg_conf_dir should be considered */ | ||
493 | 322 | TEST_EQ (lines, 3); | ||
494 | 323 | TEST_STR_MATCH (output[0], "conf_dir_a_job stop/waiting"); | ||
495 | 324 | TEST_STR_MATCH (output[1], "conf_dir_b_job stop/waiting"); | ||
496 | 325 | TEST_STR_MATCH (output[2], "xdg_dir_job stop/waiting"); | ||
497 | 326 | nih_free (output); | ||
498 | 327 | |||
499 | 328 | DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf"); | ||
500 | 329 | DELETE_FILE (confdir_a, "conf_dir_a_job.conf"); | ||
501 | 330 | DELETE_FILE (confdir_b, "conf_dir_b_job.conf"); | ||
502 | 331 | |||
503 | 332 | STOP_UPSTART (upstart_pid); | ||
504 | 333 | assert0 (unlink (session_file)); | ||
505 | 334 | |||
506 | 335 | /************************************************************/ | ||
507 | 336 | TEST_FEATURE ("Session Init with multiple --append-confdir"); | ||
508 | 337 | |||
509 | 338 | CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true"); | ||
510 | 339 | CREATE_FILE (confdir_a, "conf_dir_a_job.conf", "exec true"); | ||
511 | 340 | CREATE_FILE (confdir_b, "conf_dir_b_job.conf", "exec true"); | ||
512 | 341 | |||
513 | 342 | extra[0] = "--append-confdir"; | ||
514 | 343 | extra[1] = confdir_a; | ||
515 | 344 | extra[2] = "--append-confdir"; | ||
516 | 345 | extra[3] = confdir_b; | ||
517 | 346 | extra[4] = NULL; | ||
518 | 347 | |||
519 | 348 | /* pass 2 confdir directories */ | ||
520 | 349 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
521 | 350 | |||
522 | 351 | /* Should be running */ | ||
523 | 352 | assert0 (kill (upstart_pid, 0)); | ||
524 | 353 | |||
525 | 354 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
526 | 355 | |||
527 | 356 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
528 | 357 | TEST_NE_P (cmd, NULL); | ||
529 | 358 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
530 | 359 | |||
531 | 360 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
532 | 361 | |||
533 | 362 | /* jobs in xdg_conf_dir should be considered */ | ||
534 | 363 | TEST_EQ (lines, 3); | ||
535 | 364 | TEST_STR_MATCH (output[0], "conf_dir_a_job stop/waiting"); | ||
536 | 365 | TEST_STR_MATCH (output[1], "conf_dir_b_job stop/waiting"); | ||
537 | 366 | TEST_STR_MATCH (output[2], "xdg_dir_job stop/waiting"); | ||
538 | 367 | nih_free (output); | ||
539 | 368 | |||
540 | 369 | DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf"); | ||
541 | 370 | DELETE_FILE (confdir_a, "conf_dir_a_job.conf"); | ||
542 | 371 | DELETE_FILE (confdir_b, "conf_dir_b_job.conf"); | ||
543 | 372 | |||
544 | 373 | STOP_UPSTART (upstart_pid); | ||
545 | 374 | assert0 (unlink (session_file)); | ||
546 | 375 | |||
547 | 376 | /************************************************************/ | ||
548 | 194 | TEST_FEATURE ("Session Init with multiple --confdir and conflicting names"); | 377 | TEST_FEATURE ("Session Init with multiple --confdir and conflicting names"); |
549 | 195 | 378 | ||
550 | 196 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); | 379 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); |
551 | @@ -241,6 +424,233 @@ | |||
552 | 241 | assert0 (unlink (session_file)); | 424 | assert0 (unlink (session_file)); |
553 | 242 | 425 | ||
554 | 243 | /************************************************************/ | 426 | /************************************************************/ |
555 | 427 | TEST_FEATURE ("Session Init with multiple --prepend-confdir and conflicting names"); | ||
556 | 428 | |||
557 | 429 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); | ||
558 | 430 | CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a"); | ||
559 | 431 | CREATE_FILE (confdir_b, "foo.conf", "exec true"); | ||
560 | 432 | |||
561 | 433 | extra[0] = "--prepend-confdir"; | ||
562 | 434 | extra[1] = confdir_a; | ||
563 | 435 | extra[2] = "--prepend-confdir"; | ||
564 | 436 | extra[3] = confdir_b; | ||
565 | 437 | extra[4] = NULL; | ||
566 | 438 | |||
567 | 439 | /* pass 2 confdir directories */ | ||
568 | 440 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
569 | 441 | |||
570 | 442 | /* Should be running */ | ||
571 | 443 | assert0 (kill (upstart_pid, 0)); | ||
572 | 444 | |||
573 | 445 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
574 | 446 | |||
575 | 447 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
576 | 448 | TEST_NE_P (cmd, NULL); | ||
577 | 449 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
578 | 450 | |||
579 | 451 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
580 | 452 | |||
581 | 453 | /* We expect jobs in xdg_conf_dir to be ignored */ | ||
582 | 454 | TEST_EQ (lines, 2); | ||
583 | 455 | TEST_STR_MATCH (output[0], "conflict stop/waiting"); | ||
584 | 456 | TEST_STR_MATCH (output[1], "foo stop/waiting"); | ||
585 | 457 | nih_free (output); | ||
586 | 458 | |||
587 | 459 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
588 | 460 | TEST_NE_P (cmd, NULL); | ||
589 | 461 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
590 | 462 | |||
591 | 463 | /* Ensure the correct version of the conflict job is found */ | ||
592 | 464 | TEST_EQ (lines, 2); | ||
593 | 465 | TEST_STR_MATCH (output[0], "conflict"); | ||
594 | 466 | TEST_STR_MATCH (output[1], " emits confdir_a"); | ||
595 | 467 | nih_free (output); | ||
596 | 468 | |||
597 | 469 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | ||
598 | 470 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
599 | 471 | DELETE_FILE (confdir_b, "foo.conf"); | ||
600 | 472 | |||
601 | 473 | STOP_UPSTART (upstart_pid); | ||
602 | 474 | assert0 (unlink (session_file)); | ||
603 | 475 | |||
604 | 476 | /************************************************************/ | ||
605 | 477 | TEST_FEATURE ("Session Init with multiple --append-confdir and conflicting names"); | ||
606 | 478 | |||
607 | 479 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); | ||
608 | 480 | CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a"); | ||
609 | 481 | CREATE_FILE (confdir_b, "foo.conf", "exec true"); | ||
610 | 482 | |||
611 | 483 | extra[0] = "--append-confdir"; | ||
612 | 484 | extra[1] = confdir_a; | ||
613 | 485 | extra[2] = "--append-confdir"; | ||
614 | 486 | extra[3] = confdir_b; | ||
615 | 487 | extra[4] = NULL; | ||
616 | 488 | |||
617 | 489 | /* pass 2 confdir directories */ | ||
618 | 490 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
619 | 491 | |||
620 | 492 | /* Should be running */ | ||
621 | 493 | assert0 (kill (upstart_pid, 0)); | ||
622 | 494 | |||
623 | 495 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
624 | 496 | |||
625 | 497 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
626 | 498 | TEST_NE_P (cmd, NULL); | ||
627 | 499 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
628 | 500 | |||
629 | 501 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
630 | 502 | |||
631 | 503 | /* We expect jobs in xdg_conf_dir to be ignored */ | ||
632 | 504 | TEST_EQ (lines, 2); | ||
633 | 505 | TEST_STR_MATCH (output[0], "conflict stop/waiting"); | ||
634 | 506 | TEST_STR_MATCH (output[1], "foo stop/waiting"); | ||
635 | 507 | nih_free (output); | ||
636 | 508 | |||
637 | 509 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
638 | 510 | TEST_NE_P (cmd, NULL); | ||
639 | 511 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
640 | 512 | |||
641 | 513 | /* Ensure the correct version of the conflict job is found */ | ||
642 | 514 | TEST_EQ (lines, 2); | ||
643 | 515 | TEST_STR_MATCH (output[0], "conflict"); | ||
644 | 516 | TEST_STR_MATCH (output[1], " emits xdg_conf_dir"); | ||
645 | 517 | nih_free (output); | ||
646 | 518 | |||
647 | 519 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | ||
648 | 520 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
649 | 521 | DELETE_FILE (confdir_b, "foo.conf"); | ||
650 | 522 | |||
651 | 523 | STOP_UPSTART (upstart_pid); | ||
652 | 524 | assert0 (unlink (session_file)); | ||
653 | 525 | |||
654 | 526 | /************************************************************/ | ||
655 | 527 | TEST_FEATURE ("Session Init with multiple --confdir, --prepend-confdir and --append-confdir with conflicting names"); | ||
656 | 528 | |||
657 | 529 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); | ||
658 | 530 | CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a"); | ||
659 | 531 | CREATE_FILE (confdir_b, "foo.conf", "exec true"); | ||
660 | 532 | CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c"); | ||
661 | 533 | CREATE_FILE (confdir_d, "conflict.conf", "emits confdir_d"); | ||
662 | 534 | CREATE_FILE (confdir_e, "bar.conf", "exec false"); | ||
663 | 535 | |||
664 | 536 | extra[0] = "--prepend-confdir"; | ||
665 | 537 | extra[1] = confdir_d; | ||
666 | 538 | extra[2] = "--prepend-confdir"; | ||
667 | 539 | extra[3] = confdir_e; | ||
668 | 540 | extra[4] = "--confdir"; | ||
669 | 541 | extra[5] = confdir_a; | ||
670 | 542 | extra[6] = "--confdir"; | ||
671 | 543 | extra[7] = confdir_b; | ||
672 | 544 | extra[8] = "--append-confdir"; | ||
673 | 545 | extra[9] = confdir_c; | ||
674 | 546 | extra[10] = NULL; | ||
675 | 547 | |||
676 | 548 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
677 | 549 | |||
678 | 550 | /* Should be running */ | ||
679 | 551 | assert0 (kill (upstart_pid, 0)); | ||
680 | 552 | |||
681 | 553 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
682 | 554 | |||
683 | 555 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
684 | 556 | TEST_NE_P (cmd, NULL); | ||
685 | 557 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
686 | 558 | |||
687 | 559 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
688 | 560 | |||
689 | 561 | TEST_EQ (lines, 3); | ||
690 | 562 | TEST_STR_MATCH (output[0], "bar stop/waiting"); | ||
691 | 563 | TEST_STR_MATCH (output[1], "conflict stop/waiting"); | ||
692 | 564 | TEST_STR_MATCH (output[2], "foo stop/waiting"); | ||
693 | 565 | nih_free (output); | ||
694 | 566 | |||
695 | 567 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
696 | 568 | TEST_NE_P (cmd, NULL); | ||
697 | 569 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
698 | 570 | |||
699 | 571 | /* Ensure the correct version of the conflict job is found */ | ||
700 | 572 | TEST_EQ (lines, 2); | ||
701 | 573 | TEST_STR_MATCH (output[0], "conflict"); | ||
702 | 574 | TEST_STR_MATCH (output[1], " emits confdir_d"); | ||
703 | 575 | nih_free (output); | ||
704 | 576 | |||
705 | 577 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | ||
706 | 578 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
707 | 579 | DELETE_FILE (confdir_b, "foo.conf"); | ||
708 | 580 | DELETE_FILE (confdir_c, "conflict.conf"); | ||
709 | 581 | DELETE_FILE (confdir_d, "conflict.conf"); | ||
710 | 582 | DELETE_FILE (confdir_e, "bar.conf"); | ||
711 | 583 | |||
712 | 584 | STOP_UPSTART (upstart_pid); | ||
713 | 585 | assert0 (unlink (session_file)); | ||
714 | 586 | |||
715 | 587 | /************************************************************/ | ||
716 | 588 | TEST_FEATURE ("Session Init with multiple out of order --confdir, --prepend-confdir and --append-confdir"); | ||
717 | 589 | |||
718 | 590 | CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir"); | ||
719 | 591 | CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a"); | ||
720 | 592 | CREATE_FILE (confdir_b, "foo.conf", "exec true"); | ||
721 | 593 | CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c"); | ||
722 | 594 | CREATE_FILE (confdir_d, "conflict.conf", "emits confdir_d"); | ||
723 | 595 | CREATE_FILE (confdir_e, "bar.conf", "exec false"); | ||
724 | 596 | CREATE_FILE (confdir_f, "baz.conf", "exec false"); | ||
725 | 597 | |||
726 | 598 | extra[0] = "--append-confdir"; | ||
727 | 599 | extra[1] = confdir_a; | ||
728 | 600 | extra[2] = "--prepend-confdir"; | ||
729 | 601 | extra[3] = confdir_e; | ||
730 | 602 | extra[4] = "--confdir"; | ||
731 | 603 | extra[5] = confdir_b; | ||
732 | 604 | extra[6] = "--append-confdir"; | ||
733 | 605 | extra[7] = confdir_c; | ||
734 | 606 | extra[8] = "--prepend-confdir"; | ||
735 | 607 | extra[9] = confdir_f; | ||
736 | 608 | extra[10] = "--confdir"; | ||
737 | 609 | extra[11] = confdir_d; | ||
738 | 610 | extra[12] = NULL; | ||
739 | 611 | |||
740 | 612 | start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra); | ||
741 | 613 | |||
742 | 614 | /* Should be running */ | ||
743 | 615 | assert0 (kill (upstart_pid, 0)); | ||
744 | 616 | |||
745 | 617 | session_file = get_session_file (xdg_runtime_dir, upstart_pid); | ||
746 | 618 | |||
747 | 619 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
748 | 620 | TEST_NE_P (cmd, NULL); | ||
749 | 621 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
750 | 622 | |||
751 | 623 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
752 | 624 | |||
753 | 625 | TEST_EQ (lines, 4); | ||
754 | 626 | TEST_STR_MATCH (output[0], "bar stop/waiting"); | ||
755 | 627 | TEST_STR_MATCH (output[1], "baz stop/waiting"); | ||
756 | 628 | TEST_STR_MATCH (output[2], "conflict stop/waiting"); | ||
757 | 629 | TEST_STR_MATCH (output[3], "foo stop/waiting"); | ||
758 | 630 | nih_free (output); | ||
759 | 631 | |||
760 | 632 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
761 | 633 | TEST_NE_P (cmd, NULL); | ||
762 | 634 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
763 | 635 | |||
764 | 636 | /* Ensure the correct version of the conflict job is found */ | ||
765 | 637 | TEST_EQ (lines, 2); | ||
766 | 638 | TEST_STR_MATCH (output[0], "conflict"); | ||
767 | 639 | TEST_STR_MATCH (output[1], " emits confdir_d"); | ||
768 | 640 | nih_free (output); | ||
769 | 641 | |||
770 | 642 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | ||
771 | 643 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
772 | 644 | DELETE_FILE (confdir_b, "foo.conf"); | ||
773 | 645 | DELETE_FILE (confdir_c, "conflict.conf"); | ||
774 | 646 | DELETE_FILE (confdir_d, "conflict.conf"); | ||
775 | 647 | DELETE_FILE (confdir_e, "bar.conf"); | ||
776 | 648 | DELETE_FILE (confdir_f, "baz.conf"); | ||
777 | 649 | |||
778 | 650 | STOP_UPSTART (upstart_pid); | ||
779 | 651 | assert0 (unlink (session_file)); | ||
780 | 652 | |||
781 | 653 | /************************************************************/ | ||
782 | 244 | TEST_FEATURE ("System Init without --confdir"); | 654 | TEST_FEATURE ("System Init without --confdir"); |
783 | 245 | 655 | ||
784 | 246 | /* Use the "secret" interface */ | 656 | /* Use the "secret" interface */ |
785 | @@ -305,6 +715,66 @@ | |||
786 | 305 | STOP_UPSTART (upstart_pid); | 715 | STOP_UPSTART (upstart_pid); |
787 | 306 | 716 | ||
788 | 307 | /************************************************************/ | 717 | /************************************************************/ |
789 | 718 | TEST_FEATURE ("System Init with --prepend-confdir"); | ||
790 | 719 | |||
791 | 720 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
792 | 721 | |||
793 | 722 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true"); | ||
794 | 723 | |||
795 | 724 | extra[0] = "--prepend-confdir"; | ||
796 | 725 | extra[1] = confdir_a; | ||
797 | 726 | extra[2] = NULL; | ||
798 | 727 | |||
799 | 728 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
800 | 729 | |||
801 | 730 | /* Should be running */ | ||
802 | 731 | assert0 (kill (upstart_pid, 0)); | ||
803 | 732 | |||
804 | 733 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
805 | 734 | TEST_NE_P (cmd, NULL); | ||
806 | 735 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
807 | 736 | |||
808 | 737 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
809 | 738 | |||
810 | 739 | TEST_EQ (lines, 1); | ||
811 | 740 | TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting"); | ||
812 | 741 | nih_free (output); | ||
813 | 742 | |||
814 | 743 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
815 | 744 | |||
816 | 745 | STOP_UPSTART (upstart_pid); | ||
817 | 746 | |||
818 | 747 | /************************************************************/ | ||
819 | 748 | TEST_FEATURE ("System Init with --append-confdir"); | ||
820 | 749 | |||
821 | 750 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
822 | 751 | |||
823 | 752 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true"); | ||
824 | 753 | |||
825 | 754 | extra[0] = "--append-confdir"; | ||
826 | 755 | extra[1] = confdir_a; | ||
827 | 756 | extra[2] = NULL; | ||
828 | 757 | |||
829 | 758 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
830 | 759 | |||
831 | 760 | /* Should be running */ | ||
832 | 761 | assert0 (kill (upstart_pid, 0)); | ||
833 | 762 | |||
834 | 763 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
835 | 764 | TEST_NE_P (cmd, NULL); | ||
836 | 765 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
837 | 766 | |||
838 | 767 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
839 | 768 | |||
840 | 769 | TEST_EQ (lines, 1); | ||
841 | 770 | TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting"); | ||
842 | 771 | nih_free (output); | ||
843 | 772 | |||
844 | 773 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
845 | 774 | |||
846 | 775 | STOP_UPSTART (upstart_pid); | ||
847 | 776 | |||
848 | 777 | /************************************************************/ | ||
849 | 308 | TEST_FEATURE ("System Init with multiple --confdir"); | 778 | TEST_FEATURE ("System Init with multiple --confdir"); |
850 | 309 | 779 | ||
851 | 310 | assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1)); | 780 | assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1)); |
852 | @@ -331,14 +801,14 @@ | |||
853 | 331 | 801 | ||
854 | 332 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | 802 | qsort (output, lines, sizeof (output[0]), strcmp_compar); |
855 | 333 | 803 | ||
861 | 334 | TEST_EQ (lines, 2); | 804 | /* Like a Session Init, the System Init behaviour is (now) to |
862 | 335 | /* XXX: Only the last instance of --confdir should be honoured. | 805 | * honour all --confdirs. |
858 | 336 | * | ||
859 | 337 | * This behaviour deviates from running as a Session Init where *all* | ||
860 | 338 | * --confdir's specified are used. | ||
863 | 339 | */ | 806 | */ |
866 | 340 | TEST_STR_MATCH (output[0], "baz stop/waiting"); | 807 | TEST_EQ (lines, 3); |
867 | 341 | TEST_STR_MATCH (output[1], "qux stop/waiting"); | 808 | |
868 | 809 | TEST_STR_MATCH (output[0], "bar stop/waiting"); | ||
869 | 810 | TEST_STR_MATCH (output[1], "baz stop/waiting"); | ||
870 | 811 | TEST_STR_MATCH (output[2], "qux stop/waiting"); | ||
871 | 342 | nih_free (output); | 812 | nih_free (output); |
872 | 343 | 813 | ||
873 | 344 | DELETE_FILE (xdg_conf_dir, "foo.conf"); | 814 | DELETE_FILE (xdg_conf_dir, "foo.conf"); |
874 | @@ -349,6 +819,96 @@ | |||
875 | 349 | STOP_UPSTART (upstart_pid); | 819 | STOP_UPSTART (upstart_pid); |
876 | 350 | 820 | ||
877 | 351 | /************************************************************/ | 821 | /************************************************************/ |
878 | 822 | TEST_FEATURE ("System Init with multiple --prepend-confdir"); | ||
879 | 823 | |||
880 | 824 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
881 | 825 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default2.conf")); | ||
882 | 826 | |||
883 | 827 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true"); | ||
884 | 828 | CREATE_FILE (confdir_b, "must-not-exist-by-default2.conf", "exec true"); | ||
885 | 829 | |||
886 | 830 | extra[0] = "--prepend-confdir"; | ||
887 | 831 | extra[1] = confdir_a; | ||
888 | 832 | extra[2] = "--prepend-confdir"; | ||
889 | 833 | extra[3] = confdir_b; | ||
890 | 834 | extra[4] = NULL; | ||
891 | 835 | |||
892 | 836 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
893 | 837 | |||
894 | 838 | /* Should be running */ | ||
895 | 839 | assert0 (kill (upstart_pid, 0)); | ||
896 | 840 | |||
897 | 841 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
898 | 842 | TEST_NE_P (cmd, NULL); | ||
899 | 843 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
900 | 844 | |||
901 | 845 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
902 | 846 | |||
903 | 847 | TEST_EQ (lines, 1); | ||
904 | 848 | TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting"); | ||
905 | 849 | nih_free (output); | ||
906 | 850 | |||
907 | 851 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default2"); | ||
908 | 852 | TEST_NE_P (cmd, NULL); | ||
909 | 853 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
910 | 854 | |||
911 | 855 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
912 | 856 | |||
913 | 857 | TEST_EQ (lines, 1); | ||
914 | 858 | TEST_STR_MATCH (output[0], "must-not-exist-by-default2 stop/waiting"); | ||
915 | 859 | nih_free (output); | ||
916 | 860 | |||
917 | 861 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
918 | 862 | DELETE_FILE (confdir_b, "must-not-exist-by-default2.conf"); | ||
919 | 863 | |||
920 | 864 | STOP_UPSTART (upstart_pid); | ||
921 | 865 | |||
922 | 866 | /************************************************************/ | ||
923 | 867 | TEST_FEATURE ("System Init with multiple --append-confdir"); | ||
924 | 868 | |||
925 | 869 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
926 | 870 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default2.conf")); | ||
927 | 871 | |||
928 | 872 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true"); | ||
929 | 873 | CREATE_FILE (confdir_b, "must-not-exist-by-default2.conf", "exec true"); | ||
930 | 874 | |||
931 | 875 | extra[0] = "--append-confdir"; | ||
932 | 876 | extra[1] = confdir_a; | ||
933 | 877 | extra[2] = "--append-confdir"; | ||
934 | 878 | extra[3] = confdir_b; | ||
935 | 879 | extra[4] = NULL; | ||
936 | 880 | |||
937 | 881 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
938 | 882 | |||
939 | 883 | /* Should be running */ | ||
940 | 884 | assert0 (kill (upstart_pid, 0)); | ||
941 | 885 | |||
942 | 886 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
943 | 887 | TEST_NE_P (cmd, NULL); | ||
944 | 888 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
945 | 889 | |||
946 | 890 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
947 | 891 | |||
948 | 892 | TEST_EQ (lines, 1); | ||
949 | 893 | TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting"); | ||
950 | 894 | nih_free (output); | ||
951 | 895 | |||
952 | 896 | cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default2"); | ||
953 | 897 | TEST_NE_P (cmd, NULL); | ||
954 | 898 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
955 | 899 | |||
956 | 900 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
957 | 901 | |||
958 | 902 | TEST_EQ (lines, 1); | ||
959 | 903 | TEST_STR_MATCH (output[0], "must-not-exist-by-default2 stop/waiting"); | ||
960 | 904 | nih_free (output); | ||
961 | 905 | |||
962 | 906 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
963 | 907 | DELETE_FILE (confdir_b, "must-not-exist-by-default2.conf"); | ||
964 | 908 | |||
965 | 909 | STOP_UPSTART (upstart_pid); | ||
966 | 910 | |||
967 | 911 | /************************************************************/ | ||
968 | 352 | TEST_FEATURE ("System Init with multiple --confdir and conflicting names"); | 912 | TEST_FEATURE ("System Init with multiple --confdir and conflicting names"); |
969 | 353 | 913 | ||
970 | 354 | assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1)); | 914 | assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1)); |
971 | @@ -363,6 +923,7 @@ | |||
972 | 363 | extra[3] = confdir_b; | 923 | extra[3] = confdir_b; |
973 | 364 | extra[4] = NULL; | 924 | extra[4] = NULL; |
974 | 365 | 925 | ||
975 | 926 | /* pass 2 confdir directories */ | ||
976 | 366 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | 927 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); |
977 | 367 | 928 | ||
978 | 368 | /* Should be running */ | 929 | /* Should be running */ |
979 | @@ -375,7 +936,6 @@ | |||
980 | 375 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | 936 | qsort (output, lines, sizeof (output[0]), strcmp_compar); |
981 | 376 | 937 | ||
982 | 377 | TEST_EQ (lines, 1); | 938 | TEST_EQ (lines, 1); |
983 | 378 | /* only the last instance of --confdir should be honoured */ | ||
984 | 379 | TEST_STR_MATCH (output[0], "conflict stop/waiting"); | 939 | TEST_STR_MATCH (output[0], "conflict stop/waiting"); |
985 | 380 | nih_free (output); | 940 | nih_free (output); |
986 | 381 | 941 | ||
987 | @@ -386,7 +946,7 @@ | |||
988 | 386 | /* Ensure the correct version of the conflict job is found */ | 946 | /* Ensure the correct version of the conflict job is found */ |
989 | 387 | TEST_EQ (lines, 2); | 947 | TEST_EQ (lines, 2); |
990 | 388 | TEST_STR_MATCH (output[0], "conflict"); | 948 | TEST_STR_MATCH (output[0], "conflict"); |
992 | 389 | TEST_STR_MATCH (output[1], " emits confdir_b"); | 949 | TEST_STR_MATCH (output[1], " emits confdir_a"); |
993 | 390 | nih_free (output); | 950 | nih_free (output); |
994 | 391 | 951 | ||
995 | 392 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); | 952 | DELETE_FILE (xdg_conf_dir, "conflict.conf"); |
996 | @@ -396,11 +956,171 @@ | |||
997 | 396 | STOP_UPSTART (upstart_pid); | 956 | STOP_UPSTART (upstart_pid); |
998 | 397 | 957 | ||
999 | 398 | /************************************************************/ | 958 | /************************************************************/ |
1000 | 959 | TEST_FEATURE ("System Init with multiple --prepend-confdir and conflicting names"); | ||
1001 | 960 | |||
1002 | 961 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
1003 | 962 | |||
1004 | 963 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "emits confdir_a"); | ||
1005 | 964 | CREATE_FILE (confdir_b, "must-not-exist-by-default.conf", "emits confdir_b"); | ||
1006 | 965 | |||
1007 | 966 | extra[0] = "--prepend-confdir"; | ||
1008 | 967 | extra[1] = confdir_a; | ||
1009 | 968 | extra[2] = "--prepend-confdir"; | ||
1010 | 969 | extra[3] = confdir_b; | ||
1011 | 970 | extra[4] = NULL; | ||
1012 | 971 | |||
1013 | 972 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
1014 | 973 | |||
1015 | 974 | /* Should be running */ | ||
1016 | 975 | assert0 (kill (upstart_pid, 0)); | ||
1017 | 976 | |||
1018 | 977 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
1019 | 978 | TEST_NE_P (cmd, NULL); | ||
1020 | 979 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1021 | 980 | |||
1022 | 981 | /* Ensure the correct version of the conflict job is found */ | ||
1023 | 982 | TEST_EQ (lines, 2); | ||
1024 | 983 | TEST_STR_MATCH (output[0], "must-not-exist-by-default"); | ||
1025 | 984 | TEST_STR_MATCH (output[1], " emits confdir_a"); | ||
1026 | 985 | nih_free (output); | ||
1027 | 986 | |||
1028 | 987 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
1029 | 988 | DELETE_FILE (confdir_b, "must-not-exist-by-default.conf"); | ||
1030 | 989 | |||
1031 | 990 | STOP_UPSTART (upstart_pid); | ||
1032 | 991 | |||
1033 | 992 | /************************************************************/ | ||
1034 | 993 | TEST_FEATURE ("System Init with multiple --append-confdir and conflicting names"); | ||
1035 | 994 | |||
1036 | 995 | TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf")); | ||
1037 | 996 | |||
1038 | 997 | CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "emits confdir_a"); | ||
1039 | 998 | CREATE_FILE (confdir_b, "must-not-exist-by-default.conf", "emits confdir_b"); | ||
1040 | 999 | |||
1041 | 1000 | extra[0] = "--append-confdir"; | ||
1042 | 1001 | extra[1] = confdir_a; | ||
1043 | 1002 | extra[2] = "--append-confdir"; | ||
1044 | 1003 | extra[3] = confdir_b; | ||
1045 | 1004 | extra[4] = NULL; | ||
1046 | 1005 | |||
1047 | 1006 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
1048 | 1007 | |||
1049 | 1008 | /* Should be running */ | ||
1050 | 1009 | assert0 (kill (upstart_pid, 0)); | ||
1051 | 1010 | |||
1052 | 1011 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "must-not-exist-by-default"); | ||
1053 | 1012 | TEST_NE_P (cmd, NULL); | ||
1054 | 1013 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1055 | 1014 | |||
1056 | 1015 | /* Ensure the correct version of the conflict job is found */ | ||
1057 | 1016 | TEST_EQ (lines, 2); | ||
1058 | 1017 | TEST_STR_MATCH (output[0], "must-not-exist-by-default"); | ||
1059 | 1018 | TEST_STR_MATCH (output[1], " emits confdir_a"); | ||
1060 | 1019 | nih_free (output); | ||
1061 | 1020 | |||
1062 | 1021 | DELETE_FILE (confdir_a, "must-not-exist-by-default.conf"); | ||
1063 | 1022 | DELETE_FILE (confdir_b, "must-not-exist-by-default.conf"); | ||
1064 | 1023 | |||
1065 | 1024 | STOP_UPSTART (upstart_pid); | ||
1066 | 1025 | |||
1067 | 1026 | /************************************************************/ | ||
1068 | 1027 | TEST_FEATURE ("System Init with multiple out of order --confdir, --prepend-confdir and --append-confdir"); | ||
1069 | 1028 | |||
1070 | 1029 | CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a"); | ||
1071 | 1030 | CREATE_FILE (confdir_a, "wibble.conf", "emits wobble"); | ||
1072 | 1031 | CREATE_FILE (confdir_b, "conflict.conf", "emits confdir_b"); | ||
1073 | 1032 | CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c"); | ||
1074 | 1033 | CREATE_FILE (confdir_d, "foo.conf", "emits hello"); | ||
1075 | 1034 | CREATE_FILE (confdir_e, "bar.conf", "emits world"); | ||
1076 | 1035 | CREATE_FILE (confdir_e, "conflict.conf", "emits confdir_e"); | ||
1077 | 1036 | CREATE_FILE (confdir_f, "conflict.conf", "emits confdir_f"); | ||
1078 | 1037 | CREATE_FILE (confdir_f, "baz.conf", "exec true"); | ||
1079 | 1038 | |||
1080 | 1039 | extra[0] = "--append-confdir"; | ||
1081 | 1040 | extra[1] = confdir_a; | ||
1082 | 1041 | extra[2] = "--prepend-confdir"; | ||
1083 | 1042 | extra[3] = confdir_e; | ||
1084 | 1043 | extra[4] = "--confdir"; | ||
1085 | 1044 | extra[5] = confdir_b; | ||
1086 | 1045 | extra[6] = "--append-confdir"; | ||
1087 | 1046 | extra[7] = confdir_f; | ||
1088 | 1047 | extra[8] = "--confdir"; | ||
1089 | 1048 | extra[9] = confdir_c; | ||
1090 | 1049 | extra[10] = "--prepend-confdir"; | ||
1091 | 1050 | extra[11] = confdir_d; | ||
1092 | 1051 | extra[12] = NULL; | ||
1093 | 1052 | |||
1094 | 1053 | start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra); | ||
1095 | 1054 | |||
1096 | 1055 | /* Should be running */ | ||
1097 | 1056 | assert0 (kill (upstart_pid, 0)); | ||
1098 | 1057 | |||
1099 | 1058 | cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ()); | ||
1100 | 1059 | TEST_NE_P (cmd, NULL); | ||
1101 | 1060 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1102 | 1061 | |||
1103 | 1062 | qsort (output, lines, sizeof (output[0]), strcmp_compar); | ||
1104 | 1063 | |||
1105 | 1064 | TEST_EQ (lines, 5); | ||
1106 | 1065 | TEST_STR_MATCH (output[0], "bar stop/waiting"); | ||
1107 | 1066 | TEST_STR_MATCH (output[1], "baz stop/waiting"); | ||
1108 | 1067 | TEST_STR_MATCH (output[2], "conflict stop/waiting"); | ||
1109 | 1068 | TEST_STR_MATCH (output[3], "foo stop/waiting"); | ||
1110 | 1069 | TEST_STR_MATCH (output[4], "wibble stop/waiting"); | ||
1111 | 1070 | nih_free (output); | ||
1112 | 1071 | |||
1113 | 1072 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict"); | ||
1114 | 1073 | TEST_NE_P (cmd, NULL); | ||
1115 | 1074 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1116 | 1075 | TEST_EQ (lines, 2); | ||
1117 | 1076 | TEST_STR_MATCH (output[0], "conflict"); | ||
1118 | 1077 | TEST_STR_MATCH (output[1], " emits confdir_e"); | ||
1119 | 1078 | nih_free (output); | ||
1120 | 1079 | |||
1121 | 1080 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "wibble"); | ||
1122 | 1081 | TEST_NE_P (cmd, NULL); | ||
1123 | 1082 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1124 | 1083 | TEST_EQ (lines, 2); | ||
1125 | 1084 | TEST_STR_MATCH (output[0], "wibble"); | ||
1126 | 1085 | TEST_STR_MATCH (output[1], " emits wobble"); | ||
1127 | 1086 | nih_free (output); | ||
1128 | 1087 | |||
1129 | 1088 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "foo"); | ||
1130 | 1089 | TEST_NE_P (cmd, NULL); | ||
1131 | 1090 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1132 | 1091 | TEST_EQ (lines, 2); | ||
1133 | 1092 | TEST_STR_MATCH (output[0], "foo"); | ||
1134 | 1093 | TEST_STR_MATCH (output[1], " emits hello"); | ||
1135 | 1094 | nih_free (output); | ||
1136 | 1095 | |||
1137 | 1096 | cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "bar"); | ||
1138 | 1097 | TEST_NE_P (cmd, NULL); | ||
1139 | 1098 | RUN_COMMAND (NULL, cmd, &output, &lines); | ||
1140 | 1099 | TEST_EQ (lines, 2); | ||
1141 | 1100 | TEST_STR_MATCH (output[0], "bar"); | ||
1142 | 1101 | TEST_STR_MATCH (output[1], " emits world"); | ||
1143 | 1102 | nih_free (output); | ||
1144 | 1103 | |||
1145 | 1104 | DELETE_FILE (confdir_a, "conflict.conf"); | ||
1146 | 1105 | DELETE_FILE (confdir_a, "wibble.conf"); | ||
1147 | 1106 | DELETE_FILE (confdir_b, "conflict.conf"); | ||
1148 | 1107 | DELETE_FILE (confdir_c, "conflict.conf"); | ||
1149 | 1108 | DELETE_FILE (confdir_d, "foo.conf"); | ||
1150 | 1109 | DELETE_FILE (confdir_e, "bar.conf"); | ||
1151 | 1110 | DELETE_FILE (confdir_e, "conflict.conf"); | ||
1152 | 1111 | DELETE_FILE (confdir_f, "conflict.conf"); | ||
1153 | 1112 | DELETE_FILE (confdir_f, "baz.conf"); | ||
1154 | 1113 | |||
1155 | 1114 | STOP_UPSTART (upstart_pid); | ||
1156 | 399 | 1115 | ||
1157 | 400 | TEST_DBUS_END (dbus_pid); | 1116 | TEST_DBUS_END (dbus_pid); |
1158 | 401 | 1117 | ||
1159 | 402 | assert0 (rmdir (confdir_a)); | 1118 | assert0 (rmdir (confdir_a)); |
1160 | 403 | assert0 (rmdir (confdir_b)); | 1119 | assert0 (rmdir (confdir_b)); |
1161 | 1120 | assert0 (rmdir (confdir_c)); | ||
1162 | 1121 | assert0 (rmdir (confdir_d)); | ||
1163 | 1122 | assert0 (rmdir (confdir_e)); | ||
1164 | 1123 | assert0 (rmdir (confdir_f)); | ||
1165 | 404 | assert0 (rmdir (xdg_conf_dir)); | 1124 | assert0 (rmdir (xdg_conf_dir)); |
1166 | 405 | assert0 (rmdir (logdir)); | 1125 | assert0 (rmdir (logdir)); |
1167 | 406 | assert0 (unsetenv ("UPSTART_CONFDIR")); | 1126 | assert0 (unsetenv ("UPSTART_CONFDIR")); |
As implemented here: if i place foo.conf in both --confdir /etc/init --append-confdir /usr/share/ upstart/ system, the /etc/init/foo.conf will win.
Which I interpret to be opposite of "append" as in last one wins / "Last In First Out", and opposite of what was requested:
""
As for session jobs, I assume we can just set /custom as an XDG_CONFIG_DIR, and have /custom/upstart with jobs there.
""
In session init if foo.conf exists in both /usr/share/ upstart/ session and XDG_CONFIG_ DIR/upstart, the "override" location XDG_CONFIG_ DIR/upstart/ foo.conf wins.