------------------------------------------------------------ revno: 1415 committer: James Hunt <[email protected]> branch nick: upstart-setenv+getenv timestamp: Wed 2013-01-09 10:13:36 +0000 message: * init/man/init.5: - Overhauled 'Job environment' section. * util/initctl.c: - Added 'unset-env' and 'reset-env' commands. - Added missing periods in usage text. modified: ChangeLog init/man/init.5 util/initctl.c
-- lp:upstart https://code.launchpad.net/~upstart-devel/upstart/trunk Your team Upstart Reviewers is subscribed to branch lp:upstart. To unsubscribe from this branch go to https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== modified file 'ChangeLog' --- ChangeLog 2013-01-09 10:12:53 +0000 +++ ChangeLog 2013-01-09 10:13:36 +0000 @@ -1,3 +1,11 @@ +01-09 James Hunt <[email protected]> + + * init/man/init.5: + - Overhauled 'Job environment' section. + * util/initctl.c: + - Added 'unset-env' and 'reset-env' commands. + - Added missing periods in usage text. + 2013-01-08 James Hunt <[email protected]> * dbus/com.ubuntu.Upstart.xml: === modified file 'init/man/init.5' --- init/man/init.5 2012-12-18 17:40:49 +0000 +++ init/man/init.5 2013-01-09 10:13:36 +0000 @@ -415,17 +415,36 @@ is via \fBstart\fP (8). .SS Job environment -Each job is run with the environment from the events or commands that -started it. In addition, you may define defaults in the job which may -be overridden later and specify which environment variables are exported -into the events generated for the job. - +Each job is run with an environment constructed from the +following categories: +.\" +.IP \(bu 4 +A minimal set of standard system variables added by Upstart. +.sp 1 +All jobs contain the \fBTERM\fP and \fBPATH\fP variables. +.\" +.IP \(bu 4 +A set of special variables added by Upstart that relate to the job itself. +.sp 1 +All jobs also contain the +.B UPSTART_JOB +and +.B UPSTART_INSTANCE +environment variables, containing the name of the job and instance. These +are mostly used by the +.BR initctl (8) +utility to default to acting on the job the commands are called from. +.\" +.IP \(bu 4 +Those variables introduced by the events or command that started the +job. +.sp 1 The special .B UPSTART_EVENTS environment variable contains the list of events that started the job, it will not be present if the job was started manually. -In addition, the +The .B pre\-stop and .B post\-stop @@ -434,16 +453,17 @@ .B UPSTART_STOP_EVENTS environment variable contains the list of events that stopped the job, it will not be present if the job was stopped manually. - -All jobs also contain the -.B UPSTART_JOB +.\" +.IP \(bu 4 +Variables set within the job itself using the +.B env and -.B UPSTART_INSTANCE -environment variables, containing the name of the job and instance. These -are mostly used by the -.BR initctl (8) -utility to default to acting on the job the commands are called from. - +.B export +stanzas. These provide default values - if the command or event which causes the +job to start specifies alternative values, those are given priority over +the defaults. +.RS +.\" .TP .B env \fIKEY\fR[=\fIVALUE\fR] Defines a default environment variable, the value of which may be overridden @@ -466,6 +486,15 @@ and to all resultant events .ft (not just those relating to the current job). +.RE +.\" +.IP \(bu 4 +Variables set using the +.BR initctl (8) +job environment commands (such as \fIset-env\fP). +.sp 1 +These commands also allow unsetting of variables. + .\" .SS Services, tasks and respawning Jobs are === modified file 'util/initctl.c' --- util/initctl.c 2013-01-08 17:27:53 +0000 +++ util/initctl.c 2013-01-09 10:13:36 +0000 @@ -129,6 +129,8 @@ int get_env_action (NihCommand *command, char * const *args); int set_env_action (NihCommand *command, char * const *args); int list_env_action (NihCommand *command, char * const *args); +int unset_env_action (NihCommand *command, char * const *args); +int reset_env_action (NihCommand *command, char * const *args); /** * use_dbus: @@ -1420,9 +1422,89 @@ /** + * unset_env_action: + * @command: NihCommand invoked, + * @args: command-line arguments. + * + * This function is called for the "unset-env" command. + * + * Returns: command exit status. + **/ +int +unset_env_action (NihCommand *command, char * const *args) +{ + nih_local NihDBusProxy *upstart = NULL; + NihError *err; + char *name; + + nih_assert (command != NULL); + nih_assert (args != NULL); + + name = args[0]; + + if (! name) { + fprintf (stderr, _("%s: missing variable name\n"), program_name); + nih_main_suggest_help (); + return 1; + } + + upstart = upstart_open (NULL); + if (! upstart) + return 1; + + if (upstart_unset_env_sync (NULL, upstart, name) < 0) + goto error; + + return 0; +error: + err = nih_error_get (); + nih_error ("%s", err->message); + nih_free (err); + + return 1; +} + +/** + * reset_env_action: + * @command: NihCommand invoked, + * @args: command-line arguments. + * + * This function is called for the "reset-env" command. + * + * Returns: command exit status. + **/ +int +reset_env_action (NihCommand *command, char * const *args) +{ + nih_local NihDBusProxy *upstart = NULL; + NihError *err; + + nih_assert (command != NULL); + nih_assert (args != NULL); + + upstart = upstart_open (NULL); + if (! upstart) + return 1; + + if (upstart_reset_env_sync (NULL, upstart) < 0) + goto error; + + return 0; +error: + err = nih_error_get (); + nih_error ("%s", err->message); + nih_free (err); + + return 1; +} + +/** * list_env_strcmp_compar: * - * Function to sort environment variables for list_env_action(). + * @a: first string to compare, + * @b: second string to compare. + * + * qsort() function to sort environment variables for list_env_action(). **/ static int list_env_strcmp_compar (const void *a, const void *b) @@ -2764,7 +2846,7 @@ NULL, version_options, version_action }, { "log-priority", N_("[PRIORITY]"), N_("Change the minimum priority of log messages from the init " - "daemon"), + "daemon."), N_("PRIORITY may be one of:\n" " `debug' (messages useful for debugging upstart are logged, " "equivalent to --debug on kernel command-line);\n" @@ -2791,24 +2873,34 @@ { "check-config", N_("[CONF]"), N_("Check for unreachable jobs/event conditions."), N_("List all jobs and events which cannot be satisfied by " - "currently available job configuration files"), + "currently available job configuration files."), NULL, check_config_options, check_config_action }, { "get-env", N_("VARIABLE"), - N_("Get job environment variable"), - N_("Display the value of a job environment variable"), + N_("Retrieve value of a job environment variable."), + N_("Display the value of a variable from the job environment table."), NULL, NULL, get_env_action }, { "list-env", NULL, - N_("List all job environment variables"), - N_("Returns unsorted list of job environment variables and values"), + N_("Show all job environment variables."), + N_("Displays sorted list of variables and their values from the job environment table."), NULL, NULL, list_env_action }, + { "reset-env", N_("VARIABLE"), + N_("Revert all job environment variable changes."), + N_("Discards all changes make to the job environment table, setting it back to its default value."), + NULL, NULL, reset_env_action }, + { "set-env", N_("VARIABLE[=VALUE]"), - N_("Set job environment variable"), - N_("Set a job environment variable"), + N_("Set a job environment variable."), + N_("Adds or updates a variable in the job environment table."), NULL, set_env_options, set_env_action }, + { "unset-env", N_("VARIABLE"), + N_("Remove a job environment variable."), + N_("Discards the specified variable from the job environment table."), + NULL, NULL, unset_env_action }, + { "usage", N_("JOB"), N_("Show job usage message if available."), N_("JOB is the name of the job which usage is to be shown.\n" ), @@ -2817,7 +2909,7 @@ { "notify-disk-writeable", NULL, N_("Inform Upstart that disk is now writeable."), N_("Run to ensure output from jobs ending before " - "disk is writeable are flushed to disk"), + "disk is writeable are flushed to disk."), NULL, NULL, notify_disk_writeable_action }, NIH_COMMAND_LAST
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
