Skip to content

Commit 35b2028

Browse files
tomershafiravikivity
authored andcommitted
signal.md: describe auto signal handling
Add documentation about the default Seastar signal handlers and `app_template::config::auto_handle_sigint_sigterm` flag to `doc/signal.md`, as introducery information.
1 parent b6272e1 commit 35b2028

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

doc/signal.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22

33
Seastar provides an interface to handle signals natively and safely as asynchronous tasks.
44

5-
It provides a dedicated header called [seastar/core/signal.hh](../include/seastar/core/signal.hh).
5+
## Default Signal Handlers
66

7-
## Usage
7+
Seastar sets by default signal handlers for SIGINT/SIGTERM that call reactor::stop(). The reactor will then execute callbacks installed by reactor::at_exit().
88

9-
You should call `seastar::handle_signal` procedure in order to register the provided signal handler for the specified signal based on the configuration params.
9+
You can disable this behavior, by setting `app_template::config::auto_handle_sigint_sigterm` to false. This flag is provided in the header [seastar/core/app-template.hh](../include/seastar/core/app-template..hh). Then, Seastar will not set signal handlers, and the default behavior of the Linux kernel will be preserved (terminate the program).
10+
11+
### Examples
12+
13+
```C++
14+
#include <seastar/core/app-template.hh>
15+
16+
int main(int ac, char** av) {
17+
seastar::app_template::config cfg;
18+
cfg.auto_handle_sigint_sigterm = false;
19+
seastar::app_template app(std::move(cfg));
20+
21+
return app.run(argc, argv, [] {
22+
std::cout << "SIGINT/SIGTERM will terminate the program\n";
23+
});
24+
}
25+
```
26+
27+
## Custom Signal Handler
28+
29+
In order to set a custom signal handler, Seastar provides a procedure called `seastar::handle_signal` in the header [seastar/core/signal.hh](../include/seastar/core/signal.hh). It registers a custom handler for the specified signal based on the configuration params.
1030
1131
The procedure must be called inside the `app.run()` lambda, otherwise it's UB.
1232

0 commit comments

Comments
 (0)