From 43b271cb26e72a94ab9ee00b19204042fea01bde Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Fri, 31 Jul 2020 16:02:42 -0400 Subject: [PATCH] cmd/tailscaled: exit gracefully on SIGPIPE Signed-off-by: Dmytro Shynkevych --- cmd/tailscaled/tailscaled.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index e4dbf220d..b8d7957ee 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -148,10 +148,11 @@ func run() error { ctx, cancel := context.WithCancel(context.Background()) // Exit gracefully by cancelling the ipnserver context in most common cases: - // interrupted from the TTY or killed by a service manager. + // interrupted from the TTY (including when output is piped into e.g. grep) + // or killed by a service manager. go func() { interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, syscall.SIGINT, syscall.SIGPIPE, syscall.SIGTERM) select { case s := <-interrupt: logf("tailscaled got signal %v; shutting down", s)