Skip to content

Commit

Permalink
Fix the build of spawn on windows after the syslog changes
Browse files Browse the repository at this point in the history
I forgot syslog doesn't exist on windows. Now we're providing a nil
io.WriteCloser to get code using flags.Syslog to compile at least. I
might have to change it to an interface or switch to a different syslog
library that supports remote syslogging on any platform (or write that
myself I think it's just a socket with text).
  • Loading branch information
fsmv committed Jan 28, 2024
1 parent a9965db commit ca73805
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spawn/embedspawn/logs_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (h *logHandler) HandleLogs(logs io.ReadCloser, tag string) {
//
// It's only syslog that misses it because spawn doesn't normally syslog for
// children, they syslog on their own.
flags.Syslog.Info(panicLog)
io.WriteString(flags.Syslog, panicLog)
}
}

Expand Down
3 changes: 2 additions & 1 deletion spawn/embedspawn/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"flag"
"fmt"
"io"
"io/fs"
"log"
"os"
Expand Down Expand Up @@ -89,7 +90,7 @@ func Run(flagset *flag.FlagSet, args []string) {
panicOut.WriteString(" panic: ")
fmt.Fprint(&panicOut, value, "\n\n")
panicOut.Write(debug.Stack())
flags.Syslog.Info(panicOut.String())
io.WriteString(flags.Syslog, panicOut.String())
}
panic(value)
}
Expand Down
3 changes: 3 additions & 0 deletions tools/flags/syslog_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
// initialized if the -syslog or the -syslog_remote flag is set and [flag.Parse]
// has been called.
//
// If you need to compile your code on windows you can only assume
// io.WriteCloser.
//
// Using this writer directly will not also log to stdout
var Syslog *syslog.Writer

Expand Down
10 changes: 10 additions & 0 deletions tools/flags/syslog_flag_nil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build nosyslog || windows

package flags

import "io"

// This is provided so that we can still compile on windows and if people use
// -nosyslog, since flags.Syslog is a public API.

var Syslog io.WriteCloser = nil

0 comments on commit ca73805

Please sign in to comment.