James Hunt has proposed merging lp:~jamesodhunt/upstart/allow-multiple-cmdline-confdirs into lp:upstart.
Requested reviews: Upstart Reviewers (upstart-reviewers) For more details, see: https://code.launchpad.net/~jamesodhunt/upstart/allow-multiple-cmdline-confdirs/+merge/156512 This change is required for the upcoming test framework since it is necessary to allow a Session Init to operate in a known environment (crucially without loading in all the standard Session Jobs provided on, for example, an Ubuntu Raring system). Note this introduces a small behavioural change in that now if --confdir is specified one or more times for a Session Init, *only* those directories specified will be used (whereas before the single confdir specified would be prepended to the standard list of directories searched). = Future Work = It might be worth adding the ability for the list of directories being used to be queried both via a new initctl command (for a running instance), and via an init option to see what user directories *would* be used. = Change Summary = * init/main.c: - main(): Allow Session Init to accept multiple --confdir values, which replace all built-in values (behaviour required for testing). - handle_confdir(): Operate on conf_dirs array rather than single conf_dir value. - conf_dir_setter(): Command-line setter function to add configuration file directories to conf_dirs array. * init/man/init.8: Update on --confdir behaviour. -- https://code.launchpad.net/~jamesodhunt/upstart/allow-multiple-cmdline-confdirs/+merge/156512 Your team Upstart Reviewers is requested to review the proposed merge of lp:~jamesodhunt/upstart/allow-multiple-cmdline-confdirs into lp:upstart.
=== modified file 'ChangeLog' --- ChangeLog 2013-03-28 17:07:54 +0000 +++ ChangeLog 2013-04-02 10:30:30 +0000 @@ -1,3 +1,14 @@ +2013-04-02 James Hunt <[email protected]> + + * init/main.c: + - main(): Allow Session Init to accept multiple --confdir values, + which replace all built-in values (behaviour required for testing). + - handle_confdir(): Operate on conf_dirs array rather than single + conf_dir value. + - conf_dir_setter(): Command-line setter function to add configuration + file directories to conf_dirs array. + * init/man/init.8: Update on --confdir behaviour. + 2013-03-28 James Hunt <[email protected]> * scripts/upstart-monitor.py: on_button_press_event(): === modified file 'init/main.c' --- init/main.c 2013-03-01 15:13:54 +0000 +++ init/main.c 2013-04-02 10:30:30 +0000 @@ -88,6 +88,7 @@ static void handle_confdir (void); static void handle_logdir (void); static int console_type_setter (NihOption *option, const char *arg); +static int conf_dir_setter (NihOption *option, const char *arg); /** @@ -99,12 +100,11 @@ static int state_fd = -1; /** - * conf_dir: - * - * Full path to job configuration file directory. - * + * conf_dirs: + * + * Array of full paths to job configuration file directories. **/ -static char *conf_dir = NULL; +static char **conf_dirs = NULL; /** * initial_event: @@ -136,7 +136,7 @@ **/ static NihOption options[] = { { 0, "confdir", N_("specify alternative directory to load configuration files from"), - NULL, "DIR", &conf_dir, NULL }, + NULL, "DIR", NULL, conf_dir_setter }, { 0, "default-console", N_("default value for console stanza"), NULL, "VALUE", NULL, console_type_setter }, @@ -185,9 +185,10 @@ char *argv[]) { char **args = NULL; - char **dirs = NULL; int ret; + conf_dirs = NIH_MUST (nih_str_array_new (NULL)); + args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv)); nih_main_init (args_copy[0]); @@ -532,19 +533,38 @@ } /* Read configuration */ - if (! user_mode) + if (! user_mode) { + char *conf_dir; + int len = 0; + + nih_assert (conf_dirs[0]); + + /* Count entries */ + for (char **d = conf_dirs; d && *d; d++, len++) + ; + + nih_assert (len); + + /* Use last value specified */ + conf_dir = conf_dirs[len-1]; + NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE)); - if (conf_dir) + nih_debug ("Using configuration directory %s", conf_dir); NIH_MUST (conf_source_new (NULL, conf_dir, CONF_JOB_DIR)); + } else { + nih_local char **dirs = NULL; - if (user_mode) { dirs = NIH_MUST (get_user_upstart_dirs ()); - for (char **d = dirs; d && *d; d++) + + for (char **d = conf_dirs[0] ? conf_dirs : dirs; d && *d; d++) { + nih_debug ("Using configuration directory %s", *d); NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR)); - nih_free (dirs); + } } + nih_free (conf_dirs); + job_class_environment_init (); conf_reload (); @@ -922,31 +942,26 @@ /** * handle_confdir: * - * Determine where system configuration files should be loaded from. + * Determine where system configuration files should be loaded from + * if not specified on the command-line. **/ static void handle_confdir (void) { - char *dir; + char *dir; + + nih_assert (conf_dirs); /* user has already specified directory on command-line */ - if (conf_dir) - goto out; + if (conf_dirs[0]) + return; if (user_mode) return; - conf_dir = CONFDIR; - dir = getenv (CONFDIR_ENV); - if (! dir) - return; - - conf_dir = dir; - -out: - nih_debug ("Using alternate configuration directory %s", - conf_dir); + + NIH_MUST (nih_str_array_add (&conf_dirs, NULL, NULL, dir ? dir : CONFDIR)); } /** @@ -1001,3 +1016,20 @@ return 0; } + +/** + * NihOption setter function to handle selection of configuration file + * directories. + * + * Returns: 0 on success, -1 on invalid console type. + **/ +static int +conf_dir_setter (NihOption *option, const char *arg) +{ + nih_assert (conf_dirs); + nih_assert (option); + + NIH_MUST (nih_str_array_add (&conf_dirs, NULL, NULL, arg)); + + return 0; +} === modified file 'init/man/init.8' --- init/man/init.8 2013-02-25 09:42:11 +0000 +++ init/man/init.8 2013-04-02 10:30:30 +0000 @@ -65,10 +65,13 @@ .\" .TP .B \-\-confdir \fIdirectory\fP -Read job configuration files from a directory other than -\fI/etc/init\fP. -For user session mode, read job configuration files from this -directory at highest priority. +Read job configuration files from a directory other than the default +(\fI/etc/init\fP for process ID 1). + +When running as process ID 1, the last directory specified will be used. + +In user session mode, multiple directories will be honoured and job +configuration files loaded from the directories in the order specified. .\" .TP .B \-\-default-console \fIvalue\fP
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
