Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
aa1bdc3e
Commit
aa1bdc3e
authored
Dec 07, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow setting of a different reserved signal than SIGUSR1.
parent
bc56e509
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
9 deletions
+38
-9
async-unix.c++
c++/src/kj/async-unix.c++
+30
-7
async-unix.h
c++/src/kj/async-unix.h
+8
-2
No files found.
c++/src/kj/async-unix.c++
View file @
aa1bdc3e
...
...
@@ -32,6 +32,9 @@ namespace kj {
namespace
{
int
reservedSignal
=
SIGUSR1
;
bool
tooLateToSetReserved
=
false
;
struct
SignalCapture
{
sigjmp_buf
jumpTo
;
siginfo_t
siginfo
;
...
...
@@ -48,6 +51,8 @@ void signalHandler(int, siginfo_t* siginfo, void*) {
}
void
registerSignalHandler
(
int
signum
)
{
tooLateToSetReserved
=
true
;
sigset_t
mask
;
sigemptyset
(
&
mask
);
sigaddset
(
&
mask
,
signum
);
...
...
@@ -61,14 +66,14 @@ void registerSignalHandler(int signum) {
sigaction
(
signum
,
&
action
,
nullptr
);
}
void
register
Sigusr1
()
{
registerSignalHandler
(
SIGUSR1
);
void
register
ReservedSignal
()
{
registerSignalHandler
(
reservedSignal
);
// We also disable SIGPIPE because users of UnixEventLoop almost certainly don't want it.
signal
(
SIGPIPE
,
SIG_IGN
);
}
pthread_once_t
register
Sigusr1
Once
=
PTHREAD_ONCE_INIT
;
pthread_once_t
register
ReservedSignal
Once
=
PTHREAD_ONCE_INIT
;
}
// namespace
...
...
@@ -156,7 +161,7 @@ public:
};
UnixEventPort
::
UnixEventPort
()
{
pthread_once
(
&
register
Sigusr1Once
,
&
registerSigusr1
);
pthread_once
(
&
register
ReservedSignalOnce
,
&
registerReservedSignal
);
}
UnixEventPort
::~
UnixEventPort
()
{}
...
...
@@ -170,10 +175,28 @@ Promise<siginfo_t> UnixEventPort::onSignal(int signum) {
}
void
UnixEventPort
::
captureSignal
(
int
signum
)
{
KJ_REQUIRE
(
signum
!=
SIGUSR1
,
"Sorry, SIGUSR1 is reserved by the UnixEventPort implementation."
);
if
(
reservedSignal
==
SIGUSR1
)
{
KJ_REQUIRE
(
signum
!=
SIGUSR1
,
"Sorry, SIGUSR1 is reserved by the UnixEventPort implementation. You may call "
"UnixEventPort::setReservedSignal() to reserve a different signal."
);
}
else
{
KJ_REQUIRE
(
signum
!=
reservedSignal
,
"Can't capture signal reserved using setReservedSignal()."
,
signum
);
}
registerSignalHandler
(
signum
);
}
void
UnixEventPort
::
setReservedSignal
(
int
signum
)
{
KJ_REQUIRE
(
!
tooLateToSetReserved
,
"setReservedSignal() must be called before any calls to `captureSignal()` and "
"before any `UnixEventPort` is constructed."
);
if
(
reservedSignal
!=
SIGUSR1
&&
reservedSignal
!=
signum
)
{
KJ_FAIL_REQUIRE
(
"Detected multiple conflicting calls to setReservedSignal(). Please only "
"call this once, or always call it with the same signal number."
);
}
reservedSignal
=
signum
;
}
class
UnixEventPort
::
PollContext
{
public
:
PollContext
(
PollPromiseAdapter
*
ptr
)
{
...
...
@@ -224,7 +247,7 @@ private:
void
UnixEventPort
::
wait
()
{
sigset_t
newMask
;
sigemptyset
(
&
newMask
);
sigaddset
(
&
newMask
,
SIGUSR1
);
sigaddset
(
&
newMask
,
reservedSignal
);
{
auto
ptr
=
signalHead
;
...
...
@@ -243,7 +266,7 @@ void UnixEventPort::wait() {
// We received a signal and longjmp'd back out of the signal handler.
threadCapture
=
nullptr
;
if
(
capture
.
siginfo
.
si_signo
!=
SIGUSR1
)
{
if
(
capture
.
siginfo
.
si_signo
!=
reservedSignal
)
{
gotSignal
(
capture
.
siginfo
);
}
...
...
c++/src/kj/async-unix.h
View file @
aa1bdc3e
...
...
@@ -43,8 +43,9 @@ class UnixEventPort: public EventPort {
// just before `poll()` while using a signal handler which `siglongjmp()`s back to just before
// the signal was unblocked, or it may use a nicer platform-specific API like signalfd.
//
// The implementation uses SIGUSR1. The application must avoid using this signal for its own
// purposes.
// The implementation reserves a signal for internal use. By default, it uses SIGUSR1. If you
// need to use SIGUSR1 for something else, you must offer a different signal by calling
// setReservedSignal() at startup.
public
:
UnixEventPort
();
...
...
@@ -79,6 +80,11 @@ public:
// To un-capture a signal, simply install a different signal handler and then un-block it from
// the signal mask.
static
void
setReservedSignal
(
int
signum
);
// Sets the signal number which `UnixEventPort` reserves for internal use. If your application
// needs to use SIGUSR1, call this at startup (before any calls to `captureSignal()` and before
// constructing an `UnixEventPort`) to offer a different signal.
// implements EventPort ------------------------------------------------------
void
wait
()
override
;
void
poll
()
override
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment