Control: tags 852815 patch On Fri, Jan 27, 2017 at 12:31:59PM -0500, James McCoy wrote: > On Fri, Jan 27, 2017 at 10:12:18AM -0500, James McCoy wrote: > > I've been using "nm-online -x -q" as a test condition for a cron job, > > and as of the update to 1.6.0-1, this always exits with 1 even when > > "nmcli general status" shows State=connected, Connectivity=full. > > > > "nm-online -q" appears to work correctly. > > In 1.4.4, nm-online would exit immediately when the state was a > connected state: > > if ( state == NM_STATE_CONNECTED_LOCAL > || state == NM_STATE_CONNECTED_SITE > || state == NM_STATE_CONNECTED_GLOBAL) { > g_object_unref (client); > return 0; > } > > However, in 1.6.0, the logic was moved to a separate function that's > called by the event loop and returns the status via the shared > OnlineData pointer. quit_if_connected executes the equivalent code from > above but doesn't from after doing so, therefore data->retval is > overwritten in the next branch. > > } else { > if ( state == NM_STATE_CONNECTED_LOCAL > || state == NM_STATE_CONNECTED_SITE > || state == NM_STATE_CONNECTED_GLOBAL) { > data->retval = 0; > g_main_loop_quit (data->loop); > } > } > if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) { > data->retval = 1; > g_main_loop_quit (data->loop); > }
Attached patch explicitly returns from quit_if_connected after setting retval. This fixes the behavior for me. Cheers, -- James GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7 2D23 DFE6 91AE 331B A3DB
>From 08a1996ccc79d639218b55ee749e90816d4aa651 Mon Sep 17 00:00:00 2001 From: James McCoy <james...@jamessan.com> Date: Fri, 27 Jan 2017 12:50:39 -0500 Subject: [PATCH] nm-online: Return from quit_if_connected after setting retval c5f17a97ea8e4cee85c93ee9cfa04057f83e13ab changed nm-online to determine the status asynchronously, however this introduced a regression with "nm-online -x -q" when there is connectivity. if ( state == NM_STATE_CONNECTED_LOCAL || state == NM_STATE_CONNECTED_SITE || state == NM_STATE_CONNECTED_GLOBAL) { data->retval = 0; g_main_loop_quit (data->loop); } } if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) { data->retval = 1; g_main_loop_quit (data->loop); } After setting data->retval = 0 in the "state is connected" branch, the function falls through to the "exit_no_nm and !connecting" branch, overwriting data->retval. This causes "nm-online -x -q" to incorrectly report an offline state. Adding an explicit "return;" after any state where data->retval is set ensures that the value isn't overwritten before main() uses it. --- clients/nm-online.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clients/nm-online.c b/clients/nm-online.c index 60ea41cba..c1df195aa 100644 --- a/clients/nm-online.c +++ b/clients/nm-online.c @@ -66,11 +66,13 @@ quit_if_connected (OnlineData *data) if (data->exit_no_nm) { data->retval = 1; g_main_loop_quit (data->loop); + return; } } else if (data->wait_startup) { if (!nm_client_get_startup (data->client)) { data->retval = 0; g_main_loop_quit (data->loop); + return; } } else { if ( state == NM_STATE_CONNECTED_LOCAL @@ -78,11 +80,13 @@ quit_if_connected (OnlineData *data) || state == NM_STATE_CONNECTED_GLOBAL) { data->retval = 0; g_main_loop_quit (data->loop); + return; } } if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) { data->retval = 1; g_main_loop_quit (data->loop); + return; } } -- 2.11.0