os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
// 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.
|
|
|
|
|
|
2018-09-28 15:57:27 +02:00
|
|
|
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
|
|
|
|
|
package signal
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"syscall"
|
|
|
|
|
)
|
|
|
|
|
|
2015-10-16 09:56:07 +13:00
|
|
|
// Defined by the runtime package.
|
2013-03-15 00:00:02 -04:00
|
|
|
func signal_disable(uint32)
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
func signal_enable(uint32)
|
2015-01-29 22:37:41 -05:00
|
|
|
func signal_ignore(uint32)
|
2018-04-19 19:59:39 -07:00
|
|
|
func signal_ignored(uint32) bool
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
func signal_recv() uint32
|
|
|
|
|
|
|
|
|
|
func loop() {
|
|
|
|
|
for {
|
|
|
|
|
process(syscall.Signal(signal_recv()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
signal_enable(0) // first call - initialize
|
|
|
|
|
go loop()
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-15 00:00:02 -04:00
|
|
|
const (
|
|
|
|
|
numSig = 65 // max across all systems
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func signum(sig os.Signal) int {
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
switch sig := sig.(type) {
|
|
|
|
|
case syscall.Signal:
|
2013-03-15 00:00:02 -04:00
|
|
|
i := int(sig)
|
|
|
|
|
if i < 0 || i >= numSig {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return i
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
default:
|
2013-03-15 00:00:02 -04:00
|
|
|
return -1
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 13:52:37 -05:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-15 00:00:02 -04:00
|
|
|
|
|
|
|
|
func enableSignal(sig int) {
|
|
|
|
|
signal_enable(uint32(sig))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func disableSignal(sig int) {
|
|
|
|
|
signal_disable(uint32(sig))
|
|
|
|
|
}
|
2015-01-29 22:37:41 -05:00
|
|
|
|
|
|
|
|
func ignoreSignal(sig int) {
|
|
|
|
|
signal_ignore(uint32(sig))
|
|
|
|
|
}
|
2018-04-19 19:59:39 -07:00
|
|
|
|
|
|
|
|
func signalIgnored(sig int) bool {
|
|
|
|
|
return signal_ignored(uint32(sig))
|
|
|
|
|
}
|