Improve error messages when daemon is already running

This commit is contained in:
AsamK 2022-02-13 20:08:02 +01:00
parent 90c787f8e2
commit ccce539843
3 changed files with 17 additions and 19 deletions

View file

@ -29,8 +29,8 @@ public class Commands {
addCommand(new RegisterCommand()); addCommand(new RegisterCommand());
addCommand(new RemoveContactCommand()); addCommand(new RemoveContactCommand());
addCommand(new RemoveDeviceCommand()); addCommand(new RemoveDeviceCommand());
addCommand(new RemoteDeleteCommand());
addCommand(new RemovePinCommand()); addCommand(new RemovePinCommand());
addCommand(new RemoteDeleteCommand());
addCommand(new SendCommand()); addCommand(new SendCommand());
addCommand(new SendContactsCommand()); addCommand(new SendContactsCommand());
addCommand(new SendReactionCommand()); addCommand(new SendReactionCommand());

View file

@ -340,41 +340,39 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
} else { } else {
busType = DBusConnection.DBusBusType.SESSION; busType = DBusConnection.DBusBusType.SESSION;
} }
DBusConnection conn;
try { try {
var conn = DBusConnection.getConnection(busType); conn = DBusConnection.getConnection(busType);
dbusRunner.run(conn, DbusConfig.getObjectPath()); dbusRunner.run(conn, DbusConfig.getObjectPath());
conn.requestBusName(DbusConfig.getBusname());
logger.info("DBus daemon running on {} bus: {}", busType, DbusConfig.getBusname());
} catch (DBusException e) { } catch (DBusException e) {
logger.error("Dbus command failed", e); throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e);
throw new UnexpectedErrorException("Dbus command failed", e);
} }
try {
conn.requestBusName(DbusConfig.getBusname());
} catch (DBusException e) {
throw new UnexpectedErrorException("Dbus command failed, maybe signal-cli dbus daemon is already running: "
+ e.getMessage(), e);
}
logger.info("DBus daemon running on {} bus: {}", busType, DbusConfig.getBusname());
} }
private Thread exportMultiAccountManager( private Thread exportMultiAccountManager(
final DBusConnection conn, final Manager m, final boolean noReceiveOnStart final DBusConnection conn, final Manager m, final boolean noReceiveOnStart
) { ) {
try { final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber()); return exportDbusObject(conn, objectPath, m, noReceiveOnStart);
return exportDbusObject(conn, objectPath, m, noReceiveOnStart);
} catch (DBusException e) {
logger.error("Failed to export object", e);
return null;
}
} }
private Thread exportDbusObject( private Thread exportDbusObject(
final DBusConnection conn, final String objectPath, final Manager m, final boolean noReceiveOnStart final DBusConnection conn, final String objectPath, final Manager m, final boolean noReceiveOnStart
) throws DBusException { ) {
final var signal = new DbusSignalImpl(m, conn, objectPath, noReceiveOnStart); final var signal = new DbusSignalImpl(m, conn, objectPath, noReceiveOnStart);
final var initThread = new Thread(signal::initObjects); final var initThread = new Thread(signal::initObjects);
initThread.setName("dbus-init"); initThread.setName("dbus-init");
initThread.start(); initThread.start();
logger.debug("Exported dbus object: " + objectPath);
return initThread; return initThread;
} }

View file

@ -136,7 +136,7 @@ public class IOUtils {
logger.info("Listening on socket: " + address); logger.info("Listening on socket: " + address);
postBind(address); postBind(address);
} catch (IOException e) { } catch (IOException e) {
throw new IOErrorException("Failed to bind socket: " + e.getMessage(), e); throw new IOErrorException("Failed to bind socket " + address + ": " + e.getMessage(), e);
} }
return serverChannel; return serverChannel;
} }