*/
#define _GNU_SOURCE
-#include <errno.h>
#include <grp.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <lttng/lttng.h>
-
#include <lttng-sessiond-comm.h>
-#include "lttngerr.h"
-#include "lttng-share.h"
+#include <lttng-share.h>
+#include <lttng/lttng.h>
+#include <lttngerr.h>
/* Socket to session daemon for communication */
static int sessiond_socket;
static char sessiond_sock_path[PATH_MAX];
-/* Communication structure to ltt-sessiond */
-static struct lttcomm_session_msg lsm;
-static struct lttcomm_lttng_msg llm;
-
/* Variables */
static char *tracing_group;
static int connected;
strncpy(dst, src, len);
/* Enforce the NULL terminated byte */
dst[len - 1] = '\0';
+ } else if (dst) {
+ dst[0] = '\0';
}
}
/*
- * send_data_sessiond
+ * Copy domain to lttcomm_session_msg domain.
*
- * Send lttcomm_session_msg to the session daemon.
+ * If domain is unknown, default domain will be the kernel.
+ */
+static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src)
+{
+ if (src && dst) {
+ switch (src->type) {
+ case LTTNG_DOMAIN_KERNEL:
+ case LTTNG_DOMAIN_UST:
+ case LTTNG_DOMAIN_UST_EXEC_NAME:
+ case LTTNG_DOMAIN_UST_PID:
+ case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+ memcpy(dst, src, sizeof(struct lttng_domain));
+ break;
+ default:
+ dst->type = LTTNG_DOMAIN_KERNEL;
+ break;
+ }
+ }
+}
+
+/*
+ * Send lttcomm_session_msg to the session daemon.
*
- * On success, return 0
- * On error, return error code
+ * On success, return 0
+ * On error, return error code
*/
-static int send_data_sessiond(void)
+static int send_session_msg(struct lttcomm_session_msg *lsm)
{
int ret;
goto end;
}
- ret = lttcomm_send_unix_sock(sessiond_socket, &lsm, sizeof(lsm));
+ ret = lttcomm_send_creds_unix_sock(sessiond_socket, lsm,
+ sizeof(struct lttcomm_session_msg));
end:
return ret;
}
/*
- * recv_data_sessiond
- *
- * Receive data from the sessiond socket.
+ * Receive data from the sessiond socket.
*
- * On success, return 0
- * On error, return recv() error code
+ * On success, return 0
+ * On error, return recv() error code
*/
static int recv_data_sessiond(void *buf, size_t len)
{
/*
* Check if the specified group name exist.
*
- * If yes return 0, else return -1.
+ * If yes return 1, else return -1.
*/
static int check_tracing_group(const char *grp_name)
{
/* Alloc group list of the right size */
grp_list = malloc(grp_list_size * sizeof(gid_t));
+ if (!grp_list) {
+ ret = -1;
+ goto end;
+ }
grp_id = getgroups(grp_list_size, grp_list);
if (grp_id < -1) {
perror("getgroups");
for (i = 0; i < grp_list_size; i++) {
if (grp_list[i] == grp_tracing->gr_gid) {
- ret = 0;
+ ret = 1;
break;
}
}
}
/*
- * Set sessiond socket path by putting it in the global sessiond_sock_path
- * variable.
+ * Try connect to session daemon with sock_path.
+ *
+ * Return 0 on success, else -1
*/
-static int set_session_daemon_path(void)
+static int try_connect_sessiond(const char *sock_path)
{
int ret;
- /* Are we in the tracing group ? */
- ret = check_tracing_group(tracing_group);
- if (ret < 0 && getuid() != 0) {
+ /* If socket exist, we check if the daemon listens for connect. */
+ ret = access(sock_path, F_OK);
+ if (ret < 0) {
+ /* Not alive */
+ return -1;
+ }
+
+ ret = lttcomm_connect_unix_sock(sock_path);
+ if (ret < 0) {
+ /* Not alive */
+ return -1;
+ }
+
+ ret = lttcomm_close_unix_sock(ret);
+ if (ret < 0) {
+ perror("lttcomm_close_unix_sock");
+ }
+
+ return 0;
+}
+
+/*
+ * Set sessiond socket path by putting it in the global sessiond_sock_path
+ * variable.
+ */
+static int set_session_daemon_path(void)
+{
+ int ret;
+ int in_tgroup = 0; /* In tracing group */
+ uid_t uid;
+
+ uid = getuid();
+
+ if (uid != 0) {
+ /* Are we in the tracing group ? */
+ in_tgroup = check_tracing_group(tracing_group);
+ }
+
+ if (uid == 0) {
+ /* Root */
+ copy_string(sessiond_sock_path,
+ DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(sessiond_sock_path));
+ } else if (in_tgroup) {
+ /* Tracing group */
+ copy_string(sessiond_sock_path,
+ DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(sessiond_sock_path));
+
+ ret = try_connect_sessiond(sessiond_sock_path);
+ if (ret < 0) {
+ /* Global session daemon not available */
+ if (snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
+ DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
+ return -ENOMEM;
+ }
+ }
+ } else {
+ /* Not in tracing group and not root, default */
if (snprintf(sessiond_sock_path, PATH_MAX,
- DEFAULT_HOME_CLIENT_UNIX_SOCK,
- getenv("HOME")) < 0) {
+ DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
return -ENOMEM;
}
- } else {
- copy_string(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
- PATH_MAX);
}
return 0;
}
/*
- * Reset the session message structure.
- */
-static void reset_session_msg(void)
-{
- memset(&lsm, 0, sizeof(struct lttcomm_session_msg));
-}
-
-/*
- * ask_sessiond
+ * Ask the session daemon a specific command and put the data into buf.
*
- * Ask the session daemon a specific command and put the data into buf.
- *
- * Return size of data (only payload, not header).
+ * Return size of data (only payload, not header).
*/
-static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf)
+static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
{
int ret;
size_t size;
void *data = NULL;
+ struct lttcomm_lttng_msg llm;
ret = connect_sessiond();
if (ret < 0) {
goto end;
}
- lsm.cmd_type = lct;
-
/* Send command to session daemon */
- ret = send_data_sessiond();
+ ret = send_session_msg(lsm);
if (ret < 0) {
goto end;
}
size = llm.data_size;
if (size == 0) {
+ /* If client free with size 0 */
+ if (buf != NULL) {
+ *buf = NULL;
+ }
ret = 0;
goto end;
}
goto end;
}
+ /*
+ * Extra protection not to dereference a NULL pointer. If buf is NULL at
+ * this point, an error is returned and data is freed.
+ */
+ if (buf == NULL) {
+ ret = -1;
+ free(data);
+ goto end;
+ }
+
*buf = data;
ret = size;
end:
disconnect_sessiond();
- reset_session_msg();
return ret;
}
/*
- * Copy domain to lttcomm_session_msg domain. If unknown domain, default domain
- * will be the kernel.
+ * Create lttng handle and return pointer.
*/
-static void copy_lttng_domain(struct lttng_domain *dom)
+struct lttng_handle *lttng_create_handle(const char *session_name,
+ struct lttng_domain *domain)
{
- if (dom) {
- switch (dom->type) {
- case LTTNG_DOMAIN_KERNEL:
- case LTTNG_DOMAIN_UST:
- case LTTNG_DOMAIN_UST_EXEC_NAME:
- case LTTNG_DOMAIN_UST_PID:
- case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
- memcpy(&lsm.domain, dom, sizeof(struct lttng_domain));
- break;
- default:
- lsm.domain.type = LTTNG_DOMAIN_KERNEL;
- break;
- }
+ struct lttng_handle *handle;
+
+ handle = malloc(sizeof(struct lttng_handle));
+ if (handle == NULL) {
+ perror("malloc handle");
+ goto end;
+ }
+
+ /* Copy session name */
+ copy_string(handle->session_name, session_name,
+ sizeof(handle->session_name));
+
+ /* Copy lttng domain */
+ copy_lttng_domain(&handle->domain, domain);
+
+end:
+ return handle;
+}
+
+/*
+ * Destroy handle by free(3) the pointer.
+ */
+void lttng_destroy_handle(struct lttng_handle *handle)
+{
+ if (handle) {
+ free(handle);
}
}
+/*
+ * Register an outside consumer.
+ */
+int lttng_register_consumer(struct lttng_handle *handle,
+ const char *socket_path)
+{
+ struct lttcomm_session_msg lsm;
+
+ lsm.cmd_type = LTTNG_REGISTER_CONSUMER;
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+ copy_lttng_domain(&lsm.domain, &handle->domain);
+
+ copy_string(lsm.u.reg.path, socket_path, sizeof(lsm.u.reg.path));
+
+ return ask_sessiond(&lsm, NULL);
+}
+
/*
* Start tracing for all trace of the session.
*/
int lttng_start_tracing(const char *session_name)
{
- copy_string(lsm.session.name, session_name, NAME_MAX);
- return ask_sessiond(LTTNG_START_TRACE, NULL);
+ struct lttcomm_session_msg lsm;
+
+ if (session_name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_START_TRACE;
+
+ copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
*/
int lttng_stop_tracing(const char *session_name)
{
- copy_string(lsm.session.name, session_name, NAME_MAX);
- return ask_sessiond(LTTNG_STOP_TRACE, NULL);
+ struct lttcomm_session_msg lsm;
+
+ if (session_name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_STOP_TRACE;
+
+ copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
- * lttng_add_context
+ * Add context to event or/and channel.
*/
-int lttng_add_context(struct lttng_domain *domain,
+int lttng_add_context(struct lttng_handle *handle,
struct lttng_event_context *ctx, const char *event_name,
const char *channel_name)
{
- copy_string(lsm.u.context.channel_name, channel_name, NAME_MAX);
- copy_string(lsm.u.context.event_name, event_name, NAME_MAX);
- copy_lttng_domain(domain);
+ struct lttcomm_session_msg lsm;
- if (ctx) {
- memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
+ /* Safety check. Both are mandatory */
+ if (handle == NULL || ctx == NULL) {
+ return -1;
}
- return ask_sessiond(LTTNG_ADD_CONTEXT, NULL);
+ lsm.cmd_type = LTTNG_ADD_CONTEXT;
+
+ /* Copy channel name */
+ copy_string(lsm.u.context.channel_name, channel_name,
+ sizeof(lsm.u.context.channel_name));
+ /* Copy event name */
+ copy_string(lsm.u.context.event_name, event_name,
+ sizeof(lsm.u.context.event_name));
+
+ copy_lttng_domain(&lsm.domain, &handle->domain);
+
+ memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context));
+
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
- * lttng_enable_event
+ * Enable event
*/
-int lttng_enable_event(struct lttng_domain *domain,
+int lttng_enable_event(struct lttng_handle *handle,
struct lttng_event *ev, const char *channel_name)
{
- int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (handle == NULL || ev == NULL) {
+ return -1;
+ }
+ /* If no channel name, we put the default name */
if (channel_name == NULL) {
- copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX);
+ copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
+ sizeof(lsm.u.enable.channel_name));
} else {
- copy_string(lsm.u.enable.channel_name, channel_name, NAME_MAX);
+ copy_string(lsm.u.enable.channel_name, channel_name,
+ sizeof(lsm.u.enable.channel_name));
}
- copy_lttng_domain(domain);
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- if (ev == NULL) {
- ret = ask_sessiond(LTTNG_ENABLE_ALL_EVENT, NULL);
+ if (ev->name[0] != '\0') {
+ lsm.cmd_type = LTTNG_ENABLE_EVENT;
} else {
- memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event));
- ret = ask_sessiond(LTTNG_ENABLE_EVENT, NULL);
+ lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
}
+ memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
- return ret;
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
* Disable event of a channel and domain.
*/
-int lttng_disable_event(struct lttng_domain *domain, const char *name,
+int lttng_disable_event(struct lttng_handle *handle, const char *name,
const char *channel_name)
{
- int ret = -1;
+ struct lttcomm_session_msg lsm;
- if (channel_name == NULL) {
- copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX);
+ if (handle == NULL) {
+ return -1;
+ }
+
+ if (channel_name) {
+ copy_string(lsm.u.disable.channel_name, channel_name,
+ sizeof(lsm.u.disable.channel_name));
} else {
- copy_string(lsm.u.disable.channel_name, channel_name, NAME_MAX);
+ copy_string(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME,
+ sizeof(lsm.u.disable.channel_name));
}
- copy_lttng_domain(domain);
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- if (name == NULL) {
- ret = ask_sessiond(LTTNG_DISABLE_ALL_EVENT, NULL);
+ if (name != NULL) {
+ copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name));
+ lsm.cmd_type = LTTNG_DISABLE_EVENT;
} else {
- copy_string(lsm.u.disable.name, name, NAME_MAX);
- ret = ask_sessiond(LTTNG_DISABLE_EVENT, NULL);
+ lsm.cmd_type = LTTNG_DISABLE_ALL_EVENT;
}
- return ret;
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
* Enable channel per domain
*/
-int lttng_enable_channel(struct lttng_domain *domain,
+int lttng_enable_channel(struct lttng_handle *handle,
struct lttng_channel *chan)
{
- if (chan) {
- memcpy(&lsm.u.channel.chan, chan, sizeof(struct lttng_channel));
+ struct lttcomm_session_msg lsm;
+
+ /*
+ * NULL arguments are forbidden. No default values.
+ */
+ if (handle == NULL || chan == NULL) {
+ return -1;
}
- copy_lttng_domain(domain);
+ memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
+
+ lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
+
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- return ask_sessiond(LTTNG_ENABLE_CHANNEL, NULL);
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
* All tracing will be stopped for registered events of the channel.
*/
-int lttng_disable_channel(struct lttng_domain *domain, const char *name)
+int lttng_disable_channel(struct lttng_handle *handle, const char *name)
{
- copy_string(lsm.u.disable.channel_name, name, NAME_MAX);
- copy_lttng_domain(domain);
+ struct lttcomm_session_msg lsm;
+
+ /* Safety check. Both are mandatory */
+ if (handle == NULL || name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
+
+ copy_string(lsm.u.disable.channel_name, name,
+ sizeof(lsm.u.disable.channel_name));
+
+ copy_lttng_domain(&lsm.domain, &handle->domain);
+
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
- return ask_sessiond(LTTNG_DISABLE_CHANNEL, NULL);
+ return ask_sessiond(&lsm, NULL);
}
/*
* Return the size (bytes) of the list and set the events array.
* On error, return negative value.
*/
-int lttng_list_tracepoints(struct lttng_domain *domain,
+int lttng_list_tracepoints(struct lttng_handle *handle,
struct lttng_event **events)
{
int ret;
+ struct lttcomm_session_msg lsm;
- copy_lttng_domain(domain);
+ if (handle == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_LIST_TRACEPOINTS;
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- ret = ask_sessiond(LTTNG_LIST_TRACEPOINTS, (void **) events);
+ ret = ask_sessiond(&lsm, (void **) events);
if (ret < 0) {
return ret;
}
/*
* Return a human readable string of code
*/
-const char *lttng_get_readable_code(int code)
+const char *lttng_strerror(int code)
{
if (code > -LTTCOMM_OK) {
return "Ended with errors";
*/
int lttng_create_session(const char *name, const char *path)
{
- copy_string(lsm.session.name, name, NAME_MAX);
- copy_string(lsm.session.path, path, PATH_MAX);
- return ask_sessiond(LTTNG_CREATE_SESSION, NULL);
+ struct lttcomm_session_msg lsm;
+
+ lsm.cmd_type = LTTNG_CREATE_SESSION;
+ copy_string(lsm.session.name, name, sizeof(lsm.session.name));
+ copy_string(lsm.session.path, path, sizeof(lsm.session.path));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
* Destroy session using name.
*/
-int lttng_destroy_session(const char *name)
+int lttng_destroy_session(const char *session_name)
{
- copy_string(lsm.session.name, name, NAME_MAX);
- return ask_sessiond(LTTNG_DESTROY_SESSION, NULL);
+ struct lttcomm_session_msg lsm;
+
+ if (session_name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_DESTROY_SESSION;
+
+ copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
+
+ return ask_sessiond(&lsm, NULL);
}
/*
int lttng_list_sessions(struct lttng_session **sessions)
{
int ret;
+ struct lttcomm_session_msg lsm;
- ret = ask_sessiond(LTTNG_LIST_SESSIONS, (void**) sessions);
+ lsm.cmd_type = LTTNG_LIST_SESSIONS;
+ ret = ask_sessiond(&lsm, (void**) sessions);
if (ret < 0) {
return ret;
}
/*
* List domain of a session.
*/
-int lttng_list_domains(const char *session_name, struct lttng_domain **domains)
+int lttng_list_domains(const char *session_name,
+ struct lttng_domain **domains)
{
int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (session_name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_LIST_DOMAINS;
+
+ copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
- copy_string(lsm.session.name, session_name, NAME_MAX);
- ret = ask_sessiond(LTTNG_LIST_DOMAINS, (void**) domains);
+ ret = ask_sessiond(&lsm, (void**) domains);
if (ret < 0) {
return ret;
}
/*
* List channels of a session
*/
-int lttng_list_channels(struct lttng_domain *domain,
- const char *session_name, struct lttng_channel **channels)
+int lttng_list_channels(struct lttng_handle *handle,
+ struct lttng_channel **channels)
{
int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (handle == NULL) {
+ return -1;
+ }
- copy_string(lsm.session.name, session_name, NAME_MAX);
- copy_lttng_domain(domain);
+ lsm.cmd_type = LTTNG_LIST_CHANNELS;
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
- ret = ask_sessiond(LTTNG_LIST_CHANNELS, (void**) channels);
+ copy_lttng_domain(&lsm.domain, &handle->domain);
+
+ ret = ask_sessiond(&lsm, (void**) channels);
if (ret < 0) {
return ret;
}
/*
* List events of a session channel.
*/
-int lttng_list_events(struct lttng_domain *domain,
- const char *session_name, const char *channel_name,
- struct lttng_event **events)
+int lttng_list_events(struct lttng_handle *handle,
+ const char *channel_name, struct lttng_event **events)
{
int ret;
+ struct lttcomm_session_msg lsm;
+
+ /* Safety check. An handle and channel name are mandatory */
+ if (handle == NULL || channel_name == NULL) {
+ return -1;
+ }
+
+ lsm.cmd_type = LTTNG_LIST_EVENTS;
+ copy_string(lsm.session.name, handle->session_name,
+ sizeof(lsm.session.name));
+ copy_string(lsm.u.list.channel_name, channel_name,
+ sizeof(lsm.u.list.channel_name));
- copy_string(lsm.session.name, session_name, NAME_MAX);
- copy_string(lsm.u.list.channel_name, channel_name, NAME_MAX);
- copy_lttng_domain(domain);
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- ret = ask_sessiond(LTTNG_LIST_EVENTS, (void**) events);
+ ret = ask_sessiond(&lsm, (void**) events);
if (ret < 0) {
return ret;
}
}
/*
- * Set session name for the current lsm.
- */
-void lttng_set_session_name(const char *name)
-{
- copy_string(lsm.session.name, name, NAME_MAX);
-}
-
-/*
- * lttng_set_tracing_group
- *
- * Set tracing group variable with name. This function
- * allocate memory pointed by tracing_group.
+ * Set tracing group variable with name. This function allocate memory pointed
+ * by tracing_group.
*/
int lttng_set_tracing_group(const char *name)
{
+ if (name == NULL) {
+ return -1;
+ }
+
if (asprintf(&tracing_group, "%s", name) < 0) {
return -ENOMEM;
}
/*
* lttng_calibrate
*/
-int lttng_calibrate(struct lttng_domain *domain,
+int lttng_calibrate(struct lttng_handle *handle,
struct lttng_calibrate *calibrate)
{
- int ret;
+ struct lttcomm_session_msg lsm;
- copy_lttng_domain(domain);
+ /* Safety check. NULL pointer are forbidden */
+ if (handle == NULL || calibrate == NULL) {
+ return -1;
+ }
- memcpy(&lsm.u.calibrate, calibrate, sizeof(struct lttng_calibrate));
- ret = ask_sessiond(LTTNG_CALIBRATE, NULL);
+ lsm.cmd_type = LTTNG_CALIBRATE;
+ copy_lttng_domain(&lsm.domain, &handle->domain);
- return ret;
+ memcpy(&lsm.u.calibrate, calibrate, sizeof(lsm.u.calibrate));
+
+ return ask_sessiond(&lsm, NULL);
+}
+
+/*
+ * Set default channel attributes.
+ */
+void lttng_channel_set_default_attr(struct lttng_domain *domain,
+ struct lttng_channel_attr *attr)
+{
+ /* Safety check */
+ if (attr == NULL || domain == NULL) {
+ return;
+ }
+
+ switch (domain->type) {
+ case LTTNG_DOMAIN_KERNEL:
+ attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
+ attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+ attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+ attr->subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
+ attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
+ attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+ break;
+ case LTTNG_DOMAIN_UST:
+ case LTTNG_DOMAIN_UST_EXEC_NAME:
+ case LTTNG_DOMAIN_UST_PID:
+ case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+ attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
+ attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+ attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+ attr->subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
+ attr->num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
+ attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
+ break;
+ default:
+ /* Default behavior */
+ memset(attr, 0, sizeof(struct lttng_channel_attr));
+ break;
+ }
}
/*
- * lttng_check_session_daemon
+ * Check if session daemon is alive.
*
- * Yes, return 1
- * No, return 0
- * Error, return negative value
+ * Return 1 if alive or 0 if not.
+ * On error return -1
*/
int lttng_session_daemon_alive(void)
{
return ret;
}
- /* 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;
+ if (strlen(sessiond_sock_path) == 0) {
+ /* No socket path set. Weird error */
+ return -1;
}
- ret = lttcomm_connect_unix_sock(sessiond_sock_path);
+ ret = try_connect_sessiond(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;