diff options
author | Dan Williams <dcbw@redhat.com> | 2014-06-02 14:07:46 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2014-06-06 13:43:46 -0500 |
commit | 1383f4bc14a83b56e06210222ecf2e6b18dfc18e (patch) | |
tree | 15deab8378ca11f019e39baa0fb6c907aad0a994 /callouts | |
parent | 7eaaa6a475b3d73e0967c9fa928268c1498f6b50 (diff) |
dispatcher: use separate directories for pre-up/pre-down events
To ensure that NetworkManager does not block needlessly for events
which have no scripts, require scripts that respond to blocking
events to opt into the action.
Diffstat (limited to 'callouts')
-rw-r--r-- | callouts/nm-dispatcher-api.h | 17 | ||||
-rw-r--r-- | callouts/nm-dispatcher.c | 20 |
2 files changed, 31 insertions, 6 deletions
diff --git a/callouts/nm-dispatcher-api.h b/callouts/nm-dispatcher-api.h index 96db789283..eb6b33fe0c 100644 --- a/callouts/nm-dispatcher-api.h +++ b/callouts/nm-dispatcher-api.h @@ -20,7 +20,9 @@ #include <dbus/dbus-glib.h> -#define NMD_SCRIPT_DIR NMCONFDIR "/dispatcher.d" +#define NMD_SCRIPT_DIR NMCONFDIR "/dispatcher.d" +#define NMD_PRE_UP_DIR NMD_SCRIPT_DIR "/pre-up.d" +#define NMD_PRE_DOWN_DIR NMD_SCRIPT_DIR "/pre-down.d" /* dbus-glib types for dispatcher call return value */ #define DISPATCHER_TYPE_RESULT (dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID)) @@ -38,6 +40,19 @@ #define NMD_DEVICE_PROPS_STATE "state" #define NMD_DEVICE_PROPS_PATH "path" +/* Actions */ +#define NMD_ACTION_HOSTNAME "hostname" +#define NMD_ACTION_PRE_UP "pre-up" +#define NMD_ACTION_UP "up" +#define NMD_ACTION_PRE_DOWN "pre-down" +#define NMD_ACTION_DOWN "down" +#define NMD_ACTION_VPN_PRE_UP "vpn-pre-up" +#define NMD_ACTION_VPN_UP "vpn-up" +#define NMD_ACTION_VPN_PRE_DOWN "vpn-pre-down" +#define NMD_ACTION_VPN_DOWN "vpn-down" +#define NMD_ACTION_DHCP4_CHANGE "dhcp4-change" +#define NMD_ACTION_DHCP6_CHANGE "dhcp6-change" + typedef enum { DISPATCH_RESULT_UNKNOWN = 0, DISPATCH_RESULT_SUCCESS = 1, diff --git a/callouts/nm-dispatcher.c b/callouts/nm-dispatcher.c index 3747fd563a..6c9c294f27 100644 --- a/callouts/nm-dispatcher.c +++ b/callouts/nm-dispatcher.c @@ -414,16 +414,26 @@ dispatch_one_script (Request *request) } static GSList * -find_scripts (void) +find_scripts (const char *str_action) { GDir *dir; const char *filename; GSList *sorted = NULL; GError *error = NULL; + const char *dirname; + + if ( strcmp (str_action, NMD_ACTION_PRE_UP) == 0 + || strcmp (str_action, NMD_ACTION_VPN_PRE_UP) == 0) + dirname = NMD_PRE_UP_DIR; + else if ( strcmp (str_action, NMD_ACTION_PRE_DOWN) == 0 + || strcmp (str_action, NMD_ACTION_VPN_PRE_DOWN) == 0) + dirname = NMD_PRE_DOWN_DIR; + else + dirname = NMD_SCRIPT_DIR; - if (!(dir = g_dir_open (NMD_SCRIPT_DIR, 0, &error))) { + if (!(dir = g_dir_open (dirname, 0, &error))) { g_warning ("Failed to open dispatcher directory '%s': (%d) %s", - NMD_SCRIPT_DIR, error->code, error->message); + dirname, error->code, error->message); g_error_free (error); return NULL; } @@ -436,7 +446,7 @@ find_scripts (void) if (!check_filename (filename)) continue; - path = g_build_filename (NMD_SCRIPT_DIR, filename, NULL); + path = g_build_filename (dirname, filename, NULL); err = stat (path, &st); if (err) @@ -476,7 +486,7 @@ impl_dispatch (Handler *h, char **p; char *iface = NULL; - sorted_scripts = find_scripts (); + sorted_scripts = find_scripts (str_action); if (!sorted_scripts) { dbus_g_method_return (context, g_ptr_array_new ()); |