#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <config.h>
#include <lttng/lttng.h>
-#include <common/lttngerr.h>
+#include <common/error.h>
-#include "cmd.h"
-#include "conf.h"
+#include "command.h"
/* Variables */
static char *progname;
int opt_verbose;
static int opt_no_sessiond;
static char *opt_sessiond_path;
+static pid_t sessiond_pid;
enum {
OPT_SESSION_PATH,
*/
static void sighandler(int sig)
{
+ int status;
+
switch (sig) {
case SIGTERM:
- DBG("SIGTERM catched");
+ DBG("SIGTERM caugth");
clean_exit(EXIT_FAILURE);
break;
case SIGCHLD:
+ DBG("SIGCHLD caugth");
+ waitpid(sessiond_pid, &status, 0);
+ /* Indicate that the session daemon died */
+ sessiond_pid = 0;
+ ERR("Session daemon died (exit status %d)", WEXITSTATUS(status));
+ break;
+ case SIGUSR1:
/* Notify is done */
- DBG("SIGCHLD catched");
+ DBG("SIGUSR1 caugth");
break;
default:
- DBG("Unknown signal %d catched", sig);
+ DBG("Unknown signal %d caugth", sig);
break;
}
sa.sa_handler = sighandler;
sa.sa_mask = sigset;
sa.sa_flags = 0;
- if ((ret = sigaction(SIGCHLD, &sa, NULL)) < 0) {
+ if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) {
perror("sigaction");
goto end;
}
goto end;
}
+ if ((ret = sigaction(SIGCHLD, &sa, NULL)) < 0) {
+ perror("sigaction");
+ goto end;
+ }
+
end:
return ret;
}
case CMD_ERROR:
ERR("Command error");
break;
- case CMD_NOT_IMPLEMENTED:
- ERR("Options not implemented");
- break;
case CMD_UNDEFINED:
ERR("Undefined command");
break;
kill(getppid(), SIGTERM); /* unpause parent */
exit(EXIT_FAILURE);
} else if (pid > 0) {
+ sessiond_pid = pid;
/* Wait for lttng-sessiond to start */
pause();
+ if (!sessiond_pid) {
+ exit(EXIT_FAILURE);
+ }
goto end;
} else {
perror("fork");
}
/*
- * Check for the "help" option in the argv. If found, return 1 else return 0.
+ * Check args for specific options that *must* not trigger a session daemon
+ * execution.
+ *
+ * Return 1 if match else 0.
*/
-static int check_help_command(int argc, char **argv)
+static int check_args_no_sessiond(int argc, char **argv)
{
int i;
for (i = 0; i < argc; i++) {
if ((strncmp(argv[i], "-h", 2) == 0) ||
- strncmp(argv[i], "--h", 3) == 0) {
+ strncmp(argv[i], "--h", 3) == 0 ||
+ strncmp(argv[i], "--list-options", 14)) {
return 1;
}
}
}
/* Spawn session daemon if needed */
- if (opt_no_sessiond == 0 && check_help_command(argc, argv) == 0 &&
+ if (opt_no_sessiond == 0 && check_args_no_sessiond(argc, argv) == 0 &&
(check_sessiond() < 0)) {
goto error;
}
progname = argv[0] ? argv[0] : "lttng";
/* For Mathieu Desnoyers aka Dr Tracing */
- if (strncmp(progname, "drtrace", 7) == 0) {
- MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n\n", 27,1,33,27,0);
+ if (strncmp(progname, "drtrace", 7) == 0 ||
+ strncmp("compudj", getenv("USER"), 7) == 0) {
+ MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n", 27,1,33,27,0);
}
ret = set_signal_handler();