This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 323128551da134e7528feefd4e1999fa126c0f00 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Jan 15 07:03:32 2020 +0100 src/x2goclient-network-ssh.c: initial rework to use the GSubProcess API for connections, implement basic NULL initialization and cleanup functions. --- src/x2goclient-network-ssh.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 0056ed7..28e1294 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -90,6 +90,7 @@ struct _X2GoClientNetworkSSH { X2GoClientNetwork parent_instance; char *control_path; + GSubprocess *master_conn; }; G_DEFINE_TYPE (X2GoClientNetworkSSH, x2goclient_network_ssh, X2GOCLIENT_TYPE_NETWORK); @@ -97,6 +98,7 @@ G_DEFINE_TYPE (X2GoClientNetworkSSH, x2goclient_network_ssh, X2GOCLIENT_TYPE_NET static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetwork *parent, const GString *sockspec); static gboolean x2goclient_network_ssh_parent_connect (X2GoClientNetwork *parent, GError **gerr); +static gboolean x2goclient_network_ssh_kill_subprocesses (X2GoClientNetworkSSH *self); static void x2goclient_network_ssh_class_init (X2GoClientNetworkSSHClass *klass) { @@ -109,6 +111,7 @@ static void x2goclient_network_ssh_class_init (X2GoClientNetworkSSHClass *klass) static void x2goclient_network_ssh_init (X2GoClientNetworkSSH *self) { self->control_path = NULL; + self->master_conn = NULL; } X2GoClientNetworkSSH* x2goclient_network_ssh_new (const char *session_path) { @@ -149,6 +152,10 @@ static void x2goclient_network_ssh_finalize (GObject *object) { g_free (self->control_path); self->control_path = NULL; + if (!(x2goclient_network_ssh_kill_subprocesses (self))) { + g_log (NULL, G_LOG_LEVEL_CRITICAL, "Some subprocesses were not terminated correctly!"); + } + (G_OBJECT_CLASS (x2goclient_network_ssh_parent_class))->finalize (object); } @@ -559,6 +566,46 @@ static GSocketAddress* x2goclient_network_ssh_parse_sockspec (X2GoClientNetwork return ret; } +static gboolean x2goclient_network_ssh_kill_subprocesses (X2GoClientNetworkSSH *self) { + gboolean ret = FALSE; + + g_return_val_if_fail (X2GOCLIENT_IS_NETWORK_SSH (self), ret); + + if (self->master_conn) { + /* Cleanup, if necessary. */ + g_subprocess_force_exit (self->master_conn); + + 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 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); + + g_clear_error (&wait_error); + } + + 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."); + } + + g_object_unref (self->master_conn); + self->master_conn = NULL; + + ret = TRUE; + } + + return (ret); +} + gboolean x2goclient_network_ssh_connect (X2GoClientNetworkSSH *self, GError **gerr) { gboolean ret = FALSE; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git