]> git.giacomolli.uk - onechat/blobdiff - daemon.go
Show the user messages of the other clients
[onechat] / daemon.go
index 034cac7fdd43af811b70e84ed1aa203d6ab43c44..68073d0be5342b81eb0dc93203226cb0ee063954 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -34,6 +34,10 @@ const (
 
        // socketPathBytes is the longest path of a Unix socket on Linux.
        socketPathBytes = 107
+
+       // terminalSource is the source of the user messages from the clients of
+       // the socket.
+       terminalSource = "terminal"
 )
 
 // errTokensInUse tells that another onechat process uses the token file.
@@ -56,6 +60,14 @@ func daemon(ctx context.Context, out io.Writer) (err error) {
                return err
        }
 
+       // Check the socket path before the daemon writes a file, so that a data
+       // directory with a long path stays empty.
+       socket := filepath.Join(dir, socketFileName)
+       err = checkSocketPath(socket)
+       if err != nil {
+               return err
+       }
+
        config, err := loadConfig(dir)
        if err != nil {
                return err
@@ -90,7 +102,7 @@ func daemon(ctx context.Context, out io.Writer) (err error) {
                err = errors.Join(err, memory.Close())
        }()
 
-       listener, err := listenSocket(filepath.Join(dir, socketFileName))
+       listener, err := listenSocket(socket)
        if err != nil {
                return err
        }
@@ -297,7 +309,7 @@ func runRequest(l *loop, request clientRequest) error {
                        return errors.New("empty message")
                }
 
-               _, err := l.Submit(request.Text)
+               _, err := l.Submit(terminalSource, request.Text)
 
                return err
        case "interrupt":