+ c.getManagers().forEach(m -> {
+ m.setIgnoreAttachments(ignoreAttachments);
+ addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
+ });
+ c.addOnManagerAddedHandler(m -> {
+ m.setIgnoreAttachments(ignoreAttachments);
+ addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
+ });
+
+ final Channel inheritedChannel;
+ try {
+ inheritedChannel = System.inheritedChannel();
+ if (inheritedChannel instanceof ServerSocketChannel serverChannel) {
+ logger.info("Using inherited socket: " + serverChannel.getLocalAddress());
+ runSocketMultiAccount(c, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ } catch (IOException e) {
+ throw new IOErrorException("Failed to use inherited socket", e);
+ }
+ final var socketFile = ns.<File>get("socket");
+ if (socketFile != null) {
+ final var address = UnixDomainSocketAddress.of(socketFile.toPath());
+ final var serverChannel = IOUtils.bindSocket(address);
+ runSocketMultiAccount(c, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ final var tcpAddress = ns.getString("tcp");
+ if (tcpAddress != null) {
+ final var address = IOUtils.parseInetSocketAddress(tcpAddress);
+ final var serverChannel = IOUtils.bindSocket(address);
+ runSocketMultiAccount(c, serverChannel, receiveMode == ReceiveMode.MANUAL);
+ }
+ final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
+ if (isDbusSystem) {
+ runDbusMultiAccount(c, receiveMode != ReceiveMode.ON_START, true);
+ }
+ final var isDbusSession = Boolean.TRUE.equals(ns.getBoolean("dbus"));
+ if (isDbusSession || (
+ !isDbusSystem
+ && socketFile == null
+ && tcpAddress == null
+ && !(inheritedChannel instanceof ServerSocketChannel)
+ )) {
+ runDbusMultiAccount(c, receiveMode != ReceiveMode.ON_START, false);
+ }
+
+ synchronized (this) {
+ try {
+ wait();
+ } catch (InterruptedException ignored) {
+ }