summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-08-08 15:12:06 +0200
committerStef Walter <stefw@gnome.org>2012-08-11 07:20:05 +0200
commit54459813dc5e5a2fe92ee404487d1e8d90da9917 (patch)
tree6c46ad56ed2a33357551083d2e7783a54a990683
parentc95d1520bcf23370afbc1933d9c67ceca82ca785 (diff)
downloadgnome-keyring-54459813dc5e5a2fe92ee404487d1e8d90da9917.tar.gz
daemon: Be quiet while replacing another daemon
* When doing --replace don't complain that the other daemon cannot be reached. It may have exited but we still want to use the environment it setup. https://bugzilla.gnome.org/show_bug.cgi?id=681449
-rw-r--r--daemon/control/gkd-control-client.c31
-rw-r--r--daemon/control/gkd-control.h7
-rw-r--r--daemon/control/tests/frob-control-quit.c2
-rw-r--r--daemon/gkd-main.c2
4 files changed, 27 insertions, 15 deletions
diff --git a/daemon/control/gkd-control-client.c b/daemon/control/gkd-control-client.c
index 70b80065..54e266e2 100644
--- a/daemon/control/gkd-control-client.c
+++ b/daemon/control/gkd-control-client.c
@@ -39,7 +39,8 @@
EGG_SECURE_DECLARE (control_client);
static int
-control_connect (const gchar *path)
+control_connect (const gchar *path,
+ GkdControlFlags flags)
{
struct sockaddr_un addr;
struct stat st;
@@ -47,7 +48,8 @@ control_connect (const gchar *path)
/* First a bunch of checks to make sure nothing funny is going on */
if (lstat (path, &st) < 0) {
- g_message ("couldn't access conrol socket: %s: %s", path, g_strerror (errno));
+ if (!(flags & GKD_CONTROL_QUIET_IF_NO_PEER) || errno != ENOENT)
+ g_message ("couldn't access conrol socket: %s: %s", path, g_strerror (errno));
return -1;
} else if (st.st_uid != geteuid ()) {
@@ -74,8 +76,9 @@ control_connect (const gchar *path)
fcntl (sock, F_SETFD, 1);
if (connect (sock, (struct sockaddr*) &addr, sizeof (addr)) < 0) {
- g_message ("couldn't connect to control socket at: %s: %s",
- addr.sun_path, g_strerror (errno));
+ if (!(flags & GKD_CONTROL_QUIET_IF_NO_PEER) || errno != ECONNREFUSED)
+ g_message ("couldn't connect to control socket at: %s: %s",
+ addr.sun_path, g_strerror (errno));
close (sock);
return -1;
}
@@ -163,14 +166,16 @@ control_read (int fd, EggBuffer *buffer)
}
static gboolean
-control_chat (const gchar *directory, EggBuffer *buffer)
+control_chat (const gchar *directory,
+ GkdControlFlags flags,
+ EggBuffer *buffer)
{
gboolean ret;
gchar *path;
int sock;
path = g_strdup_printf ("%s/control", directory);
- sock = control_connect (path);
+ sock = control_connect (path, flags);
g_free (path);
if (sock < 0)
@@ -201,7 +206,7 @@ gkd_control_initialize (const gchar *directory, const gchar *components,
g_return_val_if_fail (!egg_buffer_has_error (&buffer), FALSE);
- ret = control_chat (directory, &buffer);
+ ret = control_chat (directory, 0, &buffer);
if (ret)
ret = egg_buffer_get_uint32 (&buffer, offset, &offset, &res);
@@ -232,7 +237,7 @@ gkd_control_unlock (const gchar *directory, const gchar *password)
g_return_val_if_fail (!egg_buffer_has_error (&buffer), FALSE);
- ret = control_chat (directory, &buffer);
+ ret = control_chat (directory, 0, &buffer);
if (ret)
ret = egg_buffer_get_uint32 (&buffer, offset, &offset, &res);
@@ -265,7 +270,7 @@ gkd_control_change_lock (const gchar *directory, const gchar *original,
g_return_val_if_fail (!egg_buffer_has_error (&buffer), FALSE);
- ret = control_chat (directory, &buffer);
+ ret = control_chat (directory, 0, &buffer);
if (ret)
ret = egg_buffer_get_uint32 (&buffer, offset, &offset, &res);
@@ -281,7 +286,8 @@ gkd_control_change_lock (const gchar *directory, const gchar *original,
}
gboolean
-gkd_control_quit (const gchar *directory)
+gkd_control_quit (const gchar *directory,
+ GkdControlFlags flags)
{
EggBuffer buffer;
gsize offset = 4;
@@ -295,7 +301,7 @@ gkd_control_quit (const gchar *directory)
g_return_val_if_fail (!egg_buffer_has_error (&buffer), FALSE);
- ret = control_chat (directory, &buffer);
+ ret = control_chat (directory, flags, &buffer);
if (ret)
ret = egg_buffer_get_uint32 (&buffer, offset, &offset, &res);
@@ -303,7 +309,8 @@ gkd_control_quit (const gchar *directory)
egg_buffer_uninit (&buffer);
if (!ret || res != GKD_CONTROL_RESULT_OK) {
- g_message ("couldn't quit running keyring daemon");
+ if (!(flags & GKD_CONTROL_QUIET_IF_NO_PEER))
+ g_message ("couldn't quit running keyring daemon");
return FALSE;
}
diff --git a/daemon/control/gkd-control.h b/daemon/control/gkd-control.h
index 17dd0286..9ca227ff 100644
--- a/daemon/control/gkd-control.h
+++ b/daemon/control/gkd-control.h
@@ -24,6 +24,10 @@
#include <glib.h>
+typedef enum {
+ GKD_CONTROL_QUIET_IF_NO_PEER = 1 << 0,
+} GkdControlFlags;
+
gboolean gkd_control_listen (void);
gchar** gkd_control_initialize (const gchar *directory,
@@ -37,6 +41,7 @@ gboolean gkd_control_change_lock (const gchar *directory,
const gchar *original,
const gchar *password);
-gboolean gkd_control_quit (const gchar *directory);
+gboolean gkd_control_quit (const gchar *directory,
+ GkdControlFlags flags);
#endif /* __GKD_CONTROL_H__ */
diff --git a/daemon/control/tests/frob-control-quit.c b/daemon/control/tests/frob-control-quit.c
index 66261d73..a2ade3a7 100644
--- a/daemon/control/tests/frob-control-quit.c
+++ b/daemon/control/tests/frob-control-quit.c
@@ -17,7 +17,7 @@ main (int argc, char *argv[])
directory = g_getenv ("GNOME_KEYRING_CONTROL");
g_return_val_if_fail (directory, 1);
- if (!gkd_control_quit (directory))
+ if (!gkd_control_quit (directory, 0))
return 1;
g_printerr ("success quitting daemon\n");
diff --git a/daemon/gkd-main.c b/daemon/gkd-main.c
index da71da79..9da8a01b 100644
--- a/daemon/gkd-main.c
+++ b/daemon/gkd-main.c
@@ -588,7 +588,7 @@ replace_daemon_at (const gchar *directory)
g_free (control_directory);
control_directory = g_strdup (directory);
- ret = gkd_control_quit (directory);
+ ret = gkd_control_quit (directory, GKD_CONTROL_QUIET_IF_NO_PEER);
/*
* If we quit, wait a short time before initializing so the other