[gnome-keyring/wip/dueno/ssh-agent: 12/17] spawn async with pipes
- From: Daiki Ueno <dueno src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring/wip/dueno/ssh-agent: 12/17] spawn async with pipes
- Date: Wed, 13 Dec 2017 14:15:13 +0000 (UTC)
commit 0e441e4880667485dce094ae7ced8e28c197b3f0
Author: Stef Walter <stefw gnome org>
Date: Sat Feb 20 17:02:45 2016 +0100
spawn async with pipes
daemon/ssh-agent/gkd-ssh-agent-client.c | 44 ++++++++++++++++++++++++------
1 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/daemon/ssh-agent/gkd-ssh-agent-client.c b/daemon/ssh-agent/gkd-ssh-agent-client.c
index 9d5e8d5..d300307 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-client.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-client.c
@@ -24,6 +24,8 @@
#include "daemon/gkd-util.h"
+#include <glib-unix.h>
+
#include <sys/socket.h>
#include <sys/un.h>
@@ -32,6 +34,9 @@
static gchar *ssh_agent_path = NULL;
static GPid ssh_agent_pid;
+static gint ssh_agent_out = -1;
+static guint ssh_agent_watch;
+static gboolean ssh_agent_ready;
static GMutex ssh_agent_mutex;
static void
@@ -57,20 +62,38 @@ on_child_watch (GPid pid,
}
static gboolean
+agent_watch_output (gint fd,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ if (condition & G_IO_IN)
+ ssh_agent_ready = TRUE;
+
+ read xxxx;
+
+ ssh_agent_watch = 0;
+ return FALSE;
+}
+
+static gboolean
agent_start_inlock (const char *socket)
{
- const gchar *argv[] = { SSH_AGENT, "-d", "-a", socket, NULL };
+ const gchar *argv[] = { SSH_AGENT, "-s", "-a", socket, NULL };
GError *error = NULL;
GPid pid;
- if (!g_spawn_async ("/", (gchar **)argv, NULL,
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL,
- NULL, NULL, &pid, &error)) {
+ if (!g_spawn_sync ("/", (gchar **)argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, &pid, NULL, &ssh_agent_out, NULL, &error)) {
g_warning ("couldn't run %s: %s", SSH_AGENT, error->message);
g_error_free (error);
return FALSE;
}
+ ssh_agent_ready = FALSE;
+ ssh_agent_watch = g_unix_fd_add (ssh_agent_out,
+ G_IO_IN | G_IO_HUP | G_IO_ERR,
+ agent_watch_output, NULL);
+
ssh_agent_pid = pid;
g_child_watch_add (ssh_agent_pid, on_child_watch, NULL);
return TRUE;
@@ -91,9 +114,9 @@ agent_terminate (gint pid)
gint
gkd_ssh_agent_client_connect (void)
{
+ gboolean started = FALSE;
struct sockaddr_un addr;
const gchar *directory;
- gboolean ready;
gint sock;
g_mutex_lock (&ssh_agent_mutex);
@@ -103,16 +126,19 @@ gkd_ssh_agent_client_connect (void)
ssh_agent_path = g_build_filename (directory, "ssh-agent-real", NULL);
}
- ready = agent_check (ssh_agent_pid);
- if (!ready)
- ready = agent_start_inlock (ssh_agent_path);
+ ssh_agent_ready = agent_check (ssh_agent_pid);
+ if (!ssh_agent_ready)
+ started = agent_start_inlock (ssh_agent_path);
addr.sun_family = AF_UNIX;
g_strlcpy (addr.sun_path, ssh_agent_path, sizeof (addr.sun_path));
g_mutex_unlock (&ssh_agent_mutex);
- if (!ready)
+ while (started && !ssh_agent_ready)
+ g_main_context_iteration (NULL, TRUE);
+
+ if (!ssh_agent_ready)
return -1;
sock = socket (AF_UNIX, SOCK_STREAM, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]