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

Proposed by James Hunt
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
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Approve
Review via email: mp+218953@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

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.

Revision history for this message
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

Revision history for this message
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.

Revision history for this message
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://wiki.ubuntu.com/FoundationsTeam/Specs/RaringUpstartUserSessions#init-checkconf

... 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.

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

Branch updated to also support '--prepend-confdir'. Let's add init-checkconf sugar once this is merged.

lp:~jamesodhunt/upstart/bug-1315060 updated
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.

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
=== modified file 'ChangeLog'
--- ChangeLog 2014-05-09 15:23:36 +0000
+++ ChangeLog 2014-06-04 15:39:46 +0000
@@ -1,3 +1,18 @@
12014-05-21 James Hunt <james.hunt@ubuntu.com>
2
3 * init/main.c: Add support for '--prepend-confdir'.
4 * init/man/init.8: Add '--prepend-confdir'.
5 * init/tests/test_main.c: Add tests for '--prepend-confdir'.
6
72014-05-09 James Hunt <james.hunt@ubuntu.com>
8
9 * init/main.c: add '--append-confdir' command-line option (LP: #1315060).
10 * init/man/init.8:
11 - Document '--append-confdir'.
12 - Add init(5) reference for '--confdir'.
13 * init/tests/test_main.c: New Session and System init tests for
14 '--append-confdir'.
15
12014-05-09 Dimitri John Ledkov <xnox@ubuntu.com>162014-05-09 Dimitri John Ledkov <xnox@ubuntu.com>
217
3 * util/reboot.c: only use rebootcommand code path in runlevels 0,18 * util/reboot.c: only use rebootcommand code path in runlevels 0,
@@ -11,6 +26,15 @@
11 * Convert calls to deprecated json_object_object_get() to26 * Convert calls to deprecated json_object_object_get() to
12 json_object_object_get_ex().27 json_object_object_get_ex().
1328
292014-05-02 James Hunt <james.hunt@ubuntu.com>
30
31 * init/main.c: main(): Allow System Init read from multiple
32 configuration to directories like a Session Init (LP: #1315060).
33 * init/man/init.5: Clarify default directory.
34 * init/man/init.8: Explain new behaviour.
35 * init/tests/test_main.c: test_confdir(): Update tests for new
36 '--confdir' behaviour of System init.
37
142014-04-24 James Hunt <james.hunt@ubuntu.com>382014-04-24 James Hunt <james.hunt@ubuntu.com>
1539
16 * init/man/init.5:40 * init/man/init.5:
1741
=== modified file 'init/main.c'
--- init/main.c 2014-04-11 21:15:39 +0000
+++ init/main.c 2014-06-04 15:39:46 +0000
@@ -1,6 +1,6 @@
1/* upstart1/* upstart
2 *2 *
3 * Copyright © 2009-2011 Canonical Ltd.3 * Copyright 2009-2011 Canonical Ltd.
4 * Author: Scott James Remnant <scott@netsplit.com>.4 * Author: Scott James Remnant <scott@netsplit.com>.
5 *5 *
6 * This program is free software; you can redistribute it and/or modify6 * This program is free software; you can redistribute it and/or modify
@@ -85,10 +85,12 @@
85static void usr1_handler (void *data, NihSignal *signal);85static void usr1_handler (void *data, NihSignal *signal);
86#endif /* DEBUG */86#endif /* DEBUG */
8787
88static void handle_confdir (void);88static void handle_confdir (void);
89static void handle_logdir (void);89static void handle_logdir (void);
90static int console_type_setter (NihOption *option, const char *arg);90static int console_type_setter (NihOption *option, const char *arg);
91static int conf_dir_setter (NihOption *option, const char *arg);91static int conf_dir_setter (NihOption *option, const char *arg);
92static int prepend_conf_dir_setter (NihOption *option, const char *arg);
93static int append_conf_dir_setter (NihOption *option, const char *arg);
9294
9395
94/**96/**
@@ -107,6 +109,22 @@
107static char **conf_dirs = NULL;109static char **conf_dirs = NULL;
108110
109/**111/**
112 * prepend_conf_dirs:
113 *
114 * Array of full paths to job configuration file directories that will
115 * be added to before the other values in conf_dirs.
116 **/
117static char **prepend_conf_dirs = NULL;
118
119/**
120 * append_conf_dirs:
121 *
122 * Array of full paths to job configuration file directories that will
123 * be added to conf_dirs.
124 **/
125static char **append_conf_dirs = NULL;
126
127/**
110 * initial_event:128 * initial_event:
111 *129 *
112 * Alternate event to emit at startup (rather than STARTUP_EVENT).130 * Alternate event to emit at startup (rather than STARTUP_EVENT).
@@ -146,30 +164,36 @@
146 * Command-line options we accept.164 * Command-line options we accept.
147 **/165 **/
148static NihOption options[] = {166static NihOption options[] = {
167 { 0, "append-confdir", N_("specify additional directory to load configuration files from"),
168 NULL, "DIR", NULL, append_conf_dir_setter },
169
170 { 0, "chroot-sessions", N_("enable chroot sessions"),
171 NULL, NULL, &chroot_sessions, NULL },
172
149 { 0, "confdir", N_("specify alternative directory to load configuration files from"),173 { 0, "confdir", N_("specify alternative directory to load configuration files from"),
150 NULL, "DIR", NULL, conf_dir_setter },174 NULL, "DIR", NULL, conf_dir_setter },
151175
152 { 0, "default-console", N_("default value for console stanza"),176 { 0, "default-console", N_("default value for console stanza"),
153 NULL, "VALUE", NULL, console_type_setter },177 NULL, "VALUE", NULL, console_type_setter },
154178
179 { 0, "logdir", N_("specify alternative directory to store job output logs in"),
180 NULL, "DIR", &log_dir, NULL },
181
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"),
156 NULL, NULL, &disable_dbus, NULL },183 NULL, NULL, &disable_dbus, NULL },
157184
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"),
159 NULL, NULL, &no_inherit_env , NULL },186 NULL, NULL, &no_inherit_env , NULL },
160187
161 { 0, "logdir", N_("specify alternative directory to store job output logs in"),
162 NULL, "DIR", &log_dir, NULL },
163
164 { 0, "no-log", N_("disable job logging"),188 { 0, "no-log", N_("disable job logging"),
165 NULL, NULL, &disable_job_logging, NULL },189 NULL, NULL, &disable_job_logging, NULL },
166190
167 { 0, "chroot-sessions", N_("enable chroot sessions"),
168 NULL, NULL, &chroot_sessions, NULL },
169
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)"),
171 NULL, NULL, &disable_startup_event, NULL },192 NULL, NULL, &disable_startup_event, NULL },
172193
194 { 0, "prepend-confdir", N_("specify additional initial directory to load configuration files from"),
195 NULL, "DIR", NULL, prepend_conf_dir_setter },
196
173 /* Must be specified for both stateful and stateless re-exec */197 /* Must be specified for both stateful and stateless re-exec */
174 { 0, "restart", N_("flag a re-exec has occurred"),198 { 0, "restart", N_("flag a re-exec has occurred"),
175 NULL, NULL, &restart, NULL },199 NULL, NULL, &restart, NULL },
@@ -205,6 +229,8 @@
205 int ret;229 int ret;
206230
207 conf_dirs = NIH_MUST (nih_str_array_new (NULL));231 conf_dirs = NIH_MUST (nih_str_array_new (NULL));
232 append_conf_dirs = NIH_MUST (nih_str_array_new (NULL));
233 prepend_conf_dirs = NIH_MUST (nih_str_array_new (NULL));
208234
209 args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv));235 args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv));
210236
@@ -567,25 +593,22 @@
567 }593 }
568594
569 /* Read configuration */595 /* Read configuration */
596 if (prepend_conf_dirs[0]) {
597 for (char **d = prepend_conf_dirs; d && *d; d++) {
598 nih_debug ("Prepending configuration directory %s", *d);
599 NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR));
600 }
601 }
602
570 if (! user_mode) {603 if (! user_mode) {
571 char *conf_dir;
572 int len = 0;
573
574 nih_assert (conf_dirs[0]);604 nih_assert (conf_dirs[0]);
575605
576 /* Count entries */
577 for (char **d = conf_dirs; d && *d; d++, len++)
578 ;
579
580 nih_assert (len);
581
582 /* Use last value specified */
583 conf_dir = conf_dirs[len-1];
584
585 NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));606 NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));
586607
587 nih_debug ("Using configuration directory %s", conf_dir);608 for (char **d = conf_dirs; d && *d; d++) {
588 NIH_MUST (conf_source_new (NULL, conf_dir, CONF_JOB_DIR));609 nih_debug ("Using configuration directory %s", *d);
610 NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR));
611 }
589 } else {612 } else {
590 nih_local char **dirs = NULL;613 nih_local char **dirs = NULL;
591614
@@ -597,7 +620,16 @@
597 }620 }
598 }621 }
599622
623 if (append_conf_dirs[0]) {
624 for (char **d = append_conf_dirs; d && *d; d++) {
625 nih_debug ("Adding configuration directory %s", *d);
626 NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR));
627 }
628 }
629
600 nih_free (conf_dirs);630 nih_free (conf_dirs);
631 nih_free (prepend_conf_dirs);
632 nih_free (append_conf_dirs);
601633
602 job_class_environment_init ();634 job_class_environment_init ();
603635
@@ -1105,3 +1137,37 @@
11051137
1106 return 0;1138 return 0;
1107}1139}
1140
1141/**
1142 * NihOption setter function to handle selection of configuration file
1143 * directories.
1144 *
1145 * Returns: 0 on success, -1 on invalid console type.
1146 **/
1147static int
1148prepend_conf_dir_setter (NihOption *option, const char *arg)
1149{
1150 nih_assert (prepend_conf_dirs);
1151 nih_assert (option);
1152
1153 NIH_MUST (nih_str_array_add (&prepend_conf_dirs, NULL, NULL, arg));
1154
1155 return 0;
1156}
1157
1158/**
1159 * NihOption setter function to handle selection of configuration file
1160 * directories.
1161 *
1162 * Returns: 0 on success, -1 on invalid console type.
1163 **/
1164static int
1165append_conf_dir_setter (NihOption *option, const char *arg)
1166{
1167 nih_assert (append_conf_dirs);
1168 nih_assert (option);
1169
1170 NIH_MUST (nih_str_array_add (&append_conf_dirs, NULL, NULL, arg));
1171
1172 return 0;
1173}
11081174
=== modified file 'init/man/init.5'
--- init/man/init.5 2014-04-24 12:39:18 +0000
+++ init/man/init.5 2014-06-04 15:39:46 +0000
@@ -22,7 +22,7 @@
22.BR init (8)22.BR init (8)
23daemon reads its job configuration from files in the23daemon reads its job configuration from files in the
24.I /etc/init/24.I /etc/init/
25directory, and watches for future changes to these files using25directory by default, and watches for future changes to these files using
26.BR inotify (7).26.BR inotify (7).
2727
28If Upstart was invoked as a user process with \-\-user option, it will28If Upstart was invoked as a user process with \-\-user option, it will
2929
=== modified file 'init/man/init.8'
--- init/man/init.8 2013-12-23 17:31:22 +0000
+++ init/man/init.8 2014-06-04 15:39:46 +0000
@@ -253,14 +253,41 @@
253by placing them on the kernel command-line.253by placing them on the kernel command-line.
254.\"254.\"
255.TP255.TP
256.B \-\-append-confdir \fIdirectory\fP
257Add the specified directory to the default directory or directories
258that job configuration files will be read from. This option may be
259specified multiple times which will result in job configuration files
260being loaded from each directory specified (which must exist).
261Directories will be searched for jobs in the specified order after the
262default directories have been searched.
263
264Note that if this option is used in combination with
265.BR \-\-confdir ","
266or
267.BR \-\-prepend\-confdir ","
268regardless of the order of the options on the command-line, the append
269directories will be added
270.I after
271the other directories.
272.\"
273.TP
256.B \-\-confdir \fIdirectory\fP274.B \-\-confdir \fIdirectory\fP
257Read job configuration files from a directory other than the default275Read job configuration files from a directory other than the default
258(\fI/etc/init\fP for process ID 1).276(\fI/etc/init\fP for process ID 1). This option may be specified
259277multiple times which will result in job configuration files being
260When running as process ID 1, the last directory specified will be used.278loaded from each directory specified (which must exist). Directories
261279will be searched for jobs in the specified order.
262In user session mode, multiple directories will be honoured and job280
263configuration files loaded from the directories in the order specified.281In the case that multiple directories specify a job of the same name,
282the first job encountered will be honoured.
283
284See section
285.B User Session Mode
286in
287.BR init (5)
288for the ordered list of default configuration directories a
289Session Init will consider.
290
264.\"291.\"
265.TP292.TP
266.B \-\-default-console \fIvalue\fP293.B \-\-default-console \fIvalue\fP
@@ -308,6 +335,24 @@
308daemon from starting \fBany\fP jobs automatically.335daemon from starting \fBany\fP jobs automatically.
309.\"336.\"
310.TP337.TP
338.B \-\-prepend-confdir \fIdirectory\fP
339Add the specified directory to the directory or directories
340that job configuration files will be read from. This option may be
341specified multiple times which will result in job configuration files
342being loaded from each directory specified (which must exist).
343Directories will be searched for jobs in the specified order before the
344default directories have been searched.
345
346Note that if this option is used in combination with
347.BR \-\-confdir ","
348or
349.BR \-\-append\-confdir ","
350regardless of the order of the options on the command-line, the prepend
351directories will be added
352.I before
353the other directories.
354.\"
355.TP
311.B \-\-session356.B \-\-session
312Connect to the D\-Bus session bus. This should only be used for testing.357Connect to the D\-Bus session bus. This should only be used for testing.
313.\"358.\"
314359
=== modified file 'init/tests/test_main.c'
--- init/tests/test_main.c 2013-11-12 12:17:30 +0000
+++ init/tests/test_main.c 2014-06-04 15:39:46 +0000
@@ -46,6 +46,10 @@
46{46{
47 char confdir_a[PATH_MAX];47 char confdir_a[PATH_MAX];
48 char confdir_b[PATH_MAX];48 char confdir_b[PATH_MAX];
49 char confdir_c[PATH_MAX];
50 char confdir_d[PATH_MAX];
51 char confdir_e[PATH_MAX];
52 char confdir_f[PATH_MAX];
49 char *xdg_config_home;53 char *xdg_config_home;
50 char *xdg_runtime_dir;54 char *xdg_runtime_dir;
51 char logdir[PATH_MAX];55 char logdir[PATH_MAX];
@@ -58,8 +62,10 @@
58 nih_local char *session_file = NULL;62 nih_local char *session_file = NULL;
59 nih_local char *path = NULL;63 nih_local char *path = NULL;
6064
61 /* space for 2 sets of confdir options and a terminator */65 /* space for 2 sets of confdir options, 2 sets of
62 char *extra[5];66 * prepend-confdir, 2 sets of append-confdirs and a terminator.
67 */
68 char *extra[13];
6369
64 xdg_config_home = getenv ("XDG_CONFIG_HOME");70 xdg_config_home = getenv ("XDG_CONFIG_HOME");
65 TEST_NE_P (xdg_config_home, NULL);71 TEST_NE_P (xdg_config_home, NULL);
@@ -75,6 +81,18 @@
75 TEST_FILENAME (confdir_b);81 TEST_FILENAME (confdir_b);
76 assert0 (mkdir (confdir_b, 0755));82 assert0 (mkdir (confdir_b, 0755));
7783
84 TEST_FILENAME (confdir_c);
85 assert0 (mkdir (confdir_c, 0755));
86
87 TEST_FILENAME (confdir_d);
88 assert0 (mkdir (confdir_d, 0755));
89
90 TEST_FILENAME (confdir_e);
91 assert0 (mkdir (confdir_e, 0755));
92
93 TEST_FILENAME (confdir_f);
94 assert0 (mkdir (confdir_f, 0755));
95
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");
79 TEST_NE_P (xdg_conf_dir, NULL);97 TEST_NE_P (xdg_conf_dir, NULL);
80 assert0 (mkdir (xdg_conf_dir, 0755));98 assert0 (mkdir (xdg_conf_dir, 0755));
@@ -151,6 +169,89 @@
151 assert0 (unlink (session_file));169 assert0 (unlink (session_file));
152170
153 /************************************************************/171 /************************************************************/
172 TEST_FEATURE ("Session Init with --prepend-confdir");
173
174 CREATE_FILE (confdir_a, "foo.conf", "exec foo");
175 CREATE_FILE (confdir_a, "conflict.conf", "emits prepend");
176 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits confdir");
177 CREATE_FILE (xdg_conf_dir, "baz.conf", "exec baz");
178
179 extra[0] = "--prepend-confdir";
180 extra[1] = confdir_a;
181 extra[2] = NULL;
182
183 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
184
185 /* Should be running */
186 assert0 (kill (upstart_pid, 0));
187
188 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
189
190 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
191 TEST_NE_P (cmd, NULL);
192 RUN_COMMAND (NULL, cmd, &output, &lines);
193
194 qsort (output, lines, sizeof (output[0]), strcmp_compar);
195
196 TEST_EQ (lines, 3);
197 TEST_STR_MATCH (output[0], "baz stop/waiting");
198 TEST_STR_MATCH (output[1], "conflict stop/waiting");
199 TEST_STR_MATCH (output[2], "foo stop/waiting");
200 nih_free (output);
201
202 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
203 TEST_NE_P (cmd, NULL);
204 RUN_COMMAND (NULL, cmd, &output, &lines);
205
206 TEST_EQ (lines, 2);
207 TEST_STR_MATCH (output[0], "conflict");
208 TEST_STR_MATCH (output[1], " emits prepend");
209 nih_free (output);
210
211 DELETE_FILE (confdir_a, "foo.conf");
212 DELETE_FILE (confdir_a, "conflict.conf");
213 DELETE_FILE (xdg_conf_dir, "conflict.conf");
214 DELETE_FILE (xdg_conf_dir, "baz.conf");
215
216 STOP_UPSTART (upstart_pid);
217 assert0 (unlink (session_file));
218
219 /************************************************************/
220 TEST_FEATURE ("Session Init with --append-confdir");
221
222 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");
223 CREATE_FILE (confdir_a, "conf_dir_job.conf", "exec true");
224
225 extra[0] = "--append-confdir";
226 extra[1] = confdir_a;
227 extra[2] = NULL;
228
229 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
230
231 /* Should be running */
232 assert0 (kill (upstart_pid, 0));
233
234 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
235
236 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
237 TEST_NE_P (cmd, NULL);
238 RUN_COMMAND (NULL, cmd, &output, &lines);
239
240 qsort (output, lines, sizeof (output[0]), strcmp_compar);
241
242 /* jobs in xdg_conf_dir should be considered */
243 TEST_EQ (lines, 2);
244 TEST_STR_MATCH (output[0], "conf_dir_job stop/waiting");
245 TEST_STR_MATCH (output[1], "xdg_dir_job stop/waiting");
246 nih_free (output);
247
248 DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf");
249 DELETE_FILE (confdir_a, "conf_dir_job.conf");
250
251 STOP_UPSTART (upstart_pid);
252 assert0 (unlink (session_file));
253
254 /************************************************************/
154 TEST_FEATURE ("Session Init with multiple --confdir");255 TEST_FEATURE ("Session Init with multiple --confdir");
155256
156 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");257 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");
@@ -191,6 +292,88 @@
191 assert0 (unlink (session_file));292 assert0 (unlink (session_file));
192293
193 /************************************************************/294 /************************************************************/
295 TEST_FEATURE ("Session Init with multiple --prepend-confdir");
296
297 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");
298 CREATE_FILE (confdir_a, "conf_dir_a_job.conf", "exec true");
299 CREATE_FILE (confdir_b, "conf_dir_b_job.conf", "exec true");
300
301 extra[0] = "--prepend-confdir";
302 extra[1] = confdir_a;
303 extra[2] = "--prepend-confdir";
304 extra[3] = confdir_b;
305 extra[4] = NULL;
306
307 /* pass 2 confdir directories */
308 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
309
310 /* Should be running */
311 assert0 (kill (upstart_pid, 0));
312
313 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
314
315 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
316 TEST_NE_P (cmd, NULL);
317 RUN_COMMAND (NULL, cmd, &output, &lines);
318
319 qsort (output, lines, sizeof (output[0]), strcmp_compar);
320
321 /* jobs in xdg_conf_dir should be considered */
322 TEST_EQ (lines, 3);
323 TEST_STR_MATCH (output[0], "conf_dir_a_job stop/waiting");
324 TEST_STR_MATCH (output[1], "conf_dir_b_job stop/waiting");
325 TEST_STR_MATCH (output[2], "xdg_dir_job stop/waiting");
326 nih_free (output);
327
328 DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf");
329 DELETE_FILE (confdir_a, "conf_dir_a_job.conf");
330 DELETE_FILE (confdir_b, "conf_dir_b_job.conf");
331
332 STOP_UPSTART (upstart_pid);
333 assert0 (unlink (session_file));
334
335 /************************************************************/
336 TEST_FEATURE ("Session Init with multiple --append-confdir");
337
338 CREATE_FILE (xdg_conf_dir, "xdg_dir_job.conf", "exec true");
339 CREATE_FILE (confdir_a, "conf_dir_a_job.conf", "exec true");
340 CREATE_FILE (confdir_b, "conf_dir_b_job.conf", "exec true");
341
342 extra[0] = "--append-confdir";
343 extra[1] = confdir_a;
344 extra[2] = "--append-confdir";
345 extra[3] = confdir_b;
346 extra[4] = NULL;
347
348 /* pass 2 confdir directories */
349 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
350
351 /* Should be running */
352 assert0 (kill (upstart_pid, 0));
353
354 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
355
356 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
357 TEST_NE_P (cmd, NULL);
358 RUN_COMMAND (NULL, cmd, &output, &lines);
359
360 qsort (output, lines, sizeof (output[0]), strcmp_compar);
361
362 /* jobs in xdg_conf_dir should be considered */
363 TEST_EQ (lines, 3);
364 TEST_STR_MATCH (output[0], "conf_dir_a_job stop/waiting");
365 TEST_STR_MATCH (output[1], "conf_dir_b_job stop/waiting");
366 TEST_STR_MATCH (output[2], "xdg_dir_job stop/waiting");
367 nih_free (output);
368
369 DELETE_FILE (xdg_conf_dir, "xdg_dir_job.conf");
370 DELETE_FILE (confdir_a, "conf_dir_a_job.conf");
371 DELETE_FILE (confdir_b, "conf_dir_b_job.conf");
372
373 STOP_UPSTART (upstart_pid);
374 assert0 (unlink (session_file));
375
376 /************************************************************/
194 TEST_FEATURE ("Session Init with multiple --confdir and conflicting names");377 TEST_FEATURE ("Session Init with multiple --confdir and conflicting names");
195378
196 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");379 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");
@@ -241,6 +424,233 @@
241 assert0 (unlink (session_file));424 assert0 (unlink (session_file));
242425
243 /************************************************************/426 /************************************************************/
427 TEST_FEATURE ("Session Init with multiple --prepend-confdir and conflicting names");
428
429 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");
430 CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a");
431 CREATE_FILE (confdir_b, "foo.conf", "exec true");
432
433 extra[0] = "--prepend-confdir";
434 extra[1] = confdir_a;
435 extra[2] = "--prepend-confdir";
436 extra[3] = confdir_b;
437 extra[4] = NULL;
438
439 /* pass 2 confdir directories */
440 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
441
442 /* Should be running */
443 assert0 (kill (upstart_pid, 0));
444
445 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
446
447 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
448 TEST_NE_P (cmd, NULL);
449 RUN_COMMAND (NULL, cmd, &output, &lines);
450
451 qsort (output, lines, sizeof (output[0]), strcmp_compar);
452
453 /* We expect jobs in xdg_conf_dir to be ignored */
454 TEST_EQ (lines, 2);
455 TEST_STR_MATCH (output[0], "conflict stop/waiting");
456 TEST_STR_MATCH (output[1], "foo stop/waiting");
457 nih_free (output);
458
459 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
460 TEST_NE_P (cmd, NULL);
461 RUN_COMMAND (NULL, cmd, &output, &lines);
462
463 /* Ensure the correct version of the conflict job is found */
464 TEST_EQ (lines, 2);
465 TEST_STR_MATCH (output[0], "conflict");
466 TEST_STR_MATCH (output[1], " emits confdir_a");
467 nih_free (output);
468
469 DELETE_FILE (xdg_conf_dir, "conflict.conf");
470 DELETE_FILE (confdir_a, "conflict.conf");
471 DELETE_FILE (confdir_b, "foo.conf");
472
473 STOP_UPSTART (upstart_pid);
474 assert0 (unlink (session_file));
475
476 /************************************************************/
477 TEST_FEATURE ("Session Init with multiple --append-confdir and conflicting names");
478
479 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");
480 CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a");
481 CREATE_FILE (confdir_b, "foo.conf", "exec true");
482
483 extra[0] = "--append-confdir";
484 extra[1] = confdir_a;
485 extra[2] = "--append-confdir";
486 extra[3] = confdir_b;
487 extra[4] = NULL;
488
489 /* pass 2 confdir directories */
490 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
491
492 /* Should be running */
493 assert0 (kill (upstart_pid, 0));
494
495 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
496
497 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
498 TEST_NE_P (cmd, NULL);
499 RUN_COMMAND (NULL, cmd, &output, &lines);
500
501 qsort (output, lines, sizeof (output[0]), strcmp_compar);
502
503 /* We expect jobs in xdg_conf_dir to be ignored */
504 TEST_EQ (lines, 2);
505 TEST_STR_MATCH (output[0], "conflict stop/waiting");
506 TEST_STR_MATCH (output[1], "foo stop/waiting");
507 nih_free (output);
508
509 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
510 TEST_NE_P (cmd, NULL);
511 RUN_COMMAND (NULL, cmd, &output, &lines);
512
513 /* Ensure the correct version of the conflict job is found */
514 TEST_EQ (lines, 2);
515 TEST_STR_MATCH (output[0], "conflict");
516 TEST_STR_MATCH (output[1], " emits xdg_conf_dir");
517 nih_free (output);
518
519 DELETE_FILE (xdg_conf_dir, "conflict.conf");
520 DELETE_FILE (confdir_a, "conflict.conf");
521 DELETE_FILE (confdir_b, "foo.conf");
522
523 STOP_UPSTART (upstart_pid);
524 assert0 (unlink (session_file));
525
526 /************************************************************/
527 TEST_FEATURE ("Session Init with multiple --confdir, --prepend-confdir and --append-confdir with conflicting names");
528
529 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");
530 CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a");
531 CREATE_FILE (confdir_b, "foo.conf", "exec true");
532 CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c");
533 CREATE_FILE (confdir_d, "conflict.conf", "emits confdir_d");
534 CREATE_FILE (confdir_e, "bar.conf", "exec false");
535
536 extra[0] = "--prepend-confdir";
537 extra[1] = confdir_d;
538 extra[2] = "--prepend-confdir";
539 extra[3] = confdir_e;
540 extra[4] = "--confdir";
541 extra[5] = confdir_a;
542 extra[6] = "--confdir";
543 extra[7] = confdir_b;
544 extra[8] = "--append-confdir";
545 extra[9] = confdir_c;
546 extra[10] = NULL;
547
548 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
549
550 /* Should be running */
551 assert0 (kill (upstart_pid, 0));
552
553 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
554
555 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
556 TEST_NE_P (cmd, NULL);
557 RUN_COMMAND (NULL, cmd, &output, &lines);
558
559 qsort (output, lines, sizeof (output[0]), strcmp_compar);
560
561 TEST_EQ (lines, 3);
562 TEST_STR_MATCH (output[0], "bar stop/waiting");
563 TEST_STR_MATCH (output[1], "conflict stop/waiting");
564 TEST_STR_MATCH (output[2], "foo stop/waiting");
565 nih_free (output);
566
567 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
568 TEST_NE_P (cmd, NULL);
569 RUN_COMMAND (NULL, cmd, &output, &lines);
570
571 /* Ensure the correct version of the conflict job is found */
572 TEST_EQ (lines, 2);
573 TEST_STR_MATCH (output[0], "conflict");
574 TEST_STR_MATCH (output[1], " emits confdir_d");
575 nih_free (output);
576
577 DELETE_FILE (xdg_conf_dir, "conflict.conf");
578 DELETE_FILE (confdir_a, "conflict.conf");
579 DELETE_FILE (confdir_b, "foo.conf");
580 DELETE_FILE (confdir_c, "conflict.conf");
581 DELETE_FILE (confdir_d, "conflict.conf");
582 DELETE_FILE (confdir_e, "bar.conf");
583
584 STOP_UPSTART (upstart_pid);
585 assert0 (unlink (session_file));
586
587 /************************************************************/
588 TEST_FEATURE ("Session Init with multiple out of order --confdir, --prepend-confdir and --append-confdir");
589
590 CREATE_FILE (xdg_conf_dir, "conflict.conf", "emits xdg_conf_dir");
591 CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a");
592 CREATE_FILE (confdir_b, "foo.conf", "exec true");
593 CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c");
594 CREATE_FILE (confdir_d, "conflict.conf", "emits confdir_d");
595 CREATE_FILE (confdir_e, "bar.conf", "exec false");
596 CREATE_FILE (confdir_f, "baz.conf", "exec false");
597
598 extra[0] = "--append-confdir";
599 extra[1] = confdir_a;
600 extra[2] = "--prepend-confdir";
601 extra[3] = confdir_e;
602 extra[4] = "--confdir";
603 extra[5] = confdir_b;
604 extra[6] = "--append-confdir";
605 extra[7] = confdir_c;
606 extra[8] = "--prepend-confdir";
607 extra[9] = confdir_f;
608 extra[10] = "--confdir";
609 extra[11] = confdir_d;
610 extra[12] = NULL;
611
612 start_upstart_common (&upstart_pid, TRUE, FALSE, NULL, logdir, extra);
613
614 /* Should be running */
615 assert0 (kill (upstart_pid, 0));
616
617 session_file = get_session_file (xdg_runtime_dir, upstart_pid);
618
619 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
620 TEST_NE_P (cmd, NULL);
621 RUN_COMMAND (NULL, cmd, &output, &lines);
622
623 qsort (output, lines, sizeof (output[0]), strcmp_compar);
624
625 TEST_EQ (lines, 4);
626 TEST_STR_MATCH (output[0], "bar stop/waiting");
627 TEST_STR_MATCH (output[1], "baz stop/waiting");
628 TEST_STR_MATCH (output[2], "conflict stop/waiting");
629 TEST_STR_MATCH (output[3], "foo stop/waiting");
630 nih_free (output);
631
632 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
633 TEST_NE_P (cmd, NULL);
634 RUN_COMMAND (NULL, cmd, &output, &lines);
635
636 /* Ensure the correct version of the conflict job is found */
637 TEST_EQ (lines, 2);
638 TEST_STR_MATCH (output[0], "conflict");
639 TEST_STR_MATCH (output[1], " emits confdir_d");
640 nih_free (output);
641
642 DELETE_FILE (xdg_conf_dir, "conflict.conf");
643 DELETE_FILE (confdir_a, "conflict.conf");
644 DELETE_FILE (confdir_b, "foo.conf");
645 DELETE_FILE (confdir_c, "conflict.conf");
646 DELETE_FILE (confdir_d, "conflict.conf");
647 DELETE_FILE (confdir_e, "bar.conf");
648 DELETE_FILE (confdir_f, "baz.conf");
649
650 STOP_UPSTART (upstart_pid);
651 assert0 (unlink (session_file));
652
653 /************************************************************/
244 TEST_FEATURE ("System Init without --confdir");654 TEST_FEATURE ("System Init without --confdir");
245655
246 /* Use the "secret" interface */656 /* Use the "secret" interface */
@@ -305,6 +715,66 @@
305 STOP_UPSTART (upstart_pid);715 STOP_UPSTART (upstart_pid);
306716
307 /************************************************************/717 /************************************************************/
718 TEST_FEATURE ("System Init with --prepend-confdir");
719
720 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
721
722 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true");
723
724 extra[0] = "--prepend-confdir";
725 extra[1] = confdir_a;
726 extra[2] = NULL;
727
728 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
729
730 /* Should be running */
731 assert0 (kill (upstart_pid, 0));
732
733 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default");
734 TEST_NE_P (cmd, NULL);
735 RUN_COMMAND (NULL, cmd, &output, &lines);
736
737 qsort (output, lines, sizeof (output[0]), strcmp_compar);
738
739 TEST_EQ (lines, 1);
740 TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting");
741 nih_free (output);
742
743 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
744
745 STOP_UPSTART (upstart_pid);
746
747 /************************************************************/
748 TEST_FEATURE ("System Init with --append-confdir");
749
750 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
751
752 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true");
753
754 extra[0] = "--append-confdir";
755 extra[1] = confdir_a;
756 extra[2] = NULL;
757
758 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
759
760 /* Should be running */
761 assert0 (kill (upstart_pid, 0));
762
763 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default");
764 TEST_NE_P (cmd, NULL);
765 RUN_COMMAND (NULL, cmd, &output, &lines);
766
767 qsort (output, lines, sizeof (output[0]), strcmp_compar);
768
769 TEST_EQ (lines, 1);
770 TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting");
771 nih_free (output);
772
773 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
774
775 STOP_UPSTART (upstart_pid);
776
777 /************************************************************/
308 TEST_FEATURE ("System Init with multiple --confdir");778 TEST_FEATURE ("System Init with multiple --confdir");
309779
310 assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1));780 assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1));
@@ -331,14 +801,14 @@
331801
332 qsort (output, lines, sizeof (output[0]), strcmp_compar);802 qsort (output, lines, sizeof (output[0]), strcmp_compar);
333803
334 TEST_EQ (lines, 2);804 /* Like a Session Init, the System Init behaviour is (now) to
335 /* XXX: Only the last instance of --confdir should be honoured.805 * honour all --confdirs.
336 *
337 * This behaviour deviates from running as a Session Init where *all*
338 * --confdir's specified are used.
339 */806 */
340 TEST_STR_MATCH (output[0], "baz stop/waiting");807 TEST_EQ (lines, 3);
341 TEST_STR_MATCH (output[1], "qux stop/waiting");808
809 TEST_STR_MATCH (output[0], "bar stop/waiting");
810 TEST_STR_MATCH (output[1], "baz stop/waiting");
811 TEST_STR_MATCH (output[2], "qux stop/waiting");
342 nih_free (output);812 nih_free (output);
343813
344 DELETE_FILE (xdg_conf_dir, "foo.conf");814 DELETE_FILE (xdg_conf_dir, "foo.conf");
@@ -349,6 +819,96 @@
349 STOP_UPSTART (upstart_pid);819 STOP_UPSTART (upstart_pid);
350820
351 /************************************************************/821 /************************************************************/
822 TEST_FEATURE ("System Init with multiple --prepend-confdir");
823
824 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
825 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default2.conf"));
826
827 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true");
828 CREATE_FILE (confdir_b, "must-not-exist-by-default2.conf", "exec true");
829
830 extra[0] = "--prepend-confdir";
831 extra[1] = confdir_a;
832 extra[2] = "--prepend-confdir";
833 extra[3] = confdir_b;
834 extra[4] = NULL;
835
836 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
837
838 /* Should be running */
839 assert0 (kill (upstart_pid, 0));
840
841 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default");
842 TEST_NE_P (cmd, NULL);
843 RUN_COMMAND (NULL, cmd, &output, &lines);
844
845 qsort (output, lines, sizeof (output[0]), strcmp_compar);
846
847 TEST_EQ (lines, 1);
848 TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting");
849 nih_free (output);
850
851 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default2");
852 TEST_NE_P (cmd, NULL);
853 RUN_COMMAND (NULL, cmd, &output, &lines);
854
855 qsort (output, lines, sizeof (output[0]), strcmp_compar);
856
857 TEST_EQ (lines, 1);
858 TEST_STR_MATCH (output[0], "must-not-exist-by-default2 stop/waiting");
859 nih_free (output);
860
861 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
862 DELETE_FILE (confdir_b, "must-not-exist-by-default2.conf");
863
864 STOP_UPSTART (upstart_pid);
865
866 /************************************************************/
867 TEST_FEATURE ("System Init with multiple --append-confdir");
868
869 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
870 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default2.conf"));
871
872 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "exec true");
873 CREATE_FILE (confdir_b, "must-not-exist-by-default2.conf", "exec true");
874
875 extra[0] = "--append-confdir";
876 extra[1] = confdir_a;
877 extra[2] = "--append-confdir";
878 extra[3] = confdir_b;
879 extra[4] = NULL;
880
881 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
882
883 /* Should be running */
884 assert0 (kill (upstart_pid, 0));
885
886 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default");
887 TEST_NE_P (cmd, NULL);
888 RUN_COMMAND (NULL, cmd, &output, &lines);
889
890 qsort (output, lines, sizeof (output[0]), strcmp_compar);
891
892 TEST_EQ (lines, 1);
893 TEST_STR_MATCH (output[0], "must-not-exist-by-default stop/waiting");
894 nih_free (output);
895
896 cmd = nih_sprintf (NULL, "%s status %s 2>&1", get_initctl (), "must-not-exist-by-default2");
897 TEST_NE_P (cmd, NULL);
898 RUN_COMMAND (NULL, cmd, &output, &lines);
899
900 qsort (output, lines, sizeof (output[0]), strcmp_compar);
901
902 TEST_EQ (lines, 1);
903 TEST_STR_MATCH (output[0], "must-not-exist-by-default2 stop/waiting");
904 nih_free (output);
905
906 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
907 DELETE_FILE (confdir_b, "must-not-exist-by-default2.conf");
908
909 STOP_UPSTART (upstart_pid);
910
911 /************************************************************/
352 TEST_FEATURE ("System Init with multiple --confdir and conflicting names");912 TEST_FEATURE ("System Init with multiple --confdir and conflicting names");
353913
354 assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1));914 assert0 (setenv ("UPSTART_CONFDIR", xdg_conf_dir, 1));
@@ -363,6 +923,7 @@
363 extra[3] = confdir_b;923 extra[3] = confdir_b;
364 extra[4] = NULL;924 extra[4] = NULL;
365925
926 /* pass 2 confdir directories */
366 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);927 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
367928
368 /* Should be running */929 /* Should be running */
@@ -375,7 +936,6 @@
375 qsort (output, lines, sizeof (output[0]), strcmp_compar);936 qsort (output, lines, sizeof (output[0]), strcmp_compar);
376937
377 TEST_EQ (lines, 1);938 TEST_EQ (lines, 1);
378 /* only the last instance of --confdir should be honoured */
379 TEST_STR_MATCH (output[0], "conflict stop/waiting");939 TEST_STR_MATCH (output[0], "conflict stop/waiting");
380 nih_free (output);940 nih_free (output);
381941
@@ -386,7 +946,7 @@
386 /* Ensure the correct version of the conflict job is found */946 /* Ensure the correct version of the conflict job is found */
387 TEST_EQ (lines, 2);947 TEST_EQ (lines, 2);
388 TEST_STR_MATCH (output[0], "conflict");948 TEST_STR_MATCH (output[0], "conflict");
389 TEST_STR_MATCH (output[1], " emits confdir_b");949 TEST_STR_MATCH (output[1], " emits confdir_a");
390 nih_free (output);950 nih_free (output);
391951
392 DELETE_FILE (xdg_conf_dir, "conflict.conf");952 DELETE_FILE (xdg_conf_dir, "conflict.conf");
@@ -396,11 +956,171 @@
396 STOP_UPSTART (upstart_pid);956 STOP_UPSTART (upstart_pid);
397957
398 /************************************************************/958 /************************************************************/
959 TEST_FEATURE ("System Init with multiple --prepend-confdir and conflicting names");
960
961 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
962
963 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "emits confdir_a");
964 CREATE_FILE (confdir_b, "must-not-exist-by-default.conf", "emits confdir_b");
965
966 extra[0] = "--prepend-confdir";
967 extra[1] = confdir_a;
968 extra[2] = "--prepend-confdir";
969 extra[3] = confdir_b;
970 extra[4] = NULL;
971
972 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
973
974 /* Should be running */
975 assert0 (kill (upstart_pid, 0));
976
977 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "must-not-exist-by-default");
978 TEST_NE_P (cmd, NULL);
979 RUN_COMMAND (NULL, cmd, &output, &lines);
980
981 /* Ensure the correct version of the conflict job is found */
982 TEST_EQ (lines, 2);
983 TEST_STR_MATCH (output[0], "must-not-exist-by-default");
984 TEST_STR_MATCH (output[1], " emits confdir_a");
985 nih_free (output);
986
987 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
988 DELETE_FILE (confdir_b, "must-not-exist-by-default.conf");
989
990 STOP_UPSTART (upstart_pid);
991
992 /************************************************************/
993 TEST_FEATURE ("System Init with multiple --append-confdir and conflicting names");
994
995 TEST_FALSE (file_exists ("/etc/init/must-not-exist-by-default.conf"));
996
997 CREATE_FILE (confdir_a, "must-not-exist-by-default.conf", "emits confdir_a");
998 CREATE_FILE (confdir_b, "must-not-exist-by-default.conf", "emits confdir_b");
999
1000 extra[0] = "--append-confdir";
1001 extra[1] = confdir_a;
1002 extra[2] = "--append-confdir";
1003 extra[3] = confdir_b;
1004 extra[4] = NULL;
1005
1006 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
1007
1008 /* Should be running */
1009 assert0 (kill (upstart_pid, 0));
1010
1011 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "must-not-exist-by-default");
1012 TEST_NE_P (cmd, NULL);
1013 RUN_COMMAND (NULL, cmd, &output, &lines);
1014
1015 /* Ensure the correct version of the conflict job is found */
1016 TEST_EQ (lines, 2);
1017 TEST_STR_MATCH (output[0], "must-not-exist-by-default");
1018 TEST_STR_MATCH (output[1], " emits confdir_a");
1019 nih_free (output);
1020
1021 DELETE_FILE (confdir_a, "must-not-exist-by-default.conf");
1022 DELETE_FILE (confdir_b, "must-not-exist-by-default.conf");
1023
1024 STOP_UPSTART (upstart_pid);
1025
1026 /************************************************************/
1027 TEST_FEATURE ("System Init with multiple out of order --confdir, --prepend-confdir and --append-confdir");
1028
1029 CREATE_FILE (confdir_a, "conflict.conf", "emits confdir_a");
1030 CREATE_FILE (confdir_a, "wibble.conf", "emits wobble");
1031 CREATE_FILE (confdir_b, "conflict.conf", "emits confdir_b");
1032 CREATE_FILE (confdir_c, "conflict.conf", "emits confdir_c");
1033 CREATE_FILE (confdir_d, "foo.conf", "emits hello");
1034 CREATE_FILE (confdir_e, "bar.conf", "emits world");
1035 CREATE_FILE (confdir_e, "conflict.conf", "emits confdir_e");
1036 CREATE_FILE (confdir_f, "conflict.conf", "emits confdir_f");
1037 CREATE_FILE (confdir_f, "baz.conf", "exec true");
1038
1039 extra[0] = "--append-confdir";
1040 extra[1] = confdir_a;
1041 extra[2] = "--prepend-confdir";
1042 extra[3] = confdir_e;
1043 extra[4] = "--confdir";
1044 extra[5] = confdir_b;
1045 extra[6] = "--append-confdir";
1046 extra[7] = confdir_f;
1047 extra[8] = "--confdir";
1048 extra[9] = confdir_c;
1049 extra[10] = "--prepend-confdir";
1050 extra[11] = confdir_d;
1051 extra[12] = NULL;
1052
1053 start_upstart_common (&upstart_pid, FALSE, FALSE, NULL, logdir, extra);
1054
1055 /* Should be running */
1056 assert0 (kill (upstart_pid, 0));
1057
1058 cmd = nih_sprintf (NULL, "%s list 2>&1", get_initctl ());
1059 TEST_NE_P (cmd, NULL);
1060 RUN_COMMAND (NULL, cmd, &output, &lines);
1061
1062 qsort (output, lines, sizeof (output[0]), strcmp_compar);
1063
1064 TEST_EQ (lines, 5);
1065 TEST_STR_MATCH (output[0], "bar stop/waiting");
1066 TEST_STR_MATCH (output[1], "baz stop/waiting");
1067 TEST_STR_MATCH (output[2], "conflict stop/waiting");
1068 TEST_STR_MATCH (output[3], "foo stop/waiting");
1069 TEST_STR_MATCH (output[4], "wibble stop/waiting");
1070 nih_free (output);
1071
1072 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "conflict");
1073 TEST_NE_P (cmd, NULL);
1074 RUN_COMMAND (NULL, cmd, &output, &lines);
1075 TEST_EQ (lines, 2);
1076 TEST_STR_MATCH (output[0], "conflict");
1077 TEST_STR_MATCH (output[1], " emits confdir_e");
1078 nih_free (output);
1079
1080 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "wibble");
1081 TEST_NE_P (cmd, NULL);
1082 RUN_COMMAND (NULL, cmd, &output, &lines);
1083 TEST_EQ (lines, 2);
1084 TEST_STR_MATCH (output[0], "wibble");
1085 TEST_STR_MATCH (output[1], " emits wobble");
1086 nih_free (output);
1087
1088 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "foo");
1089 TEST_NE_P (cmd, NULL);
1090 RUN_COMMAND (NULL, cmd, &output, &lines);
1091 TEST_EQ (lines, 2);
1092 TEST_STR_MATCH (output[0], "foo");
1093 TEST_STR_MATCH (output[1], " emits hello");
1094 nih_free (output);
1095
1096 cmd = nih_sprintf (NULL, "%s show-config %s 2>&1", get_initctl (), "bar");
1097 TEST_NE_P (cmd, NULL);
1098 RUN_COMMAND (NULL, cmd, &output, &lines);
1099 TEST_EQ (lines, 2);
1100 TEST_STR_MATCH (output[0], "bar");
1101 TEST_STR_MATCH (output[1], " emits world");
1102 nih_free (output);
1103
1104 DELETE_FILE (confdir_a, "conflict.conf");
1105 DELETE_FILE (confdir_a, "wibble.conf");
1106 DELETE_FILE (confdir_b, "conflict.conf");
1107 DELETE_FILE (confdir_c, "conflict.conf");
1108 DELETE_FILE (confdir_d, "foo.conf");
1109 DELETE_FILE (confdir_e, "bar.conf");
1110 DELETE_FILE (confdir_e, "conflict.conf");
1111 DELETE_FILE (confdir_f, "conflict.conf");
1112 DELETE_FILE (confdir_f, "baz.conf");
1113
1114 STOP_UPSTART (upstart_pid);
3991115
400 TEST_DBUS_END (dbus_pid);1116 TEST_DBUS_END (dbus_pid);
4011117
402 assert0 (rmdir (confdir_a));1118 assert0 (rmdir (confdir_a));
403 assert0 (rmdir (confdir_b));1119 assert0 (rmdir (confdir_b));
1120 assert0 (rmdir (confdir_c));
1121 assert0 (rmdir (confdir_d));
1122 assert0 (rmdir (confdir_e));
1123 assert0 (rmdir (confdir_f));
404 assert0 (rmdir (xdg_conf_dir));1124 assert0 (rmdir (xdg_conf_dir));
405 assert0 (rmdir (logdir));1125 assert0 (rmdir (logdir));
406 assert0 (unsetenv ("UPSTART_CONFDIR"));1126 assert0 (unsetenv ("UPSTART_CONFDIR"));

Subscribers

People subscribed via source and target branches