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

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmt2005 committed Apr 26, 2017
1 parent 86706dc commit 1930c2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Exit abnormally upon SIGPIPE (#15).

## [1.4.1] - 2017-03-01
### Changed
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ Commands using this framework implement these external specifications:

* `SIGPIPE`

SIGPIPE is completely ignored. See [#13](https://github.com/cybozu-go/cmd/issues/13) for details.
The framework changes [the way Go handles SIGPIPE slightly](https://golang.org/pkg/os/signal/#hdr-SIGPIPE).
If a program using this framework receives SIGPIPE when writing to stdout or stderr, the program exits with status code 2.
See [#15](https://github.com/cybozu-go/cmd/issues/15) for details.

### Environment variables

Expand Down
12 changes: 8 additions & 4 deletions sigpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
sigPipeExit = 2
)

// handleSigPipe catches SIGPIPE and exit abnormally with status code 2.
// handleSigPipe catches SIGPIPE and exits abnormally with status code 2.
//
// Background:
//
Expand All @@ -27,17 +27,21 @@ const (
// https://golang.org/pkg/os/signal/#hdr-SIGPIPE
//
// journald is a service tightly integrated in systemd. Go programs
// running as a systemd service will normally connect its stdout and
// running as a systemd service will normally connect their stdout and
// stderr pipes to journald. Unfortunately though, journald often
// dies and restarts due to bugs, and once it restarts, programs
// whose stdout and stderr was connected to journald will receive
// whose stdout and stderr were connected to journald will receive
// SIGPIPE at their next writes to stdout or stderr.
//
// Combined these specifications and problems all together, Go programs
// running as systemd services often die with SIGPIPE, but systemd will
// not restarts them as they "successfully exited" except when the service
// not restart them as they "successfully exited" except when the service
// is configured with SuccessExitStatus= without SIGPIPE or Restart=always.
//
// Ignoring SIGPIPE would not help; the stdout or stderr pipes will
// be choked and eventually the Go program will stop forever there
// if a service ignores SIGPIPE and writes to them contiuously.
//
// Handling SIGPIPE manually and exiting with abnormal status code 2
// can work around the problem.
func handleSigPipe() {
Expand Down

0 comments on commit 1930c2b

Please sign in to comment.