diff options
-rw-r--r-- | client/gdaemonvfs.c | 3 | ||||
-rw-r--r-- | common/gvfsutils.c | 46 | ||||
-rw-r--r-- | common/gvfsutils.h | 1 | ||||
-rw-r--r-- | monitor/proxy/gproxyvolumemonitor.c | 3 |
4 files changed, 51 insertions, 2 deletions
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c index caf846a5..8a91570f 100644 --- a/client/gdaemonvfs.c +++ b/client/gdaemonvfs.c @@ -40,6 +40,7 @@ #include <glib/gi18n-lib.h> #include <glib/gstdio.h> #include <gvfsdbus.h> +#include "gvfsutils.h" typedef struct { char *type; @@ -1501,7 +1502,7 @@ g_io_module_load (GIOModule *module) * without spawning private dbus instances. * See bug 526454. */ - if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) + if (!gvfs_have_session_bus ()) return; /* Make this module resident so that we ground the common diff --git a/common/gvfsutils.c b/common/gvfsutils.c index 87718f30..47c31176 100644 --- a/common/gvfsutils.c +++ b/common/gvfsutils.c @@ -21,8 +21,15 @@ #include <string.h> #include <glib.h> +#include <glib/gstdio.h> #include "gvfsutils.h" +#ifdef G_OS_UNIX +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> +#endif + /** * gvfs_randomize_string: * @str: the string to randomize @@ -40,3 +47,42 @@ gvfs_randomize_string (char *str, for (i = 0; i < len; i++) str[i] = chars[g_random_int_range (0, strlen(chars))]; } + +/** + * gvfs_have_session_bus: + * + * Returns: %TRUE if we can connect to a session or user bus without + * triggering X11 autolaunching. + */ +gboolean +gvfs_have_session_bus (void) +{ + if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") != NULL) + return TRUE; + +#ifdef G_OS_UNIX + { + gboolean ret = FALSE; + gchar *bus; + GStatBuf buf; + + bus = g_build_filename (g_get_user_runtime_dir (), "bus", NULL); + + if (g_stat (bus, &buf) < 0) + goto out; + + if (buf.st_uid != geteuid ()) + goto out; + + if ((buf.st_mode & S_IFMT) != S_IFSOCK) + goto out; + + ret = TRUE; +out: + g_free (bus); + return ret; + } +#else + return FALSE; +#endif +} diff --git a/common/gvfsutils.h b/common/gvfsutils.h index aa7faf5e..edac0b07 100644 --- a/common/gvfsutils.h +++ b/common/gvfsutils.h @@ -24,6 +24,7 @@ G_BEGIN_DECLS void gvfs_randomize_string (char *str, int len); +gboolean gvfs_have_session_bus (void); G_END_DECLS diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c index a7466f0e..d2585464 100644 --- a/monitor/proxy/gproxyvolumemonitor.c +++ b/monitor/proxy/gproxyvolumemonitor.c @@ -45,6 +45,7 @@ #include "gvfsmonitorimpl.h" #include "gvfsdbus.h" #include "gvfsdaemonprotocol.h" +#include "gvfsutils.h" G_LOCK_DEFINE_STATIC(proxy_vm); @@ -1412,7 +1413,7 @@ g_proxy_volume_monitor_setup_session_bus_connection (void) * without spawning private dbus instances. * See bug 526454. */ - if (g_getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) + if (!gvfs_have_session_bus ()) return FALSE; if (the_volume_monitors == NULL) |