• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package base
6
7import (
8	"os"
9	"os/signal"
10	"sync"
11)
12
13// Interrupted is closed when the go command receives an interrupt signal.
14var Interrupted = make(chan struct{})
15
16// processSignals setups signal handler.
17func processSignals() {
18	sig := make(chan os.Signal, 1)
19	signal.Notify(sig, signalsToIgnore...)
20	go func() {
21		<-sig
22		close(Interrupted)
23	}()
24}
25
26var onceProcessSignals sync.Once
27
28// StartSigHandlers starts the signal handlers.
29func StartSigHandlers() {
30	onceProcessSignals.Do(processSignals)
31}
32