harden and platformize FIFO handling
Reject a FIFO path that points to an existing non-FIFO object. Previously we removed whatever was at that path before creating the pipe, so pointing -fifo at a regular file silently deleted it. An existing FIFO is reused and only a missing path is created. Move the implementation into fifo_unix.go and fifo_windows.go. This lets the Unix build use syscall.Mkfifo directly, which is not available on Windows. Prevent the reader from endlessly spinning on a closed FIFO after an error. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c5baaae6a7
commit
4f41dd4ed6
@@ -3,17 +3,14 @@ package main
|
||||
import _ "net/http/pprof"
|
||||
import (
|
||||
"al.essio.dev/pkg/shellescape"
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
barnlog "git.stormux.org/storm/barnard/log"
|
||||
@@ -75,32 +72,6 @@ func setup_notify_runner(notify_command string) chan []string {
|
||||
return t
|
||||
}
|
||||
|
||||
func setup_fifo(fn string) (chan string, error) {
|
||||
t := make(chan string)
|
||||
if fn == "" {
|
||||
return t, nil
|
||||
}
|
||||
os.Remove(fn)
|
||||
err := syscall.Mkfifo(fn, 0600)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
file, err := os.OpenFile(fn, os.O_RDWR, os.ModeNamedPipe)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
go func(fh io.Reader, out chan string) {
|
||||
reader := bufio.NewReader(fh)
|
||||
for {
|
||||
line, err := reader.ReadBytes('\n')
|
||||
if err == nil {
|
||||
out <- strings.TrimSpace(string(line))
|
||||
}
|
||||
}
|
||||
}(file, t)
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Command line flags
|
||||
server := flag.String("server", "localhost:64738", "the server to connect to")
|
||||
|
||||
Reference in New Issue
Block a user