]> nmode's Git Repositories - signal-cli/commitdiff
Extend shutdown request with optional error
authorAsamK <asamk@gmx.de>
Sun, 29 Jun 2025 09:16:32 +0000 (11:16 +0200)
committerAsamK <asamk@gmx.de>
Sun, 29 Jun 2025 09:22:30 +0000 (11:22 +0200)
src/main/java/org/asamk/signal/Shutdown.java
src/main/java/org/asamk/signal/commands/DaemonCommand.java

index a59497c9e46a17ec360d295dfcbf2f4e2674b9a9..c51c12e465c8817e6e8f9d5a259c1e811811f5c6 100644 (file)
@@ -1,5 +1,6 @@
 package org.asamk.signal;
 
+import org.asamk.signal.commands.exceptions.CommandException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -11,7 +12,7 @@ import sun.misc.Signal;
 public class Shutdown {
 
     private static final Logger logger = LoggerFactory.getLogger(Shutdown.class);
-    private static final CompletableFuture<Void> shutdown = new CompletableFuture<>();
+    private static final CompletableFuture<Object> shutdown = new CompletableFuture<>();
     private static final CompletableFuture<Void> shutdownComplete = new CompletableFuture<>();
     private static boolean initialized = false;
 
@@ -43,9 +44,17 @@ public class Shutdown {
         shutdown.complete(null);
     }
 
-    public static void waitForShutdown() throws InterruptedException {
+    public static void triggerShutdown(CommandException exception) {
+        logger.debug("Triggering shutdown with exception.", exception);
+        shutdown.complete(exception);
+    }
+
+    public static void waitForShutdown() throws InterruptedException, CommandException {
         try {
-            shutdown.get();
+            final var result = shutdown.get();
+            if (result instanceof CommandException e) {
+                throw e;
+            }
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         }
index 197e1286ee80abb4b18124189e803ce279480d09..6790c65d5da5e1a8b8434869e927f4c4cf7f37a7 100644 (file)
@@ -97,7 +97,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
             final OutputWriter outputWriter
     ) throws CommandException {
         Shutdown.installHandler();
-        logger.info("Starting daemon in single-account mode for " + m.getSelfNumber());
+        logger.info("Starting daemon in single-account mode for {}", m.getSelfNumber());
         final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
         final var receiveMode = ns.<ReceiveMode>get("receive-mode");
         final var receiveConfig = getReceiveConfig(ns);