Message ID | 8f4469febaaf5c48afdf13a6c88e959956c0f204.1733414906.git.mprivozn@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | qga: Open channel before going daemon | expand |
On Thu, Dec 5, 2024 at 6:19 PM Michal Privoznik <mprivozn@redhat.com> wrote: > After previous commits, run_agent_once() can't return anything > else but EXIT_SUCCESS. Transitionally, run_agent() can't return > anything else but EXIT_SUCCESS too. There's not much value in > having these function return an integer. Make them return void. > > Signed-off-by: Michal Privoznik <mprivozn@redhat.com> > Reviewed-by: Ján Tomko <jtomko@redhat.com> > --- > qga/main.c | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > > diff --git a/qga/main.c b/qga/main.c > index 35f061b5ea..346274f114 100644 > --- a/qga/main.c > +++ b/qga/main.c > @@ -145,7 +145,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD > type, LPVOID data, > DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data); > VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); > #endif > -static int run_agent(GAState *s); > +static void run_agent(GAState *s); > static void stop_agent(GAState *s, bool requested); > > static void > @@ -1521,7 +1521,7 @@ static void cleanup_agent(GAState *s) > ga_state = NULL; > } > > -static int run_agent_once(GAState *s) > +static void run_agent_once(GAState *s) > { > if (!s->channel && > channel_init(s, s->config->method, s->config->channel_path, > @@ -1536,8 +1536,6 @@ static int run_agent_once(GAState *s) > run_agent_once return EXIT_FAILURE when channel_init fails, so we have compilation issue ../qga/main.c: In function ‘run_agent_once’: ../qga/main.c:1530:16: error: ‘return’ with a value, in function returning void [-Wreturn-mismatch] 1530 | return EXIT_FAILURE; | ^~~~~~~~~~~~ ../qga/main.c:1524:13: note: declared here 1524 | static void run_agent_once(GAState *s) | ^~~~~~~~~~~~~~ ninja: build stopped: subcommand failed. As on Windows, we will really reinitialize the channel, I think, we need to get the real exit code. If initialization fails and the service gets a stop request we will see in Windows Events information that the service crashed. > ga_channel_free(s->channel); > s->channel = NULL; > } > - > - return EXIT_SUCCESS; > } > > static void wait_for_channel_availability(GAState *s) > @@ -1561,21 +1559,17 @@ static void wait_for_channel_availability(GAState > *s) > #endif > } > > -static int run_agent(GAState *s) > +static void run_agent(GAState *s) > { > - int ret = EXIT_SUCCESS; > - > s->force_exit = false; > > do { > - ret = run_agent_once(s); > + run_agent_once(s); > if (s->config->retry_path && !s->force_exit) { > g_warning("agent stopped unexpectedly, restarting..."); > wait_for_channel_availability(s); > } > } while (s->config->retry_path && !s->force_exit); > - > - return ret; > } > > static void stop_agent(GAState *s, bool requested) > @@ -1674,14 +1668,15 @@ int main(int argc, char **argv) > SERVICE_TABLE_ENTRY service_table[] = { > { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; > StartServiceCtrlDispatcher(service_table); > - ret = EXIT_SUCCESS; > } else { > - ret = run_agent(s); > + run_agent(s); > } > #else > - ret = run_agent(s); > + run_agent(s); > #endif > > + ret = EXIT_SUCCESS; > + > cleanup_agent(s); > > end: > -- > 2.45.2 > >
diff --git a/qga/main.c b/qga/main.c index 35f061b5ea..346274f114 100644 --- a/qga/main.c +++ b/qga/main.c @@ -145,7 +145,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data, DWORD WINAPI handle_serial_device_events(DWORD type, LPVOID data); VOID WINAPI service_main(DWORD argc, TCHAR *argv[]); #endif -static int run_agent(GAState *s); +static void run_agent(GAState *s); static void stop_agent(GAState *s, bool requested); static void @@ -1521,7 +1521,7 @@ static void cleanup_agent(GAState *s) ga_state = NULL; } -static int run_agent_once(GAState *s) +static void run_agent_once(GAState *s) { if (!s->channel && channel_init(s, s->config->method, s->config->channel_path, @@ -1536,8 +1536,6 @@ static int run_agent_once(GAState *s) ga_channel_free(s->channel); s->channel = NULL; } - - return EXIT_SUCCESS; } static void wait_for_channel_availability(GAState *s) @@ -1561,21 +1559,17 @@ static void wait_for_channel_availability(GAState *s) #endif } -static int run_agent(GAState *s) +static void run_agent(GAState *s) { - int ret = EXIT_SUCCESS; - s->force_exit = false; do { - ret = run_agent_once(s); + run_agent_once(s); if (s->config->retry_path && !s->force_exit) { g_warning("agent stopped unexpectedly, restarting..."); wait_for_channel_availability(s); } } while (s->config->retry_path && !s->force_exit); - - return ret; } static void stop_agent(GAState *s, bool requested) @@ -1674,14 +1668,15 @@ int main(int argc, char **argv) SERVICE_TABLE_ENTRY service_table[] = { { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } }; StartServiceCtrlDispatcher(service_table); - ret = EXIT_SUCCESS; } else { - ret = run_agent(s); + run_agent(s); } #else - ret = run_agent(s); + run_agent(s); #endif + ret = EXIT_SUCCESS; + cleanup_agent(s); end: