summary refs log tree commit diff stats
path: root/qga/main.c
diff options
context:
space:
mode:
authorMichael Roth <mdroth@linux.vnet.ibm.com>2018-10-07 14:02:19 +0300
committerMichael Roth <mdroth@linux.vnet.ibm.com>2018-10-31 09:04:20 -0500
commitd88495a864011139683e62fb7f84db93c7b51881 (patch)
tree9f472d65107489fe69372273374d00be9d072915 /qga/main.c
parent0f4d3a4912d1ca6585409b92d1d7fefb8baf60fa (diff)
downloadfocaccia-qemu-d88495a864011139683e62fb7f84db93c7b51881.tar.gz
focaccia-qemu-d88495a864011139683e62fb7f84db93c7b51881.zip
qga: move w32 service handling out of run_agent()
Eventually we want a w32 service to be able to restart the qga main
loop from within service_main(). To allow for this we move service
handling out of run_agent() such that service_main() calls
run_agent() instead of the reverse.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Bishara AbuHattoum <bishara@daynix.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/main.c')
-rw-r--r--qga/main.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/qga/main.c b/qga/main.c
index eb31f99b38..761007deb4 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -119,6 +119,7 @@ DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
                                   LPVOID ctx);
 VOID WINAPI service_main(DWORD argc, TCHAR *argv[]);
 #endif
+static int run_agent(GAState *s);
 
 static void
 init_dfl_pathnames(void)
@@ -712,7 +713,7 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[])
     service->status.dwWaitHint = 0;
     SetServiceStatus(service->status_handle, &service->status);
 
-    g_main_loop_run(ga_state->main_loop);
+    run_agent(ga_state);
 
     service->status.dwCurrentState = SERVICE_STOPPED;
     SetServiceStatus(service->status_handle, &service->status);
@@ -1340,17 +1341,8 @@ static int run_agent(GAState *s)
         g_critical("failed to initialize guest agent channel");
         return EXIT_FAILURE;
     }
-#ifndef _WIN32
+
     g_main_loop_run(ga_state->main_loop);
-#else
-    if (s->config->daemonize) {
-        SERVICE_TABLE_ENTRY service_table[] = {
-            { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
-        StartServiceCtrlDispatcher(service_table);
-    } else {
-        g_main_loop_run(ga_state->main_loop);
-    }
-#endif
 
     return EXIT_SUCCESS;
 }
@@ -1436,7 +1428,19 @@ int main(int argc, char **argv)
         g_critical("error initializing guest agent");
         goto end;
     }
+
+#ifdef _WIN32
+    if (config->daemonize) {
+        SERVICE_TABLE_ENTRY service_table[] = {
+            { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
+        StartServiceCtrlDispatcher(service_table);
+    } else {
+        ret = run_agent(s);
+    }
+#else
     ret = run_agent(s);
+#endif
+
     cleanup_agent(s);
 
 end: