mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Shut down when dbus daemon connection goes away unexpectedly
Fixes #1800
This commit is contained in:
parent
069325af47
commit
cb06cbdcca
1 changed files with 16 additions and 1 deletions
|
@ -1,17 +1,21 @@
|
||||||
package org.asamk.signal.dbus;
|
package org.asamk.signal.dbus;
|
||||||
|
|
||||||
import org.asamk.signal.DbusConfig;
|
import org.asamk.signal.DbusConfig;
|
||||||
|
import org.asamk.signal.Shutdown;
|
||||||
import org.asamk.signal.commands.exceptions.CommandException;
|
import org.asamk.signal.commands.exceptions.CommandException;
|
||||||
|
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.MultiAccountManager;
|
import org.asamk.signal.manager.MultiAccountManager;
|
||||||
|
import org.freedesktop.dbus.connections.IDisconnectCallback;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
|
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -94,7 +98,9 @@ public class DbusHandler implements AutoCloseable {
|
||||||
final var busType = isDbusSystem ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
|
final var busType = isDbusSystem ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
|
||||||
logger.debug("Starting DBus server on {} bus: {}", busType, busname);
|
logger.debug("Starting DBus server on {} bus: {}", busType, busname);
|
||||||
try {
|
try {
|
||||||
dBusConnection = DBusConnectionBuilder.forType(busType).build();
|
dBusConnection = DBusConnectionBuilder.forType(busType)
|
||||||
|
.withDisconnectCallback(new DisconnectCallback())
|
||||||
|
.build();
|
||||||
dbusRunner.run(dBusConnection);
|
dbusRunner.run(dBusConnection);
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e);
|
throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e);
|
||||||
|
@ -141,4 +147,13 @@ public class DbusHandler implements AutoCloseable {
|
||||||
|
|
||||||
void run(DBusConnection connection) throws DBusException;
|
void run(DBusConnection connection) throws DBusException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class DisconnectCallback implements IDisconnectCallback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnectOnError(IOException ex) {
|
||||||
|
logger.debug("DBus daemon disconnected unexpectedly, shutting down");
|
||||||
|
Shutdown.triggerShutdown(new IOErrorException("Unexpected dbus daemon disconnect", ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue