]> git.giacomolli.uk - onechat/commitdiff
Exit with status 0 when a signal stops the daemon
authorAnderson A. Giacomolli <agiacomolli@gmail.com>
Sat, 7 Nov 2026 02:53:53 +0000 (23:53 -0300)
committerAnderson A. Giacomolli <agiacomolli@gmail.com>
Sat, 7 Nov 2026 02:53:53 +0000 (23:53 -0300)
A signal is the normal stop of the daemon and of the terminal client, so
both exit with status 0 and print no error after Ctrl-C or SIGTERM. The
other commands still report a canceled context, because a signal there
stops an operation before it is done.

Issue: 5daf23e

main.go

diff --git a/main.go b/main.go
index 680c58d9a1c3884b5f8bab7bc8ef04d3874ee12c..9bc69d1dcdfb40213805d98920bc4b007efd3210 100644 (file)
--- a/main.go
+++ b/main.go
@@ -33,16 +33,12 @@ func run() error {
                if err != nil {
                        return err
                }
                if err != nil {
                        return err
                }
+       // A signal is the normal stop of the daemon and the client, so their
+       // result does not include ctx.Err().
        case len(args) == 1 && args[0] == "daemon":
        case len(args) == 1 && args[0] == "daemon":
-               err := daemon(ctx, os.Stdout)
-               if err != nil {
-                       return err
-               }
+               return daemon(ctx, os.Stdout)
        case len(args) == 1 && args[0] == "chat":
        case len(args) == 1 && args[0] == "chat":
-               err := chat(ctx, os.Stdin, os.Stdout)
-               if err != nil {
-                       return err
-               }
+               return chat(ctx, os.Stdin, os.Stdout)
        case len(args) > 0 && args[0] == "probe":
                err := probe(ctx, args[1:], os.Stdout)
                if err != nil {
        case len(args) > 0 && args[0] == "probe":
                err := probe(ctx, args[1:], os.Stdout)
                if err != nil {