mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-24 09:58:14 +02:00
dispatcher: only dispatch if scripts exist
If there are no dispatcher scripts, don't bother dispatching any events. This saves some time configuring networking if the event would have no effect anyway.
This commit is contained in:
parent
4cc13befd3
commit
5150cb88c2
5 changed files with 62 additions and 2 deletions
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#define NMD_SCRIPT_DIR NMCONFDIR "/dispatcher.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))
|
||||
#define DISPATCHER_TYPE_RESULT_ARRAY (dbus_g_type_get_collection ("GPtrArray", DISPATCHER_TYPE_RESULT))
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@
|
|||
#include "nm-dispatcher-utils.h"
|
||||
#include "nm-glib-compat.h"
|
||||
|
||||
#define NMD_SCRIPT_DIR NMCONFDIR "/dispatcher.d"
|
||||
|
||||
static GMainLoop *loop = NULL;
|
||||
static gboolean debug = FALSE;
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "nm-config.h"
|
||||
#include "nm-posix-signals.h"
|
||||
#include "nm-session-monitor.h"
|
||||
#include "nm-dispatcher.h"
|
||||
|
||||
#if !defined(NM_DIST_VERSION)
|
||||
# define NM_DIST_VERSION VERSION
|
||||
|
|
@ -604,6 +605,8 @@ main (int argc, char *argv[])
|
|||
dhcp_mgr = nm_dhcp_manager_get ();
|
||||
g_assert (dhcp_mgr != NULL);
|
||||
|
||||
nm_dispatcher_init ();
|
||||
|
||||
settings = nm_settings_new (&error);
|
||||
if (!settings) {
|
||||
nm_log_err (LOGD_CORE, "failed to initialize settings storage: %s",
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "nm-dbus-glib-types.h"
|
||||
#include "nm-glib-compat.h"
|
||||
|
||||
static gboolean do_dispatch = TRUE;
|
||||
static GSList *requests = NULL;
|
||||
|
||||
static void
|
||||
|
|
@ -134,12 +135,15 @@ fill_vpn_props (NMIP4Config *ip4_config,
|
|||
typedef struct {
|
||||
DispatcherFunc callback;
|
||||
gpointer user_data;
|
||||
guint idle_id;
|
||||
} DispatchInfo;
|
||||
|
||||
static void
|
||||
dispatcher_info_free (DispatchInfo *info)
|
||||
{
|
||||
requests = g_slist_remove (requests, info);
|
||||
if (info->idle_id)
|
||||
g_source_remove (info->idle_id);
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
|
|
@ -261,6 +265,18 @@ action_to_string (DispatcherAction action)
|
|||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static gboolean
|
||||
dispatcher_idle_cb (gpointer user_data)
|
||||
{
|
||||
DispatchInfo *info = user_data;
|
||||
|
||||
info->idle_id = 0;
|
||||
if (info->callback)
|
||||
info->callback (info, info->user_data);
|
||||
dispatcher_info_free (info);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static gconstpointer
|
||||
_dispatcher_call (DispatcherAction action,
|
||||
NMConnection *connection,
|
||||
|
|
@ -299,6 +315,16 @@ _dispatcher_call (DispatcherAction action,
|
|||
if (action == DISPATCHER_ACTION_VPN_UP)
|
||||
g_return_val_if_fail (vpn_ip4_config != NULL, NULL);
|
||||
|
||||
if (do_dispatch == FALSE) {
|
||||
info = g_malloc0 (sizeof (*info));
|
||||
info->callback = callback;
|
||||
info->user_data = user_data;
|
||||
info->idle_id = g_idle_add (dispatcher_idle_cb, info);
|
||||
requests = g_slist_append (requests, info);
|
||||
nm_log_dbg (LOGD_DISPATCH, "ignoring request; no scripts in " NMD_SCRIPT_DIR);
|
||||
return info;
|
||||
}
|
||||
|
||||
g_connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ());
|
||||
proxy = dbus_g_proxy_new_for_name (g_connection,
|
||||
NM_DISPATCHER_DBUS_SERVICE,
|
||||
|
|
@ -416,3 +442,32 @@ nm_dispatcher_call_cancel (gconstpointer call)
|
|||
((DispatchInfo *) call)->callback = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
dispatcher_dir_changed (GFileMonitor *monitor)
|
||||
{
|
||||
GDir *dir;
|
||||
|
||||
/* Default to dispatching on any errors */
|
||||
do_dispatch = TRUE;
|
||||
dir = g_dir_open (NMD_SCRIPT_DIR, 0, NULL);
|
||||
if (dir) {
|
||||
do_dispatch = !!g_dir_read_name (dir);
|
||||
g_dir_close (dir);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nm_dispatcher_init (void)
|
||||
{
|
||||
GFile *file;
|
||||
static GFileMonitor *monitor;
|
||||
|
||||
file = g_file_new_for_path (NMD_SCRIPT_DIR);
|
||||
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
if (monitor) {
|
||||
g_signal_connect (monitor, "changed", G_CALLBACK (dispatcher_dir_changed), NULL);
|
||||
dispatcher_dir_changed (monitor);
|
||||
}
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,4 +61,6 @@ gconstpointer nm_dispatcher_call_vpn (DispatcherAction action,
|
|||
|
||||
void nm_dispatcher_call_cancel (gconstpointer call);
|
||||
|
||||
void nm_dispatcher_init (void);
|
||||
|
||||
#endif /* NM_DISPATCHER_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue