remove file at fifo logging location if it exists

Signed-off-by: Stijn Opheide <stijn@opheide.be>
This commit is contained in:
Stijn Opheide 2023-04-12 15:49:32 +02:00
parent eb81457111
commit 247d919a81
No known key found for this signature in database
GPG Key ID: 4289ED4534A90112

View File

@ -100,7 +100,14 @@ type remoteLog struct {
// Path returns the name of a FIFO connected to the logging daemon.
func (r *remoteLog) Path(n string) string {
path := filepath.Join(r.fifoDir, n+".log")
// replicate behavior of os.Create(path) for a fileLog.
// if a file exists at the given path, os.Create will truncate it.
// syscall.Mkfifo on the other hand fails when a file exists at the given path.
if _, err := os.Stat(path); err == nil {
os.Remove(path)
}
if err := syscall.Mkfifo(path, 0600); err != nil {
log.Printf("failed to create fifo %s: %s", path, err)
return "/dev/null"
}
go func() {