The SPICE client paths will be different on Windows and Unix so add a helper function returning the paths to use to spawn the clients. --- SpiceXPI/src/plugin/controller-unix.cpp | 66 ++++++++++++++++++++++++--------- SpiceXPI/src/plugin/controller.h | 1 + 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/SpiceXPI/src/plugin/controller-unix.cpp b/SpiceXPI/src/plugin/controller-unix.cpp index 504a8ef..743e00b 100644 --- a/SpiceXPI/src/plugin/controller-unix.cpp +++ b/SpiceXPI/src/plugin/controller-unix.cpp @@ -139,6 +139,20 @@ int SpiceController::Connect(const int nRetries) return rc; } +void SpiceController::GetClientPaths(GStrv *client_argv, GStrv *fallback_argv) +{ + if (client_argv != NULL) { + *client_argv = g_new0(char *, 2); + (*client_argv)[0] = g_strdup("/usr/libexec/spice-xpi-client"); + } + + if (fallback_argv != NULL) { + *client_argv = g_new0(char *, 3); + (*client_argv)[0] = g_strdup("/usr/bin/spicec"); + (*client_argv)[1] = g_strdup("--controller"); + } +} + void SpiceController::SetupControllerPipe(GStrv &env) { std::string socket_file(this->m_tmp_dir); @@ -209,42 +223,58 @@ void SpiceController::WaitForPid(GPid pid) gpointer SpiceController::ClientThread(gpointer data) { - char *spice_xpi_argv[] = { "/usr/libexec/spice-xpi-client", NULL }; SpiceController *fake_this = (SpiceController *)data; gchar **env = g_get_environ(); GPid pid; - gboolean spawned; + gboolean spawned = FALSE; GError *error = NULL; + GStrv client_argv; + GStrv fallback_argv; + fake_this->GetClientPaths(&client_argv, &fallback_argv); + { + char *argv_str = g_strjoinv(" ", client_argv); + g_warning("main client cmdline: %s", argv_str); + g_free(argv_str); + argv_str = g_strjoinv(" ", fallback_argv); + g_warning("fallback client cmdline: %s", argv_str); + g_free(argv_str); + } fake_this->SetupControllerPipe(env); if (!fake_this->m_proxy.empty()) env = g_environ_setenv(env, "SPICE_PROXY", fake_this->m_proxy.c_str(), TRUE); - spawned = g_spawn_async(NULL, - spice_xpi_argv, env, - G_SPAWN_DO_NOT_REAP_CHILD, - NULL, NULL, /* child_func, child_arg */ - &pid, &error); - if (error != NULL) { - g_warning("failed to start spice-xpi-client: %s", error->message); - g_clear_error(&error); + if (client_argv != NULL) { + spawned = g_spawn_async(NULL, + client_argv, env, + G_SPAWN_DO_NOT_REAP_CHILD, + NULL, NULL, /* child_func, child_arg */ + &pid, &error); + if (error != NULL) { + g_warning("failed to start %s: %s", client_argv[0], error->message); + g_warn_if_fail(spawned == FALSE); + g_clear_error(&error); + } } - if (!spawned) { + if (!spawned && (fallback_argv != NULL)) { // TODO: temporary fallback for backward compatibility - char *spicec_argv[] = { "/usr/bin/spicec", "--controller", NULL }; - g_message("failed to run spice-xpi-client, running spicec instead"); - spawned = g_spawn_async(NULL, spicec_argv, env, + g_message("failed to run preferred client, running fallback client instead"); + spawned = g_spawn_async(NULL, fallback_argv, env, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, /* child_func, child_arg */ &pid, &error); - } - if (error != NULL) { - g_warning("failed to start spice-xpi-client: %s", error->message); - g_clear_error(&error); + if (error != NULL) { + g_warning("failed to start %s: %s", fallback_argv[0], error->message); + g_warn_if_fail(spawned == FALSE); + g_clear_error(&error); + } } g_strfreev(env); + g_strfreev(client_argv); + g_strfreev(fallback_argv); + if (!spawned) { g_critical("ERROR failed to run spicec fallback"); return NULL; diff --git a/SpiceXPI/src/plugin/controller.h b/SpiceXPI/src/plugin/controller.h index f47a921..de4516c 100644 --- a/SpiceXPI/src/plugin/controller.h +++ b/SpiceXPI/src/plugin/controller.h @@ -90,6 +90,7 @@ private: int Connect(); void WaitForPid(GPid pid); void SetupControllerPipe(GStrv &env); + void GetClientPaths(GStrv *client_argv, GStrv *fallback_argv); static void ChildExited(GPid pid, gint status, gpointer user_data); static gpointer ClientThread(gpointer data); -- 1.8.1.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel