#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
+#include <string.h>
#define event_list "lttng_statedump_start,lttng_statedump_end," \
"lttng_statedump_process_state,lttng_statedump_file_descriptor," \
}
static
-int start(char *name, int sudo, int local)
+int start(char *name, int sudo, int local, int print)
{
int ret;
char cmd[1024];
goto end;
}
+ if (!print)
+ goto end;
+
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",
+ ret = sprintf(cmd, "babeltrace -i lttng-live net://localhost|grep %s|cut -d' ' -f1",
name);
}
if (ret < 0) {
return ret;
}
+static
+char *live_path(char *name)
+{
+ FILE *fp;
+ int ret;
+ char path[1035];
+ char cmd[1024];
+ char *out = NULL;
+
+ ret = sprintf(cmd, "lttngtop -r net://localhost|grep %s|cut -d' ' -f1",
+ name);
+ if (ret < 0) {
+ fprintf(stderr, "allocating cmd\n");
+ goto end;
+ }
+
+ fp = popen(cmd, "r");
+ if (fp == NULL) {
+ printf("Failed to run command\n" );
+ goto end;
+ }
+
+ /* Read the output a line at a time - output it. */
+ out = fgets(path, sizeof(path)-1, fp);
+ if (out)
+ out = strdup(path);
+
+ /* close */
+ pclose(fp);
+
+end:
+ return out;
+}
+
static
int destroy(char *name)
{
int sudo = 0;
char cmd[1024];
- if (getuid() != 0) {
+ ret = system("groups|grep tracing >/dev/null");
+ if (ret != 0 && getuid() != 0) {
ret = system("sudo -l lttng >/dev/null");
if (ret < 0) {
fprintf(stderr, "[error] You are not root and not "
goto end_free;
}
- ret = start(name, sudo, 1);
+ ret = start(name, sudo, 1, 1);
if (ret < 0) {
goto end_free;
}
return ret;
}
-int destroy_session(char *name)
+int destroy_live_local_session(char *name)
{
return destroy(name);
}
-int create_live_local_session()
+int create_live_local_session(char **session_path, char **session_name, int print)
{
int ret;
char *name;
goto end_free;
}
- ret = start(name, sudo, 0);
+ ret = start(name, sudo, 0, print);
if (ret < 0) {
goto end_free;
}
+ if (session_path)
+ *session_path = live_path(name);
+ if (session_name) {
+ *session_name = name;
+ goto end;
+ }
+
end_free:
free(name);
end:
return ret;
}
-
-/*
-int create_live_local_session();
-int destroy_live_local_session();
-*/