Move utils_expand_path and utils_expand_path_keep_symlink to libpath.la
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index de95fad311fa0c0c09fdb7a0b0bcf9793edcef9d..eddce5c5482e69fbd40f24191426f8137367b09e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
@@ -37,6 +37,7 @@
 #include <common/futex.h>
 #include <common/relayd/relayd.h>
 #include <common/utils.h>
+#include <common/path.h>
 #include <common/daemonize.h>
 #include <common/config/session-config.h>
 #include <common/dynamic-buffer.h>
@@ -75,6 +76,7 @@
 #include "manage-apps.h"
 #include "manage-kernel.h"
 #include "modprobe.h"
+#include "ust-sigbus.h"
 
 static const char *help_msg =
 #ifdef LTTNG_EMBED_HELP
@@ -856,7 +858,7 @@ static int set_options(int argc, char **argv)
        int ret = 0, c = 0, option_index = 0;
        int orig_optopt = optopt, orig_optind = optind;
        char *optstring;
-       const char *config_path = NULL;
+       char *config_path = NULL;
 
        optstring = utils_generate_optstring(long_options,
                        sizeof(long_options) / sizeof(struct option));
@@ -880,6 +882,7 @@ static int set_options(int argc, char **argv)
                        WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.",
                                "-f, --config");
                } else {
+                       free(config_path);
                        config_path = utils_expand_path(optarg);
                        if (!config_path) {
                                ERR("Failed to resolve path: %s", optarg);
@@ -925,6 +928,7 @@ static int set_options(int argc, char **argv)
        }
 
 end:
+       free(config_path);
        free(optstring);
        return ret;
 }
@@ -1168,7 +1172,7 @@ error:
  * Simply stop all worker threads, leaving main() return gracefully after
  * joining all threads and calling cleanup().
  */
-static void sighandler(int sig)
+static void sighandler(int sig, siginfo_t *siginfo, void *arg)
 {
        switch (sig) {
        case SIGINT:
@@ -1182,6 +1186,23 @@ static void sighandler(int sig)
        case SIGUSR1:
                CMM_STORE_SHARED(recv_child_signal, 1);
                break;
+       case SIGBUS:
+       {
+               int write_ret;
+               const char msg[] = "Received SIGBUS, aborting program.\n";
+
+               lttng_ust_handle_sigbus(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();
+       }
        default:
                break;
        }
@@ -1203,9 +1224,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;
@@ -1221,13 +1242,19 @@ 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");
                return ret;
        }
 
-       DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE and SIGINT");
+       DBG("Signal handler set for SIGTERM, SIGUSR1, SIGPIPE, SIGINT, and SIGBUS");
 
        return ret;
 }
This page took 0.024519 seconds and 4 git commands to generate.