summaryrefslogtreecommitdiff
path: root/src/cmd/go/signal.go
blob: e8ba0d36556ad4efd9f2a83e8c8b37cf0e95c24e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"os"
	"os/signal"
	"sync"
)

// interrupted is closed, if go process is interrupted.
var interrupted = make(chan struct{})

// processSignals setups signal handler.
func processSignals() {
	sig := make(chan os.Signal)
	signal.Notify(sig, signalsToIgnore...)
	go func() {
		<-sig
		close(interrupted)
	}()
}

var onceProcessSignals sync.Once

// startSigHandlers start signal handlers.
func startSigHandlers() {
	onceProcessSignals.Do(processSignals)
}