From ff7ddd9d204d3b303d1ab17f47c74991aa54b527 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 29 Oct 2020 15:02:04 -0700 Subject: [PATCH] ipn/ipnserver: move Windows local disk logging up to the parent process To capture panics, log.Printf writes to os.Stderr, etc. Fixes #726 --- ipn/ipnserver/server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ipn/ipnserver/server.go b/ipn/ipnserver/server.go index 7ba21abbb..cb76ba5a4 100644 --- a/ipn/ipnserver/server.go +++ b/ipn/ipnserver/server.go @@ -26,6 +26,7 @@ import ( "inet.af/netaddr" "tailscale.com/control/controlclient" "tailscale.com/ipn" + "tailscale.com/log/filelogger" "tailscale.com/logtail/backoff" "tailscale.com/net/netstat" "tailscale.com/safesocket" @@ -520,6 +521,11 @@ func Run(ctx context.Context, logf logger.Logf, logid string, getEngine func() ( return ctx.Err() } +// BabysitProc runs the current executable as a child process with the +// provided args, capturing its output, writing it to files, and +// restarting the process on any crashes. +// +// It's only currently (2020-10-29) used on Windows. func BabysitProc(ctx context.Context, args []string, logf logger.Logf) { executable, err := os.Executable() @@ -527,6 +533,14 @@ func BabysitProc(ctx context.Context, args []string, logf logger.Logf) { panic("cannot determine executable: " + err.Error()) } + if runtime.GOOS == "windows" { + if len(args) != 2 && args[0] != "/subproc" { + panic(fmt.Sprintf("unexpected arguments %q", args)) + } + logID := args[1] + logf = filelogger.New("tailscale-service", logID, logf) + } + var proc struct { mu sync.Mutex p *os.Process