From d4b39a42ef9afdcfae916dd1ca2594538be854fd Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Fri, 27 Jul 2018 12:39:22 +0200 Subject: [PATCH] agent-manager: order newer agents befor the old one This is a mere debugging convenience thing: e.g. if you run, but want to check whether nm-applet or nmcli agent works fine, it's convenient that the agent you run later gets a chance to deal with the secrets requests first. Is seems to do the job and is simpler that adding some more complicated policy (e.g. introducing priorities or something). https://github.com/NetworkManager/NetworkManager/pull/174 --- src/settings/nm-agent-manager.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 1836a5e8f9..b6c14ae9f7 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -651,12 +651,14 @@ agent_compare_func (gconstpointer aa, gconstpointer bb, gpointer user_data) NMSessionMonitor *sm; gboolean a_active, b_active; gulong a_pid, b_pid, requester; + guint64 a_start, b_start; + + a_pid = nm_secret_agent_get_pid (a); + b_pid = nm_secret_agent_get_pid (b); /* Prefer agents in the process the request came from */ if (nm_auth_subject_is_unix_process (req->subject)) { requester = nm_auth_subject_get_unix_process_pid (req->subject); - a_pid = nm_secret_agent_get_pid (a); - b_pid = nm_secret_agent_get_pid (b); if (a_pid != b_pid) { if (a_pid == requester) @@ -672,11 +674,17 @@ agent_compare_func (gconstpointer aa, gconstpointer bb, gpointer user_data) b_active = nm_session_monitor_session_exists (sm, nm_secret_agent_get_owner_uid (b), TRUE); if (a_active && !b_active) return -1; - else if (a_active == b_active) - return 0; else if (!a_active && b_active) return 1; + /* Prefer agents launched later (this is essentially to ease agent debugging) */ + a_start = nm_utils_get_start_time_for_pid (a_pid, NULL, NULL); + b_start = nm_utils_get_start_time_for_pid (b_pid, NULL, NULL); + if (a_start > b_start) + return -1; + else if (a_start < b_start) + return 1; + return 0; }