From 2800232bbf6f44e6776bd18286d5d51fdf70392b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 18 Jun 2018 13:08:16 +0200 Subject: [PATCH] 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 ce9619047c5daac9a006d16d07453d50e0520e71) --- NEWS | 1 + dispatcher/nm-dispatcher-utils.c | 2 ++ man/NetworkManager.xml | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/NEWS b/NEWS index 246ea48bd6..3852f618fa 100644 --- a/NEWS +++ b/NEWS @@ -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), diff --git a/dispatcher/nm-dispatcher-utils.c b/dispatcher/nm-dispatcher-utils.c index 362f31264e..4d04eeca97 100644 --- a/dispatcher/nm-dispatcher-utils.c +++ b/dispatcher/nm-dispatcher-utils.c @@ -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); diff --git a/man/NetworkManager.xml b/man/NetworkManager.xml index 0ec6b0aee9..7b0513bb92 100644 --- a/man/NetworkManager.xml +++ b/man/NetworkManager.xml @@ -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: + + NM_DISPATCHER_ACTION + + The dispatcher action like "up" or "dhcp4-change", identical to the first + command line argument. Since NetworkManager 1.12.0. + + CONNECTION_UUID