Commit fc0275e2 authored by Niels Möller's avatar Niels Möller
Browse files

* src/lshd.c (install_terminate_handler): Catch SIGTERM and

arrange for exit(0) to be called on termination.

Rev: src/lshd.c:1.111
parent 6b0dd081
......@@ -648,6 +648,47 @@ main_argp =
(connection_require_userauth connection)))))))
*/
/* FIXME: Perhaps move to daemon.c? */
/* Catch SIGTERM and call exit(). That way, profiling info is written
* properly when the process is terminated. */
static volatile sig_atomic_t terminate;
static void terminate_handler(int signum)
{
assert(signum == SIGTERM);
terminate = 1;
}
static void
do_terminate_callback(struct lsh_callback *s UNUSED)
{
exit(0);
}
static const struct lsh_callback
terminate_callback =
{ STATIC_HEADER, do_terminate_callback };
static void
install_terminate_handler(struct io_backend *backend)
{
struct sigaction term;
memset(&term, 0, sizeof(term));
term.sa_handler = terminate_handler;
sigemptyset(&term.sa_mask);
term.sa_flags = 0;
if (sigaction(SIGTERM, &term, NULL) < 0)
{
werror ("Failed to install SIGTERM handler (errno = %i): %z\n",
errno, STRERROR(errno));
exit(EXIT_FAILURE);
}
io_signal_handler(backend, &terminate, &terminate_callback);
}
int main(int argc, char **argv)
{
......@@ -655,6 +696,8 @@ int main(int argc, char **argv)
struct io_backend *backend = make_io_backend();
install_terminate_handler(backend);
/* For filtering messages. Could perhaps also be used when converting
* strings to and from UTF8. */
setlocale(LC_CTYPE, "");
......@@ -784,5 +827,7 @@ int main(int argc, char **argv)
io_run(backend);
/* gc(NULL); */
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment