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 11:52:37 -07: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.
|
|
|
|
|
2013-08-23 09:50:24 -06:00
|
|
|
// +build darwin dragonfly freebsd linux openbsd netbsd
|
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 11:52:37 -07:00
|
|
|
|
|
|
|
#include "runtime.h"
|
|
|
|
#include "defs_GOOS_GOARCH.h"
|
|
|
|
#include "os_GOOS.h"
|
2013-03-14 12:35:13 -06:00
|
|
|
#include "signal_unix.h"
|
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 11:52:37 -07:00
|
|
|
|
|
|
|
extern SigTab runtime·sigtab[];
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·initsig(void)
|
|
|
|
{
|
|
|
|
int32 i;
|
|
|
|
SigTab *t;
|
|
|
|
|
|
|
|
// First call: basic setup.
|
|
|
|
for(i = 0; i<NSIG; i++) {
|
|
|
|
t = &runtime·sigtab[i];
|
2012-02-16 20:36:40 -07:00
|
|
|
if((t->flags == 0) || (t->flags & SigDefault))
|
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 11:52:37 -07:00
|
|
|
continue;
|
2013-03-14 22:00:02 -06:00
|
|
|
|
|
|
|
// For some signals, we respect an inherited SIG_IGN handler
|
|
|
|
// rather than insist on installing our own default handler.
|
|
|
|
// Even these signals can be fetched using the os/signal package.
|
|
|
|
switch(i) {
|
|
|
|
case SIGHUP:
|
|
|
|
case SIGINT:
|
|
|
|
if(runtime·getsig(i) == SIG_IGN) {
|
|
|
|
t->flags = SigNotify | SigIgnored;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t->flags |= SigHandling;
|
2012-02-16 20:36:40 -07:00
|
|
|
runtime·setsig(i, runtime·sighandler, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·sigenable(uint32 sig)
|
|
|
|
{
|
|
|
|
SigTab *t;
|
|
|
|
|
2013-03-14 22:00:02 -06:00
|
|
|
if(sig >= NSIG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
t = &runtime·sigtab[sig];
|
|
|
|
if((t->flags & SigNotify) && !(t->flags & SigHandling)) {
|
|
|
|
t->flags |= SigHandling;
|
|
|
|
if(runtime·getsig(sig) == SIG_IGN)
|
|
|
|
t->flags |= SigIgnored;
|
|
|
|
runtime·setsig(sig, runtime·sighandler, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·sigdisable(uint32 sig)
|
|
|
|
{
|
|
|
|
SigTab *t;
|
|
|
|
|
|
|
|
if(sig >= NSIG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
t = &runtime·sigtab[sig];
|
|
|
|
if((t->flags & SigNotify) && (t->flags & SigHandling)) {
|
|
|
|
t->flags &= ~SigHandling;
|
|
|
|
if(t->flags & SigIgnored)
|
|
|
|
runtime·setsig(sig, SIG_IGN, true);
|
|
|
|
else
|
|
|
|
runtime·setsig(sig, SIG_DFL, true);
|
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 11:52:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·resetcpuprofiler(int32 hz)
|
|
|
|
{
|
|
|
|
Itimerval it;
|
2012-02-28 14:18:24 -07:00
|
|
|
|
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 11:52:37 -07:00
|
|
|
runtime·memclr((byte*)&it, sizeof it);
|
|
|
|
if(hz == 0) {
|
|
|
|
runtime·setitimer(ITIMER_PROF, &it, nil);
|
|
|
|
} else {
|
|
|
|
it.it_interval.tv_sec = 0;
|
|
|
|
it.it_interval.tv_usec = 1000000 / hz;
|
|
|
|
it.it_value = it.it_interval;
|
|
|
|
runtime·setitimer(ITIMER_PROF, &it, nil);
|
|
|
|
}
|
|
|
|
m->profilehz = hz;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
os·sigpipe(void)
|
|
|
|
{
|
|
|
|
runtime·setsig(SIGPIPE, SIG_DFL, false);
|
2013-03-14 23:11:03 -06:00
|
|
|
runtime·raise(SIGPIPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·crash(void)
|
|
|
|
{
|
|
|
|
#ifdef GOOS_darwin
|
|
|
|
// OS X core dumps are linear dumps of the mapped memory,
|
|
|
|
// from the first virtual byte to the last, with zeros in the gaps.
|
|
|
|
// Because of the way we arrange the address space on 64-bit systems,
|
|
|
|
// this means the OS X core file will be >128 GB and even on a zippy
|
|
|
|
// workstation can take OS X well over an hour to write (uninterruptible).
|
|
|
|
// Save users from making that mistake.
|
|
|
|
if(sizeof(void*) == 8)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
runtime·setsig(SIGABRT, SIG_DFL, false);
|
|
|
|
runtime·raise(SIGABRT);
|
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 11:52:37 -07:00
|
|
|
}
|