Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Ignore SIGPIPE for systemd, fixes #13.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmt2005 committed Mar 1, 2017
1 parent 5a2c7f2 commit 30b46aa
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
func init() {
defaultEnv = NewEnvironment(context.Background())
handleSignal(defaultEnv)
ignoreSigPipe()
}

// Stop just declares no further Go will be called.
Expand Down
19 changes: 19 additions & 0 deletions sigpipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build !windows

package cmd

import (
"os"
"os/signal"
"syscall"
)

func ignoreSigPipe() {
// signal.Ignore does NOT ignore signals; instead, it just stop
// relaying signals to the channel.
//signal.Ignore(syscall.SIGPIPE)

// buffer-less channel will effectively ignore the signal
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGPIPE)
}
3 changes: 3 additions & 0 deletions sigpipe_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package cmd

func ignoreSigPipe() {}

0 comments on commit 30b46aa

Please # to comment.