X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.cms.lib.dbus%2Fsrc%2Forg%2Fargeo%2Fcms%2Fdbus%2FCmsDBusImpl.java;h=cf939648af96e55c48439e3ec246b04bdbfac892;hp=b9a202be9d7d2ab3e581f60bc9080fcae52c38da;hb=a4e2def61f587de89a03037aec2b95c54732ec55;hpb=93832291a83666434bd589a0b3fd11f956224bfc diff --git a/org.argeo.cms.lib.dbus/src/org/argeo/cms/dbus/CmsDBusImpl.java b/org.argeo.cms.lib.dbus/src/org/argeo/cms/dbus/CmsDBusImpl.java index b9a202be9..cf939648a 100644 --- a/org.argeo.cms.lib.dbus/src/org/argeo/cms/dbus/CmsDBusImpl.java +++ b/org.argeo.cms.lib.dbus/src/org/argeo/cms/dbus/CmsDBusImpl.java @@ -19,6 +19,7 @@ public class CmsDBusImpl implements CmsDBus { private BusAddress sessionBusAddress; private EmbeddedDBusDaemon dBusDaemon; + private Path dBusDaemonSocket; private CmsEventBus cmsEventBus; @@ -27,8 +28,9 @@ public class CmsDBusImpl implements CmsDBus { final String envSessionBusAddress = System.getenv(DBUS_SESSION_BUS_ADDRESS); if (envSessionBusAddress != null) { sessionBusAddress = BusAddress.of(envSessionBusAddress); - - // !! We must first initialise a connection, otherwise there are classloader issues later on + + // !! We must first initialise a connection, otherwise there are classloader + // issues later on try (DBusConnection dBusConnection = DBusConnectionBuilder.forAddress(sessionBusAddress) .withShared(false).build()) { @@ -36,11 +38,15 @@ public class CmsDBusImpl implements CmsDBus { log.debug(() -> "Found session DBus with address " + sessionBusAddress); } else { Path socketLocation = Paths.get(System.getProperty("user.home"), ".cache", "argeo", "bus"); - Files.createDirectories(socketLocation.getParent()); - // TODO escape : on Windows? - String embeddedSessionBusAddress = "unix:path=" + socketLocation.toUri().getPath(); - dBusDaemon = new EmbeddedDBusDaemon(embeddedSessionBusAddress); + if (Files.exists(socketLocation)) + Files.delete(socketLocation); + else + Files.createDirectories(socketLocation.getParent()); + + String embeddedSessionBusAddress = "unix:path=" + socketLocation.toString(); + dBusDaemon = new EmbeddedDBusDaemon(embeddedSessionBusAddress + ",listen=true"); dBusDaemon.startInBackgroundAndWait(30 * 1000); + dBusDaemonSocket = socketLocation; sessionBusAddress = BusAddress.of(embeddedSessionBusAddress); try (DBusConnection dBusConnection = DBusConnectionBuilder.forAddress(sessionBusAddress) @@ -63,6 +69,11 @@ public class CmsDBusImpl implements CmsDBus { } catch (IOException e) { log.error("Cannot close embedded DBus daemon", e); } + try { + Files.delete(dBusDaemonSocket); + } catch (IOException e) { + log.error("Cannot delete DBus daemon socket " + dBusDaemonSocket, e); + } } }