From b317e79b5ba36de27a3c525e96455206f3b27da9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 12 Jun 2014 12:52:56 +0200 Subject: [PATCH] dispatcher: improve debug logging for dispatcher callouts - ensure, that dispatcher_results_process() logs a line even if no scripts were run. This way we alyways know when the callout returns. - log a line when cancelling a dispatcher call Signed-off-by: Thomas Haller --- src/nm-dispatcher.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 2ddbf4900..73b2041dc 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -203,6 +203,12 @@ dispatcher_results_process (guint request_id, GPtrArray *results) g_return_if_fail (results != NULL); + if (results->len == 0) { + nm_log_dbg (LOGD_DISPATCH, "(%u) succeeded but no scripts invoked", + request_id); + return; + } + for (i = 0; i < results->len; i++) { GValueArray *item = g_ptr_array_index (results, i); GValue *tmp; @@ -221,8 +227,10 @@ dispatcher_results_process (guint request_id, GPtrArray *results) if (!validate_element (request_id, tmp, G_TYPE_STRING, i, 0)) continue; script = g_value_get_string (tmp); - if (!script || strncmp (script, NMD_SCRIPT_DIR_DEFAULT "/", STRLEN (NMD_SCRIPT_DIR_DEFAULT "/"))) - continue; + if (!script) + script = "(unknown)"; + else if (!strncmp (script, NMD_SCRIPT_DIR_DEFAULT "/", STRLEN (NMD_SCRIPT_DIR_DEFAULT "/"))) + script += STRLEN (NMD_SCRIPT_DIR_DEFAULT "/"), /* Result */ tmp = g_value_array_get_nth (item, 1); @@ -240,11 +248,11 @@ dispatcher_results_process (guint request_id, GPtrArray *results) if (result == DISPATCH_RESULT_SUCCESS) { nm_log_dbg (LOGD_DISPATCH, "(%u) %s succeeded", request_id, - script + STRLEN (NMD_SCRIPT_DIR_DEFAULT "/")); + script); } else { nm_log_warn (LOGD_DISPATCH, "(%u) %s failed (%s): %s", request_id, - script + STRLEN (NMD_SCRIPT_DIR_DEFAULT "/"), + script, dispatch_result_to_string (result), err ? err : ""); } @@ -356,15 +364,21 @@ _dispatcher_call (DispatcherAction action, /* All actions except 'hostname' require a device */ if (action == DISPATCHER_ACTION_HOSTNAME) { - nm_log_dbg (LOGD_DISPATCH, "(%u) dispatching action '%s'", - reqid, action_to_string (action)); + nm_log_dbg (LOGD_DISPATCH, "(%u) dispatching action '%s'%s", + reqid, action_to_string (action), + blocking + ? " (blocking)" + : (callback ? " (with callback)" : "")); } else { g_return_val_if_fail (NM_IS_DEVICE (device), FALSE); - nm_log_dbg (LOGD_DISPATCH, "(%u) (%s) dispatching action '%s'", + nm_log_dbg (LOGD_DISPATCH, "(%u) (%s) dispatching action '%s'%s", reqid, vpn_iface ? vpn_iface : nm_device_get_iface (device), - action_to_string (action)); + action_to_string (action), + blocking + ? " (blocking)" + : (callback ? " (with callback)" : "")); } /* VPN actions require at least an IPv4 config (for now) */ @@ -620,10 +634,13 @@ nm_dispatcher_call_cancel (guint call_id) * DispatcherInfo's callback to NULL. */ info = g_hash_table_lookup (requests, GUINT_TO_POINTER (call_id)); - if (info) + g_return_if_fail (info); + + if (info && info->callback) { + nm_log_dbg (LOGD_DISPATCH, "(%u) cancelling dispatcher callback action", + call_id); info->callback = NULL; - else - g_return_if_reached (); + } } typedef struct {