dispatcher: add NM_DISPATCHER_ACTION environment variable

Previously, the action was only passed as the first command line
argument to the dispatcher scripts. Now, also set it via the
"$NM_DISPATCHER_ACTION" environment variable.

The main purpose is to have a particular, nm-dispatcher specific
variable that is always set inside the dispatcher scripts.
For example, imagine you have a script that can be either called by
dispatcher or some other means (manually, or spawned via
/etc/NetworkManager/dispatcher.d/11-dhclient).  Then it might make
sense to differenciate from inside the script whether you are called
by nm-dispatcher. But previously, there was no specific environment
variable that was always set inside the dispatcher event. For example,
with the "hostname" action there are no other environment variables.

Now (with version 1.12), you can check for `test -n "$NM_DISPATCHER_ACTION"`.

(cherry picked from commit ce9619047c)
This commit is contained in:
Thomas Haller 2018-06-18 13:08:16 +02:00
parent f8dfc436b1
commit 2800232bbf
3 changed files with 10 additions and 0 deletions

1
NEWS
View file

@ -47,6 +47,7 @@ Notable changes include:
The following features were backported to 1.10.x releases from 1.10.0 to
1.10.10 are also present in NetworkManager-1.12:
* Set NM_DISPATCHER_ACTION environment variable in dispatcher scripts.
* Fix crash during reapply of connection settings
* Fix connectivity timeout handling (bgo #794464),
* Retry activating devices when the parent becomes managed (rh #1553595),

View file

@ -575,6 +575,8 @@ done:
_items_add_key0 (items, NULL, "PATH", g_getenv ("PATH"));
_items_add_key (items, NULL, "NM_DISPATCHER_ACTION", action);
*out_error_message = NULL;
g_ptr_array_add (items, NULL);
return (char **) g_ptr_array_free (g_steal_pointer (&items), FALSE);

View file

@ -181,6 +181,13 @@
The environment contains more information about the interface and the connection.
The following variables are available for the use in the dispatcher scripts:
<variablelist class="dispatcher-environment">
<varlistentry>
<term><varname>NM_DISPATCHER_ACTION</varname></term>
<listitem><para>
The dispatcher action like "up" or "dhcp4-change", identical to the first
command line argument. Since NetworkManager 1.12.0.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>CONNECTION_UUID</varname></term>
<listitem><para>