This is an automated email from the git hooks/post-receive script. x2go pushed a change to branch master in repository libx2goclient. from 6c70ae1 src/x2goclient-network-ssh.c: optionally use x2goclient_network_options_ssh_to_array () to fetch options as a string array if an options object is set. new 3231285 src/x2goclient-network-ssh.c: initial rework to use the GSubProcess API for connections, implement basic NULL initialization and cleanup functions. new 2e1e4d7 src/x2goclient-network-ssh.c: re-implement master connection spawning via GSubprocess. The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Summary of changes: src/x2goclient-network-ssh.c | 84 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 13 deletions(-) -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git
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
This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository libx2goclient. commit 2e1e4d76fb92d7e0fe2fa06a502c2a4f69a693d4 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Jan 15 08:01:18 2020 +0100 src/x2goclient-network-ssh.c: re-implement master connection spawning via GSubprocess. Sadly, even that "fails" to work correctly with the forking/detaching ssh process. --- src/x2goclient-network-ssh.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/x2goclient-network-ssh.c b/src/x2goclient-network-ssh.c index 28e1294..502e7fb 100644 --- a/src/x2goclient-network-ssh.c +++ b/src/x2goclient-network-ssh.c @@ -796,30 +796,41 @@ static gboolean x2goclient_network_ssh_parent_connect (X2GoClientNetwork *parent g_printf ("\n"); g_printf ("Launching!\n"); - gint ssh_exit = -1; - gchar *ssh_stdout = NULL, *ssh_stderr = NULL; GError *ssh_err = NULL; - ret = g_spawn_sync (NULL, (gchar**)(ssh_cmd->pdata), NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &ssh_stdout, &ssh_stderr, &ssh_exit, &ssh_err); + self->master_conn = g_subprocess_newv ((const gchar* const*)(ssh_cmd->pdata), G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE, &ssh_err); + + ret = self->master_conn != NULL; if (ret) { - g_printf ("Process executed successfully!\nReturn value: %d\nStdout:\n>>>%s<<<\nStderr:\n>>>%s<<<\n", ssh_exit, ssh_stdout, ssh_stderr); + g_printf ("Process started/executed successfully!\n"); if (ssh_err) { g_printf ("Successful execution, but ssh_err set? Weird, here's the message: %s", ssh_err->message); } + + GCancellable *master_conn_comm_cancel = g_cancellable_new (); + g_clear_error (&ssh_err); + GBytes *ssh_stdout = NULL, *ssh_stderr = NULL; + if (!(g_subprocess_communicate (self->master_conn, NULL, master_conn_comm_cancel, &ssh_stdout, &ssh_stderr, &ssh_err))) { + g_log (NULL, G_LOG_LEVEL_CRITICAL, "Communication with master connection subprocess failed: %s", ssh_err->message); + } + else { + gsize ssh_stdout_size = 0, ssh_stderr_size = 0; + const gchar *ssh_stdout_str = g_bytes_get_data (ssh_stdout, &ssh_stdout_size), + *ssh_stderr_str = g_bytes_get_data (ssh_stderr, &ssh_stderr_size); + g_printf ("Stdout:\n>>>%.*s<<<\nStderr:\n>>>%.*s<<<\n", ssh_stdout_size, ssh_stdout_str, ssh_stderr_size, ssh_stderr_str); + + g_bytes_unref (ssh_stdout); + g_bytes_unref (ssh_stderr); + } + + g_clear_error (&ssh_err); } else { - g_printf ("Process didn't execute successfully!\nError:\n>>>%s<<<\n", ssh_err->message); + g_printf ("Process didn't execute/start successfully!\nError:\n>>>%s<<<\n", ssh_err->message); } - g_free (ssh_stdout); - ssh_stdout = NULL; - - g_free (ssh_stderr); - ssh_stderr = NULL; - - g_free (ssh_err); - ssh_err = NULL; + g_clear_error (&ssh_err); } g_free (session_path); -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/libx2goclient.git