Commit b871c1b3 authored by Mihai Moldovan's avatar Mihai Moldovan
Browse files

src/x2goclient-network-ssh.c: rewrite x2goclient_network_ssh_kill_subprocesses...

src/x2goclient-network-ssh.c: rewrite x2goclient_network_ssh_kill_subprocesses () to not kill an actual process but spawn an OpenSSH client process executing an exit command for the master connection.
parent d8ec4e0c
......@@ -699,40 +699,33 @@ static gboolean x2goclient_network_ssh_kill_subprocesses (X2GoClientNetworkSSH *
g_return_val_if_fail (X2GOCLIENT_IS_NETWORK_SSH (self), ret);
if (self->active_master_conn) {
/* FIXME: rework this code! */
/* Cleanup, if necessary. */
g_log (NULL, G_LOG_LEVEL_DEBUG, "Master connection cleanup required.");
g_subprocess_force_exit (self->master_conn);
GPtrArray *ssh_cmd = g_ptr_array_new_with_free_func (&x2goclient_clear_strings);
g_ptr_array_add (ssh_cmd, g_strdup ("ssh"));
GCancellable *wait_cancel = g_cancellable_new ();
GError *wait_error = NULL;
while (!(g_subprocess_wait (self->master_conn, wait_cancel, &wait_error))) {
* Try to wait for subprocess termination really hard.
* The wait call should only fail if the operation was cancelled, but
* given that we don't do that (explicitly), it should not occur in the
* first place.
g_log (NULL, G_LOG_LEVEL_CRITICAL, "Waiting on master connection subprocess termination was cancelled!\nError: %s\nThis should not have happened. Retrying.", wait_error->message);
/* Add control path options. */
g_ptr_array_add (ssh_cmd, g_strdup ("-o"));
g_ptr_array_add (ssh_cmd, g_strdup_printf ("ControlPath=\"%s\"", self->control_path));
g_clear_error (&wait_error);
/* Add master socket command. */
g_ptr_array_add (ssh_cmd, g_strdup ("-O"));
g_ptr_array_add (ssh_cmd, g_strdup ("exit"));
if (0 == g_subprocess_get_if_exited (self->master_conn)) {
gint exit_status = g_subprocess_get_exit_status (self->master_conn);
g_log (NULL, G_LOG_LEVEL_WARNING, "Master connection subprocess exited with an error; return code: %d", exit_status);
else {
g_log (NULL, G_LOG_LEVEL_MESSAGE, "Master connection subprocess exited successfully.");
ret = x2goclient_network_ssh_sshcmd_add_host_port (self, ssh_cmd, NULL);
g_object_unref (self->master_conn);
self->master_conn = NULL;
self->active_master_conn = FALSE;
if (ret) {
/* Zero-terminate. */
g_ptr_array_add (ssh_cmd, NULL);
ret = TRUE;
/* Okay, execute. */
x2goclient_network_ssh_gptrarray_print_debug (ssh_cmd, "Terminating master connection via:", "OpenSSH client command");
g_log (NULL, G_LOG_LEVEL_DEBUG, "Launching!");
ret = x2goclient_network_ssh_start_sshcmd (self, ssh_cmd, NULL, FALSE);
self->active_master_conn = (!(ret));
return (ret);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment