diff -up libbonobo-2.22.0/activation-server/activation-server-main.c.Share-ior-filename-getter-between-server-and-client libbonobo-2.22.0/activation-server/activation-server-main.c
--- libbonobo-2.22.0/activation-server/activation-server-main.c.Share-ior-filename-getter-between-server-and-client	2007-09-25 04:00:14.000000000 -0400
+++ libbonobo-2.22.0/activation-server/activation-server-main.c	2008-05-06 16:06:43.000000000 -0400
@@ -363,9 +363,7 @@ dump_ior (CORBA_ORB orb, int dev_null_fd
 #endif
         if (server_reg) {
                 char *fname;
-                fname = g_build_filename (ORBit_get_safe_tmp (),
-                                          "bonobo-activation-server-ior",
-                                          NULL);
+                fname = _bonobo_activation_ior_fname_get ();
                 fh = g_fopen (fname, "w+");
 		fprintf (fh, "%s\n", ior);
 		fclose (fh);
diff -up libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c.Share-ior-filename-getter-between-server-and-client libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c
--- libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c.Share-ior-filename-getter-between-server-and-client	2007-11-12 08:10:27.000000000 -0500
+++ libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c	2008-05-06 16:11:10.000000000 -0400
@@ -498,16 +498,16 @@ get_tmpdir (void)
         return tmpdir;
 }
 
-static char *
-get_lock_fname (void)
+char *
+_bonobo_activation_lock_fname_get (void)
 {
         return g_build_filename (get_tmpdir (),
                                  "bonobo-activation-register.lock",
                                  NULL);
 }
 
-static char *
-get_ior_fname (void)
+char *
+_bonobo_activation_ior_fname_get (void)
 {
         return g_build_filename (get_tmpdir (),
                                  "bonobo-activation-server-ior",
@@ -543,7 +543,7 @@ rloc_file_lock (const BonoboActivationBa
         int retval;
         char *err;
 
-        fn = get_lock_fname ();
+        fn = _bonobo_activation_lock_fname_get ();
 
 	while ((lock_fd = open (fn, O_CREAT | O_RDWR, 0700)) < 0) {
 
@@ -577,7 +577,7 @@ rloc_file_lock (const BonoboActivationBa
 
         g_free (fn);
 #elif defined (G_OS_WIN32)
-	char *fn = get_lock_fname ();
+	char *fn = _bonobo_activation_lock_fname_get ();
         wchar_t *wfn = g_utf8_to_utf16 (fn, -1, NULL, NULL, NULL);
         
 	while ((lock_fd = _wsopen (wfn, O_CREAT|O_RDWR|_O_SHORT_LIVED|_O_NOINHERIT, _SH_DENYRW, 0700)) < 0) {
@@ -630,7 +630,7 @@ rloc_file_check (const BonoboActivationB
 	FILE *fh;
 	char *fn;
 
-        fn = get_ior_fname ();
+        fn = _bonobo_activation_ior_fname_get ();
 	fh = g_fopen (fn, "r");
         g_free (fn);
 
@@ -662,7 +662,7 @@ rloc_file_register (const BonoboActivati
 	char *fn;
 	FILE *fh;
 
-        fn = get_ior_fname ();
+        fn = _bonobo_activation_ior_fname_get ();
 	fh = g_fopen (fn, "w");
 
         if (fh != NULL) {
@@ -681,7 +681,7 @@ rloc_file_unregister (const BonoboActiva
 {
 	char *fn;
 
-	g_unlink ((fn = get_ior_fname ()));
+	g_unlink ((fn = _bonobo_activation_ior_fname_get ()));
         g_free (fn);
 }
 
diff -up libbonobo-2.22.0/bonobo-activation/bonobo-activation-private.h.Share-ior-filename-getter-between-server-and-client libbonobo-2.22.0/bonobo-activation/bonobo-activation-private.h
--- libbonobo-2.22.0/bonobo-activation/bonobo-activation-private.h.Share-ior-filename-getter-between-server-and-client	2007-09-17 07:16:55.000000000 -0400
+++ libbonobo-2.22.0/bonobo-activation/bonobo-activation-private.h	2008-05-06 16:10:31.000000000 -0400
@@ -85,6 +85,9 @@ Bonobo_ActivationClient bonobo_activatio
     /* used only for unit testing */
 CORBA_char * _bonobo_activation_get_activation_env_value (const char *name);
 
+char * _bonobo_activation_ior_fname_get (void);
+char * _bonobo_activation_lock_fname_get (void);
+
 #ifdef G_OS_WIN32
 
 char *_bonobo_activation_win32_replace_prefix (const char *runtime_prefix,
diff -up libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c.Tie-activation-server-ior-and-lock-to-running-session libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c
--- libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c.Tie-activation-server-ior-and-lock-to-running-session	2008-05-06 16:13:40.000000000 -0400
+++ libbonobo-2.22.0/bonobo-activation/bonobo-activation-base-service.c	2008-05-06 16:16:07.000000000 -0400
@@ -498,20 +498,57 @@ get_tmpdir (void)
         return tmpdir;
 }
 
+static const char *
+get_session_guid (void)
+{
+        const char *session_bus_address;
+        const char *guid;
+
+        /* FIXME: we may want to use dbus-address.h functions here
+         */
+        session_bus_address = g_getenv ("DBUS_SESSION_BUS_ADDRESS");
+
+        if (session_bus_address == NULL)
+                return NULL;
+
+        guid = g_strrstr (session_bus_address, "guid=");
+
+        if (guid == NULL)
+                return NULL;
+
+        return guid + strlen ("guid=");
+}
+
 char *
 _bonobo_activation_lock_fname_get (void)
 {
-        return g_build_filename (get_tmpdir (),
-                                 "bonobo-activation-register.lock",
-                                 NULL);
+       const char *session_guid;
+
+       session_guid = get_session_guid ();
+
+       if (session_guid == NULL)
+               return g_build_filename (get_tmpdir (),
+                                        "bonobo-activation-register.lock",
+                                        NULL);
+
+       return g_strdup_printf ("%s" G_DIR_SEPARATOR_S "bonobo-activation-register-%s.lock",
+                               get_tmpdir (), session_guid);
 }
 
 char *
 _bonobo_activation_ior_fname_get (void)
 {
-        return g_build_filename (get_tmpdir (),
-                                 "bonobo-activation-server-ior",
-                                 NULL);
+       const char *session_guid;
+
+       session_guid = get_session_guid ();
+
+       if (session_guid == NULL)
+               return g_build_filename (get_tmpdir (),
+                                        "bonobo-activation-server-ior",
+                                        NULL);
+
+       return g_strdup_printf ("%s" G_DIR_SEPARATOR_S "bonobo-activation-server-%s-ior",
+                               get_tmpdir (), session_guid);
 }
 
 static void
diff -up libbonobo-2.22.0/activation-server/activation-server-main.c.Make-activation-server-exit-when-session-goes-away libbonobo-2.22.0/activation-server/activation-server-main.c
--- libbonobo-2.22.0/activation-server/activation-server-main.c.Make-activation-server-exit-when-session-goes-away	2008-05-03 22:50:47.000000000 -0400
+++ libbonobo-2.22.0/activation-server/activation-server-main.c	2008-05-03 22:50:47.000000000 -0400
@@ -54,6 +54,8 @@
 
 #include <glib/gstdio.h>
 
+#include <dbus/dbus-glib-lowlevel.h>
+
 static gboolean        server_threaded = FALSE;
 static glong           server_guard_depth = 0;
 static GStaticRecMutex server_guard = G_STATIC_REC_MUTEX_INIT;
@@ -373,6 +375,21 @@ dump_ior (CORBA_ORB orb, int dev_null_fd
 	CORBA_free (ior);
 }
 
+static DBusHandlerResult
+bus_message_handler (DBusConnection *connection,
+                     DBusMessage    *message,
+                     GMainLoop      *loop)
+{
+        if (dbus_message_is_signal (message,
+                                    DBUS_INTERFACE_LOCAL,
+                                    "Disconnected")) {
+                g_main_loop_quit (loop);
+                return DBUS_HANDLER_RESULT_HANDLED;
+        }
+
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -396,6 +413,8 @@ main (int argc, char *argv[])
 	const gchar                  *debug_output_env;
 #endif
 	GError                       *error = NULL;
+        DBusConnection               *connection;
+        DBusError                     bus_error;
 
 #ifdef HAVE_SETSID
         /*
@@ -533,6 +552,27 @@ main (int argc, char *argv[])
 
 	od_finished_internal_registration (); 
 
+        dbus_error_init (&bus_error);
+        connection = dbus_bus_get (DBUS_BUS_SESSION, &bus_error);
+
+        if (dbus_error_is_set (&bus_error)) {
+                g_warning ("could not associate with desktop session: %s",
+                           bus_error.message);
+                connection = NULL;
+        } else {
+                GMainContext *main_context;
+
+                main_context = g_main_loop_get_context (main_loop);
+                dbus_connection_setup_with_g_main (connection, main_context);
+
+                if (dbus_connection_add_filter (connection,
+                                                (DBusHandleMessageFunction)
+                                                bus_message_handler, main_loop,
+                                                NULL)) {
+                        dbus_connection_set_exit_on_disconnect (connection, FALSE);
+                }
+        }
+
         if (getenv ("BONOBO_ACTIVATION_DEBUG") == NULL)
                 chdir ("/");
 
--- libbonobo-2.22.0/configure.in	2008-05-06 15:04:30.000000000 -0400
+++ libbonobo-2.22.0/configure.in	2008-05-06 15:04:15.000000000 -0400
@@ -121,6 +121,8 @@
 	gmodule-2.0 >= 2.0.1 \
 	ORBit-2.0 >= 2.4.0 \
 	ORBit-CosNaming-2.0 >= 2.4.0 \
+	dbus-1 >= 1.0.0 \
+	dbus-glib-1 >= 0.74 \
 	libxml-2.0 >= 2.4.20)
 AC_SUBST(SERVER_LIBS)
 AC_SUBST(SERVER_CFLAGS)
diff -up libbonobo-2.22.0/activation-server/activation-server-main.c.clean-up-ior-on-exit libbonobo-2.22.0/activation-server/activation-server-main.c
--- libbonobo-2.22.0/activation-server/activation-server-main.c.clean-up-ior-on-exit	2008-05-06 16:17:27.000000000 -0400
+++ libbonobo-2.22.0/activation-server/activation-server-main.c	2008-05-06 16:43:53.000000000 -0400
@@ -375,6 +375,20 @@ dump_ior (CORBA_ORB orb, int dev_null_fd
 	CORBA_free (ior);
 }
 
+static void
+cleanup_ior_and_lock_files (void)
+{
+    char *fname;
+
+    fname = _bonobo_activation_ior_fname_get ();
+    g_unlink (fname);
+    g_free (fname);
+
+    fname = _bonobo_activation_lock_fname_get ();
+    g_unlink (fname);
+    g_free (fname);
+}
+
 static DBusHandlerResult
 bus_message_handler (DBusConnection *connection,
                      DBusMessage    *message,
@@ -588,6 +602,8 @@ main (int argc, char *argv[])
         bonobo_object_directory_shutdown (threaded_poa, ev);
         activation_context_shutdown ();
 
+        cleanup_ior_and_lock_files ();
+
 #ifdef HAVE_SYSLOG_H
 	closelog ();
 	g_free (syslog_ident);
