X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttngctl%2Fliblttngctl.c;h=ec01859a9aa00b3394f6bfe29ac89abbfb976ae6;hp=37a0f8b8b257ca13026eedaf98d9dda88184bfc2;hb=ca3c5ac0cf100d80352a1a81936b5adc47942f35;hpb=f5177a38890d9d7f3324f9bc1d87c9cb77fcc2b3 diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index 37a0f8b8b..ec01859a9 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -30,7 +30,7 @@ #include -#include "liblttsessiondcomm.h" +#include #include "lttngerr.h" #include "lttng-share.h" @@ -46,6 +46,18 @@ static struct lttcomm_lttng_msg llm; static char *tracing_group; static int connected; +/* + * Copy string from src to dst and enforce null terminated byte. + */ +static void copy_string(char *dst, const char *src, size_t len) +{ + if (src && dst) { + strncpy(dst, src, len); + /* Enforce the NULL terminated byte */ + dst[len - 1] = '\0'; + } +} + /* * send_data_sessiond * @@ -154,13 +166,14 @@ static int set_session_daemon_path(void) /* Are we in the tracing group ? */ ret = check_tracing_group(tracing_group); if (ret < 0 && getuid() != 0) { - if (sprintf(sessiond_sock_path, DEFAULT_HOME_CLIENT_UNIX_SOCK, - getenv("HOME")) < 0) { + if (snprintf(sessiond_sock_path, PATH_MAX, + DEFAULT_HOME_CLIENT_UNIX_SOCK, + getenv("HOME")) < 0) { return -ENOMEM; } } else { - strncpy(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, - sizeof(DEFAULT_GLOBAL_CLIENT_UNIX_SOCK)); + copy_string(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, + PATH_MAX); } return 0; @@ -300,18 +313,6 @@ static void copy_lttng_domain(struct lttng_domain *dom) } } -/* - * Copy string from src to dst and enforce null terminated byte. - */ -static void copy_string(char *dst, const char *src, size_t len) -{ - if (src && dst) { - strncpy(dst, src, len); - /* Enforce the NULL terminated byte */ - dst[len - 1] = '\0'; - } -} - /* * Start tracing for all trace of the session. */ @@ -354,7 +355,7 @@ int lttng_add_context(struct lttng_domain *domain, int lttng_enable_event(struct lttng_domain *domain, struct lttng_event *ev, const char *channel_name) { - int ret = -1; + int ret; if (channel_name == NULL) { copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX); @@ -362,23 +363,13 @@ int lttng_enable_event(struct lttng_domain *domain, copy_string(lsm.u.enable.channel_name, channel_name, NAME_MAX); } - if (domain) { - switch (domain->type) { - case LTTNG_DOMAIN_KERNEL: - if (ev == NULL) { - ret = ask_sessiond(LTTNG_KERNEL_ENABLE_ALL_EVENT, NULL); - } else { - memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event)); - ret = ask_sessiond(LTTNG_KERNEL_ENABLE_EVENT, NULL); - } - break; - case LTTNG_DOMAIN_UST: - ret = LTTCOMM_NOT_IMPLEMENTED; - break; - default: - ret = LTTCOMM_UNKNOWN_DOMAIN; - break; - }; + copy_lttng_domain(domain); + + if (ev == NULL) { + ret = ask_sessiond(LTTNG_ENABLE_ALL_EVENT, NULL); + } else { + memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event)); + ret = ask_sessiond(LTTNG_ENABLE_EVENT, NULL); } return ret; @@ -411,37 +402,21 @@ int lttng_disable_event(struct lttng_domain *domain, const char *name, } /* - * Enable recording for a channel for the kernel tracer. + * Enable channel per domain */ int lttng_enable_channel(struct lttng_domain *domain, struct lttng_channel *chan) { - int ret = -1; - if (chan) { memcpy(&lsm.u.channel.chan, chan, sizeof(struct lttng_channel)); } - if (domain) { - switch (domain->type) { - case LTTNG_DOMAIN_KERNEL: - ret = ask_sessiond(LTTNG_KERNEL_ENABLE_CHANNEL, NULL); - break; - case LTTNG_DOMAIN_UST: - ret = LTTCOMM_NOT_IMPLEMENTED; - break; - default: - ret = LTTCOMM_UNKNOWN_DOMAIN; - break; - }; - } + copy_lttng_domain(domain); - return ret; + return ask_sessiond(LTTNG_ENABLE_CHANNEL, NULL); } /* - * Disable channel. - * * All tracing will be stopped for registered events of the channel. */ int lttng_disable_channel(struct lttng_domain *domain, const char *name) @@ -601,6 +576,22 @@ int lttng_set_tracing_group(const char *name) return 0; } +/* + * lttng_calibrate + */ +int lttng_calibrate(struct lttng_domain *domain, + struct lttng_calibrate *calibrate) +{ + int ret; + + copy_lttng_domain(domain); + + memcpy(&lsm.u.calibrate, calibrate, sizeof(struct lttng_calibrate)); + ret = ask_sessiond(LTTNG_CALIBRATE, NULL); + + return ret; +} + /* * lttng_check_session_daemon * @@ -618,13 +609,22 @@ int lttng_session_daemon_alive(void) return ret; } - /* If socket exist, we consider the daemon started */ + /* If socket exist, we check if the daemon listens to connect. */ ret = access(sessiond_sock_path, F_OK); if (ret < 0) { /* Not alive */ return 0; } + ret = lttcomm_connect_unix_sock(sessiond_sock_path); + if (ret < 0) { + /* Not alive */ + return 0; + } + ret = lttcomm_close_unix_sock(ret); + if (ret < 0) + perror("lttcomm_close_unix_sock"); + /* Is alive */ return 1; }