From e4aaf7afbde3201331163147d4bf308876ceaef4 Mon Sep 17 00:00:00 2001 From: ymmt2005 Date: Wed, 1 Mar 2017 17:47:31 +0900 Subject: [PATCH] Ignore SIGPIPE for systemd, fixes #13. --- CHANGELOG.md | 1 + README.md | 4 ++++ default.go | 1 + sigpipe.go | 12 ++++++++++++ sigpipe_windows.go | 3 +++ 5 files changed, 21 insertions(+) create mode 100644 sigpipe.go create mode 100644 sigpipe_windows.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c25bcbf..59072e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Fix `NewEnvironment` documentation. +- Ignore SIGPIPE for systemd (#13). ## [1.4.0] - 2016-09-10 ### Added diff --git a/README.md b/README.md index 8d97271..00dfd2d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ Commands using this framework implement these external specifications: On Windows, this is not implemented. +* `SIGPIPE` + + SIGPIPE is completely ignored. See [#13](https://github.com/cybozu-go/cmd/issues/13) for details. + ### Environment variables * `REQUEST_ID_HEADER` diff --git a/default.go b/default.go index 65517a6..51eecaa 100644 --- a/default.go +++ b/default.go @@ -9,6 +9,7 @@ var ( func init() { defaultEnv = NewEnvironment(context.Background()) handleSignal(defaultEnv) + ignoreSigPipe() } // Stop just declares no further Go will be called. diff --git a/sigpipe.go b/sigpipe.go new file mode 100644 index 0000000..9d4d690 --- /dev/null +++ b/sigpipe.go @@ -0,0 +1,12 @@ +// +build !windows + +package cmd + +import ( + "os/signal" + "syscall" +) + +func ignoreSigPipe() { + signal.Ignore(syscall.SIGPIPE) +} diff --git a/sigpipe_windows.go b/sigpipe_windows.go new file mode 100644 index 0000000..e630a90 --- /dev/null +++ b/sigpipe_windows.go @@ -0,0 +1,3 @@ +package cmd + +func ignoreSigPipe() {}