ret = -1;
goto end;
}
+ ret = system("sudo -l lttng >/dev/null");
+ if (ret < 0) {
+ fprintf(stderr, "[error] You are not root and not "
+ "allowed by sudo to use lttng\n");
+ ret = -1;
+ goto end;
+ }
sudo = 1;
}
}
static
-int enable_event(char *name, int sudo)
+int live_local_session(char *name, int sudo)
+{
+ int ret;
+ char cmd[1024];
+
+ ret = sprintf(cmd, "%s lttng create %s --live 1000000 -U net://localhost >/dev/null",
+ (sudo) ? "sudo" : " ", name);
+ if (ret < 0) {
+ fprintf(stderr, "Allocating cmd\n");
+ goto end;
+ }
+ ret = (system(cmd));
+ if (ret != 0) {
+ fprintf(stderr, "Error: creating the session\n");
+ ret = -1;
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
+static
+int enable_events(char *name, int sudo)
{
int ret;
char cmd[1024];
}
static
-int start(char *name, int sudo)
+int start(char *name, int sudo, int local)
{
int ret;
char cmd[1024];
goto end;
}
- ret = sprintf(cmd, "%s lttng list|grep %s|cut -d'(' -f2|cut -d ')' -f1",
- (sudo) ? "sudo" : " ", name);
+ if (local) {
+ ret = sprintf(cmd, "%s lttng list|grep %s|cut -d'(' -f2|cut -d ')' -f1",
+ (sudo) ? "sudo" : " ", name);
+ } else {
+ ret = sprintf(cmd, "lttngtop -r net://localhost|grep %s|cut -d' ' -f1",
+ name);
+ }
if (ret < 0) {
fprintf(stderr, "allocating cmd\n");
goto end;
}
- fprintf(stderr, "Local session started in ");
+ fprintf(stderr, "%s session started : ",
+ (local) ? "Local" : "Live");
ret = (system(cmd));
if (ret != 0) {
fprintf(stderr, "error: listing the sessions\n");
}
static
-int destroy(char *name, int sudo)
+int destroy(char *name)
{
int ret;
+ int sudo = 0;
char cmd[1024];
+ if (getuid() != 0) {
+ ret = system("sudo -l lttng >/dev/null");
+ if (ret < 0) {
+ fprintf(stderr, "[error] You are not root and not "
+ "allowed by sudo to use lttng\n");
+ ret = -1;
+ goto end;
+ }
+ sudo = 1;
+ }
+
ret = sprintf(cmd, "%s lttng destroy %s >/dev/null",
(sudo) ? "sudo" : " ", name);
if (ret < 0) {
goto end_free;
}
- ret = enable_event(name, sudo);
+ ret = enable_events(name, sudo);
if (ret < 0) {
goto end_free;
}
goto end_free;
}
- ret = start(name, sudo);
+ ret = start(name, sudo, 1);
if (ret < 0) {
goto end_free;
}
return ret;
}
-int destroy_local_session(char *name, int sudo)
+int destroy_session(char *name)
+{
+ return destroy(name);
+}
+
+int create_live_local_session()
{
- return destroy(name, sudo);
+ int ret;
+ char *name;
+ int sudo = 0;
+
+ ret = check_requirements(&sudo);
+
+ name = random_session_name();
+ if (!name) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = check_session_name(name, sudo);
+ if (ret < 0) {
+ goto end_free;
+ }
+
+ ret = live_local_session(name, sudo);
+ if (ret < 0) {
+ goto end_free;
+ }
+
+ ret = enable_events(name, sudo);
+ if (ret < 0) {
+ goto end_free;
+ }
+
+ ret = add_contexts(name, sudo);
+ if (ret < 0) {
+ goto end_free;
+ }
+
+ ret = start(name, sudo, 0);
+ if (ret < 0) {
+ goto end_free;
+ }
+
+end_free:
+ free(name);
+end:
+ return ret;
}
/*
OPT_VERBOSE,
OPT_GUI_TEST,
OPT_CREATE_LOCAL_SESSION,
+ OPT_CREATE_LIVE_SESSION,
};
static struct poptOption long_options[] = {
{ "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
{ "gui-test", 'g', POPT_ARG_NONE, NULL, OPT_GUI_TEST, NULL, NULL },
{ "create-local-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LOCAL_SESSION, NULL, NULL },
+ { "create-live-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LIVE_SESSION, NULL, NULL },
{ NULL, 0, 0, NULL, 0, NULL, NULL },
};
fprintf(fp, " -b, --begin Network live streaming : read the trace for the beginning of the recording\n");
fprintf(fp, " -o, --output <filename> In textdump, output the log in <filename>\n");
fprintf(fp, " -g, --gui-test Test if the ncurses support is compiled in (return 0 if it is)\n");
+ fprintf(fp, " --create-local-session Setup a LTTng local session with all the right parameters\n");
+ fprintf(fp, " --create-live-session Setup a LTTng live session on localhost with all the right parameters\n");
}
/*
case OPT_CREATE_LOCAL_SESSION:
ret = create_local_session();
exit(ret);
+ case OPT_CREATE_LIVE_SESSION:
+ ret = create_live_local_session();
+ exit(ret);
case OPT_TEXTDUMP:
opt_textdump = 1;
break;