summaryrefslogtreecommitdiff
path: root/SPICEConsoleAPI.cpp
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-10-02 22:50:46 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2012-10-02 23:10:06 +0200
commit8b47b54c7a08612c9c0fd6fa44d9d0ed46a85d83 (patch)
tree3d9f8dbcdc2b206a2f7e8219bf0ecb7c80a71075 /SPICEConsoleAPI.cpp
parent60c53563604bbf33096f968f1058c8d5f3750d6d (diff)
Move SPICEController::StartClient to SpiceController
This method is OS-specific, this commit moves it to SpiceController because this class has most of the OS-specific code.
Diffstat (limited to 'SPICEConsoleAPI.cpp')
-rw-r--r--SPICEConsoleAPI.cpp82
1 files changed, 2 insertions, 80 deletions
diff --git a/SPICEConsoleAPI.cpp b/SPICEConsoleAPI.cpp
index f2d6609..d617568 100644
--- a/SPICEConsoleAPI.cpp
+++ b/SPICEConsoleAPI.cpp
@@ -34,8 +34,6 @@
* ***** END LICENSE BLOCK ***** */
#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
#include <glib.h>
@@ -91,57 +89,6 @@ bool SPICEConsoleAPI::initSocket(void)
return true;
}
-bool SPICEConsoleAPI::startClient(void)
-{
- /* use a pipe for the children to wait until it gets tracked */
- int pipe_fds[2] = { -1, -1 };
- if (pipe(pipe_fds) < 0) {
- perror("spice-xpi system error");
- return false;
- }
-
- m_pid_controller = fork();
- if (m_pid_controller == 0)
- {
- setpgrp();
-
- close(pipe_fds[1]);
- pipe_fds[1] = -1;
-
- char c;
- if (read(pipe_fds[0], &c, 1) != 0)
- g_critical("Error while reading on pipe: %s", g_strerror(errno));
-
- close(pipe_fds[0]);
- pipe_fds[0] = -1;
-
- execl("/usr/libexec/spice-xpi-client", "/usr/libexec/spice-xpi-client", NULL);
- g_message("failed to run spice-xpi-client, running spicec instead");
-
- // TODO: temporary fallback for backward compatibility
- execl("/usr/bin/spicec", "/usr/bin/spicec", "--controller", NULL);
- g_critical("ERROR failed to run spicec fallback");
-
- exit(EXIT_FAILURE);
- }
- else
- {
- g_debug("child pid: %"G_GUINT64_FORMAT, (guint64)m_pid_controller);
-
- close(pipe_fds[0]);
- pipe_fds[0] = -1;
-
- pthread_t controller_thread_id;
- pthread_create(&controller_thread_id, NULL, ControllerWaitHelper,
- reinterpret_cast<void*>(this));
-
- close(pipe_fds[1]);
- pipe_fds[1] = -1;
-
- return true;
- }
-}
-
bool SPICEConsoleAPI::createTrustStore(void)
{
// create trust store filename
@@ -215,7 +162,7 @@ void SPICEConsoleAPI::connect()
return;
}
- if (!this->startClient()) {
+ if (!m_external_controller.StartClient()) {
g_critical("failed to start SPICE client");
return;
}
@@ -270,8 +217,7 @@ void SPICEConsoleAPI::show()
void SPICEConsoleAPI::disconnect()
{
- if (m_pid_controller > 0)
- kill(-m_pid_controller, SIGTERM);
+ m_external_controller.StopClient();
}
void SPICEConsoleAPI::SetLanguageStrings(const std::string &section,
@@ -389,27 +335,3 @@ template<typename T> void SPICEConsoleAPI::SendValue(uint32_t id,
}
SendMsg(id, value);
}
-
-void *SPICEConsoleAPI::ControllerWaitHelper(void *opaque)
-{
- SPICEConsoleAPI *fake_this = reinterpret_cast<SPICEConsoleAPI *>(opaque);
- if (!fake_this)
- return NULL;
-
- int exit_code;
- waitpid(fake_this->m_pid_controller, &exit_code, 0);
- g_debug("child finished, pid: %"G_GUINT64_FORMAT, (guint64)exit_code);
-
- fake_this->m_connected_status = fake_this->m_external_controller.TranslateRC(exit_code);
- if (!getenv("SPICE_XPI_DEBUG"))
- {
- fake_this->fire_disconnected(exit_code);
- fake_this->m_external_controller.Disconnect();
- }
-
- unlink(fake_this->m_trust_store_file.c_str());
- fake_this->m_trust_store_file.clear();
- fake_this->m_pid_controller = -1;
- return NULL;
-}
-