X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-consumerd%2Flttng-consumerd.c;h=dbcda885eede04a0a92a3189a975247de80ce4f2;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=ddd07a14279eb3e88bc93b5497e8989a08cb2b3a;hpb=929f71ec24b58045319473f050a7f235f726ec78;p=lttng-tools.git diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index ddd07a142..dbcda885e 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -1,19 +1,9 @@ /* - * Copyright (C) 2011 - Julien Desfossez - * Mathieu Desnoyers + * Copyright (C) 2011 Julien Desfossez + * Copyright (C) 2011 Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _LGPL_SOURCE @@ -36,7 +26,6 @@ #include #include #include -#include #include #include @@ -93,13 +82,30 @@ enum lttng_consumer_type lttng_consumer_get_type(void) /* * Signal handler for the daemon */ -static void sighandler(int sig) +static void sighandler(int sig, siginfo_t *siginfo, void *arg) { if (sig == SIGINT && sigintcount++ == 0) { DBG("ignoring first SIGINT"); return; } + if (sig == SIGBUS) { + int write_ret; + const char msg[] = "Received SIGBUS, aborting program.\n"; + + lttng_consumer_sigbus_handle(siginfo->si_addr); + /* + * If ustctl did not catch this signal (triggering a + * siglongjmp), abort the program. Otherwise, the execution + * will resume from the ust-ctl call which caused this error. + * + * The return value is ignored since the program aborts anyhow. + */ + write_ret = write(STDERR_FILENO, msg, sizeof(msg)); + (void) write_ret; + abort(); + } + if (ctx) { lttng_consumer_should_exit(ctx); } @@ -107,7 +113,7 @@ static void sighandler(int sig) /* * Setup signal handler for : - * SIGINT, SIGTERM, SIGPIPE + * SIGINT, SIGTERM, SIGPIPE, SIGBUS */ static int set_signal_handler(void) { @@ -121,9 +127,9 @@ static int set_signal_handler(void) } sa.sa_mask = sigset; - sa.sa_flags = 0; + sa.sa_flags = SA_SIGINFO; - sa.sa_handler = sighandler; + sa.sa_sigaction = sighandler; if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { PERROR("sigaction"); return ret; @@ -134,6 +140,12 @@ static int set_signal_handler(void) return ret; } + if ((ret = sigaction(SIGBUS, &sa, NULL)) < 0) { + PERROR("sigaction"); + return ret; + } + + sa.sa_flags = 0; sa.sa_handler = SIG_IGN; if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) { PERROR("sigaction"); @@ -311,6 +323,10 @@ int main(int argc, char **argv) rcu_register_thread(); + if (run_as_create_worker(argv[0], NULL, NULL) < 0) { + goto exit_set_signal_handler; + } + if (set_signal_handler()) { retval = -1; goto exit_set_signal_handler; @@ -411,10 +427,6 @@ int main(int argc, char **argv) set_ulimit(); } - if (run_as_create_worker(argv[0], NULL, NULL) < 0) { - goto exit_init_data; - } - /* create the consumer instance with and assign the callbacks */ ctx = lttng_consumer_create(opt_type, lttng_consumer_read_subbuffer, NULL, lttng_consumer_on_recv_stream, NULL);