/*
* Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
#define _LGPL_SOURCE
#include <assert.h>
#include <urcu/uatomic.h>
+#include <urcu/rculist.h>
#include <common/common.h>
#include <common/sessiond-comm/agent.h>
#define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS)
+/*
+ * Agent application context representation.
+ */
+struct agent_app_ctx {
+ char *provider_name;
+ char *ctx_name;
+
+ /* agent_app_ctx are part of the agent app_ctx_list. */
+ struct cds_list_head list_node;
+
+ /* For call_rcu teardown. */
+ struct rcu_head rcu_node;
+};
+
/*
* Human readable agent return code.
*/
*
* Return 0 on success or else a negative errno value of sendmsg() op.
*/
-static int send_payload(struct lttcomm_sock *sock, void *data,
+static int send_payload(struct lttcomm_sock *sock, const void *data,
size_t size)
{
int ret;
uint64_t data_size;
size_t filter_expression_length;
uint32_t reply_ret_code;
- struct lttcomm_agent_enable msg;
+ struct lttcomm_agent_enable_event msg;
struct lttcomm_agent_generic_reply reply;
assert(app);
return ret;
}
+/*
+ * Send Pascal-style string. Size is sent as a 32-bit big endian integer.
+ */
+static
+int send_pstring(struct lttcomm_sock *sock, const char *str, uint32_t len)
+{
+ int ret;
+ uint32_t len_be;
+
+ len_be = htobe32(len);
+ ret = send_payload(sock, &len_be, sizeof(len_be));
+ if (ret) {
+ goto end;
+ }
+
+ ret = send_payload(sock, str, len);
+ if (ret) {
+ goto end;
+ }
+end:
+ return ret;
+}
+
+/*
+ * Internal enable application context on an agent application. This function
+ * communicates with the agent to enable a given application context.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+static int app_context_op(struct agent_app *app,
+ struct agent_app_ctx *ctx, enum lttcomm_agent_command cmd)
+{
+ int ret;
+ uint32_t reply_ret_code;
+ struct lttcomm_agent_generic_reply reply;
+ size_t app_ctx_provider_name_len, app_ctx_name_len, data_size;
+
+ assert(app);
+ assert(app->sock);
+ assert(ctx);
+ assert(cmd == AGENT_CMD_APP_CTX_ENABLE ||
+ cmd == AGENT_CMD_APP_CTX_DISABLE);
+
+ DBG2("Agent %s application %s:%s for app pid: %d and socket %d",
+ cmd == AGENT_CMD_APP_CTX_ENABLE ? "enabling" : "disabling",
+ ctx->provider_name, ctx->ctx_name,
+ app->pid, app->sock->fd);
+
+ /*
+ * Calculate the payload's size, which consists of the size (u32, BE)
+ * of the provider name, the NULL-terminated provider name string, the
+ * size (u32, BE) of the context name, followed by the NULL-terminated
+ * context name string.
+ */
+ app_ctx_provider_name_len = strlen(ctx->provider_name) + 1;
+ app_ctx_name_len = strlen(ctx->ctx_name) + 1;
+ data_size = sizeof(uint32_t) + app_ctx_provider_name_len +
+ sizeof(uint32_t) + app_ctx_name_len;
+
+ ret = send_header(app->sock, data_size, cmd, 0);
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ if (app_ctx_provider_name_len > UINT32_MAX ||
+ app_ctx_name_len > UINT32_MAX) {
+ ERR("Application context name > MAX_UINT32");
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ ret = send_pstring(app->sock, ctx->provider_name,
+ (uint32_t) app_ctx_provider_name_len);
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ ret = send_pstring(app->sock, ctx->ctx_name,
+ (uint32_t) app_ctx_name_len);
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ ret = recv_reply(app->sock, &reply, sizeof(reply));
+ if (ret < 0) {
+ goto error_io;
+ }
+
+ reply_ret_code = be32toh(reply.ret_code);
+ log_reply_code(reply_ret_code);
+ switch (reply_ret_code) {
+ case AGENT_RET_CODE_SUCCESS:
+ break;
+ default:
+ ret = LTTNG_ERR_UNK;
+ goto error;
+ }
+
+ return LTTNG_OK;
+
+error_io:
+ ret = LTTNG_ERR_UST_ENABLE_FAIL;
+error:
+ return ret;
+}
+
/*
* Internal disable agent event call on a agent application. This function
* communicates with the agent to disable a given event.
int ret;
uint64_t data_size;
uint32_t reply_ret_code;
- struct lttcomm_agent_disable msg;
+ struct lttcomm_agent_disable_event msg;
struct lttcomm_agent_generic_reply reply;
assert(app);
return ret;
}
+static
+void destroy_app_ctx(struct agent_app_ctx *ctx)
+{
+ free(ctx->provider_name);
+ free(ctx->ctx_name);
+ free(ctx);
+}
+
+static
+struct agent_app_ctx *create_app_ctx(struct lttng_event_context *ctx)
+{
+ struct agent_app_ctx *agent_ctx = NULL;
+
+ if (!ctx) {
+ goto end;
+ }
+
+ assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT);
+ agent_ctx = zmalloc(sizeof(*ctx));
+ if (!agent_ctx) {
+ goto end;
+ }
+
+ agent_ctx->provider_name = strdup(ctx->u.app_ctx.provider_name);
+ agent_ctx->ctx_name = strdup(ctx->u.app_ctx.ctx_name);
+ if (!agent_ctx->provider_name || !agent_ctx->ctx_name) {
+ destroy_app_ctx(agent_ctx);
+ agent_ctx = NULL;
+ }
+end:
+ return agent_ctx;
+}
+
+/*
+ * Enable agent context on every agent applications registered with the session
+ * daemon.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int agent_enable_context(struct lttng_event_context *ctx,
+ enum lttng_domain_type domain)
+{
+ int ret;
+ struct agent_app *app;
+ struct lttng_ht_iter iter;
+
+ assert(ctx);
+ if (ctx->ctx != LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ rcu_read_lock();
+
+ cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+ node.node) {
+ struct agent_app_ctx *agent_ctx;
+
+ if (app->domain != domain) {
+ continue;
+ }
+
+ agent_ctx = create_app_ctx(ctx);
+ if (!agent_ctx) {
+ goto error_unlock;
+ }
+
+ /* Enable event on agent application through TCP socket. */
+ ret = app_context_op(app, agent_ctx, AGENT_CMD_APP_CTX_ENABLE);
+ if (ret != LTTNG_OK) {
+ destroy_app_ctx(agent_ctx);
+ goto error_unlock;
+ }
+ }
+
+ ret = LTTNG_OK;
+
+error_unlock:
+ rcu_read_unlock();
+error:
+ return ret;
+}
+
/*
- * Disable agent event on every agent applications registered with the session
+ * Disable agent event on every agent application registered with the session
* daemon.
*
* Return LTTNG_OK on success or else a LTTNG_ERR* code.
return ret;
}
+/*
+ * Disable agent context on every agent application registered with the session
+ * daemon.
+ *
+ * Return LTTNG_OK on success or else a LTTNG_ERR* code.
+ */
+int disable_context(struct agent_app_ctx *ctx, enum lttng_domain_type domain)
+{
+ int ret = LTTNG_OK;
+ struct agent_app *app;
+ struct lttng_ht_iter iter;
+
+ assert(ctx);
+
+ rcu_read_lock();
+ DBG2("Disabling agent application context %s:%s",
+ ctx->provider_name, ctx->ctx_name);
+ cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app,
+ node.node) {
+ if (app->domain != domain) {
+ continue;
+ }
+
+ ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_DISABLE);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+ }
+end:
+ rcu_read_unlock();
+ return ret;
+}
+
/*
* Ask every agent for the list of possible event. Events is allocated with the
* events of every agent application.
}
lttng_ht_node_init_u64(&agt->node, agt->domain);
+ CDS_INIT_LIST_HEAD(&agt->app_ctx_list);
return 0;
error:
agt->being_used = 1;
}
+/*
+ * Unique add of a agent context to an agent object.
+ */
+int agent_add_context(struct lttng_event_context *ctx, struct agent *agt)
+{
+ int ret = LTTNG_OK;
+ struct agent_app_ctx *agent_ctx = NULL;
+
+ assert(ctx);
+ assert(agt);
+ assert(agt->events);
+ assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT);
+
+ agent_ctx = create_app_ctx(ctx);
+ if (!agent_ctx) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ DBG3("Agent adding context %s:%s", ctx->u.app_ctx.provider_name,
+ ctx->u.app_ctx.ctx_name);
+ cds_list_add_tail_rcu(&agent_ctx->list_node, &agt->app_ctx_list);
+end:
+ return ret;
+}
+
/*
* Find multiple agent events sharing the given name.
*
free(event);
}
+static
+void destroy_app_ctx_rcu(struct rcu_head *head)
+{
+ struct agent_app_ctx *ctx =
+ caa_container_of(head, struct agent_app_ctx, rcu_node);
+
+ destroy_app_ctx(ctx);
+}
+
/*
* Destroy an agent completely.
*/
{
struct lttng_ht_node_str *node;
struct lttng_ht_iter iter;
+ struct agent_app_ctx *ctx;
assert(agt);
struct agent_event *event;
/*
- * When destroying an event, we have to try to disable it on the agent
- * side so the event stops generating data. The return value is not
- * important since we have to continue anyway destroying the object.
+ * When destroying an event, we have to try to disable it on the
+ * agent side so the event stops generating data. The return
+ * value is not important since we have to continue anyway
+ * destroying the object.
*/
event = caa_container_of(node, struct agent_event, node);
(void) agent_disable_event(event, agt->domain);
assert(!ret);
call_rcu(&node->head, destroy_event_agent_rcu);
}
- rcu_read_unlock();
+ cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) {
+ (void) disable_context(ctx, agt->domain);
+ cds_list_del(&ctx->list_node);
+ call_rcu(&ctx->rcu_node, destroy_app_ctx_rcu);
+ }
+ rcu_read_unlock();
ht_cleanup_push(agt->events);
free(agt);
}
struct agent_app *app;
struct agent_event *event;
struct lttng_ht_iter iter;
+ struct agent_app_ctx *ctx;
assert(agt);
assert(sock >= 0);
DBG("Agent updating app socket %d", sock);
rcu_read_lock();
+ app = agent_find_app_by_sock(sock);
+ /*
+ * We are in the registration path thus if the application is gone,
+ * there is a serious code flow error.
+ */
+ assert(app);
cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) {
/* Skip event if disabled. */
if (!event->enabled) {
continue;
}
- app = agent_find_app_by_sock(sock);
- /*
- * We are in the registration path thus if the application is gone,
- * there is a serious code flow error.
- */
- assert(app);
-
ret = enable_event(app, event);
if (ret != LTTNG_OK) {
DBG2("Agent update unable to enable event %s on app pid: %d sock %d",
continue;
}
}
+
+ cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) {
+ ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_ENABLE);
+ if (ret != LTTNG_OK) {
+ DBG2("Agent update unable to add application context %s:%s on app pid: %d sock %d",
+ ctx->provider_name, ctx->ctx_name,
+ app->pid, app->sock->fd);
+ continue;
+ }
+ }
+
rcu_read_unlock();
}
/*
* Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
/* Contains event indexed by name. */
struct lttng_ht *events;
+ /* Application context list (struct agent_app_ctx). */
+ struct cds_list_head app_ctx_list;
+
/* Node used for the hash table indexed by domain type. */
struct lttng_ht_node_u64 node;
};
void agent_delete_event(struct agent_event *event, struct agent *agt);
void agent_destroy_event(struct agent_event *event);
+/* Agent context API.*/
+int agent_enable_context(struct lttng_event_context *ctx,
+ enum lttng_domain_type domain);
+int agent_add_context(struct lttng_event_context *ctx, struct agent *agt);
+
/* Agent app API. */
struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
struct lttcomm_sock *sock);
/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
enum lttng_buffer_type type)
{
struct lttng_channel *chan;
+ const char *channel_name = DEFAULT_CHANNEL_NAME;
chan = zmalloc(sizeof(struct lttng_channel));
if (chan == NULL) {
goto error_alloc;
}
- if (snprintf(chan->name, sizeof(chan->name), "%s",
- DEFAULT_CHANNEL_NAME) < 0) {
- PERROR("snprintf default channel name");
- goto error;
- }
-
/* Same for all domains. */
chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
chan->attr.tracefile_size = DEFAULT_CHANNEL_TRACEFILE_SIZE;
chan->attr.read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER;
chan->attr.live_timer_interval = DEFAULT_KERNEL_CHANNEL_LIVE_TIMER;
break;
+ case LTTNG_DOMAIN_JUL:
+ channel_name = DEFAULT_JUL_CHANNEL_NAME;
+ goto common_ust;
+ case LTTNG_DOMAIN_LOG4J:
+ channel_name = DEFAULT_LOG4J_CHANNEL_NAME;
+ goto common_ust;
+ case LTTNG_DOMAIN_PYTHON:
+ channel_name = DEFAULT_PYTHON_CHANNEL_NAME;
+ goto common_ust;
case LTTNG_DOMAIN_UST:
+common_ust:
switch (type) {
case LTTNG_BUFFER_PER_UID:
chan->attr.subbuf_size = default_get_ust_uid_channel_subbuf_size();
goto error; /* Not implemented */
}
+ if (snprintf(chan->name, sizeof(chan->name), "%s",
+ channel_name) < 0) {
+ PERROR("snprintf default channel name");
+ goto error;
+ }
return chan;
error:
/*
* Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
char *channel_name, struct lttng_event_context *ctx, int kwpipe)
{
int ret, chan_kern_created = 0, chan_ust_created = 0;
+ char *app_ctx_provider_name = NULL, *app_ctx_name = NULL;
+
+ if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
+ app_ctx_provider_name = ctx->u.app_ctx.provider_name;
+ app_ctx_name = ctx->u.app_ctx.ctx_name;
+ }
switch (domain) {
case LTTNG_DOMAIN_KERNEL:
goto error;
}
break;
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ {
+ /*
+ * Validate channel name.
+ * If no channel name is given and the domain is JUL or LOG4J,
+ * set it to the appropriate domain-specific channel name. If
+ * a name is provided but does not match the expexted channel
+ * name, return an error.
+ */
+ if (domain == LTTNG_DOMAIN_JUL && *channel_name &&
+ strcmp(channel_name,
+ DEFAULT_JUL_CHANNEL_NAME)) {
+ ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+ goto error;
+ } else if (domain == LTTNG_DOMAIN_LOG4J && *channel_name &&
+ strcmp(channel_name,
+ DEFAULT_LOG4J_CHANNEL_NAME)) {
+ ret = LTTNG_ERR_UST_CHAN_NOT_FOUND;
+ goto error;
+ }
+ }
case LTTNG_DOMAIN_UST:
{
struct ltt_ust_session *usess = session->ust_session;
}
ret = context_ust_add(usess, domain, ctx, channel_name);
+ free(app_ctx_provider_name);
+ free(app_ctx_name);
+ app_ctx_name = NULL;
+ app_ctx_provider_name = NULL;
if (ret != LTTNG_OK) {
goto error;
}
goto error;
}
- return LTTNG_OK;
+ ret = LTTNG_OK;
+ goto end;
error:
if (chan_kern_created) {
uchan);
trace_ust_destroy_channel(uchan);
}
+end:
+ free(app_ctx_provider_name);
+ free(app_ctx_name);
return ret;
}
/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
#include "kernel.h"
#include "ust-app.h"
#include "trace-ust.h"
+#include "agent.h"
/*
* Add kernel context to all channel.
struct ltt_ust_channel *uchan, struct lttng_event_context *ctx)
{
int ret;
- struct ltt_ust_context *uctx;
+ struct ltt_ust_context *uctx = NULL;
assert(usess);
assert(uchan);
assert(ctx);
- assert(domain == LTTNG_DOMAIN_UST);
/* Check if context is duplicate */
cds_list_for_each_entry(uctx, &uchan->ctx_list, list) {
goto duplicate;
}
}
+ uctx = NULL;
+
+ switch (domain) {
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ {
+ struct agent *agt = trace_ust_find_agent(usess, domain);
+
+ if (!agt) {
+ agt = agent_create(domain);
+ if (!agt) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ agent_add(agt, usess->agents);
+ }
+ ret = agent_add_context(ctx, agt);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+
+ ret = agent_enable_context(ctx, domain);
+ if (ret != LTTNG_OK) {
+ goto error;
+ }
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
+ break;
+ default:
+ assert(0);
+ }
/* Create ltt UST context */
uctx = trace_ust_create_context(ctx);
assert(usess);
assert(ctx);
assert(channel_name);
- assert(domain == LTTNG_DOMAIN_UST);
rcu_read_lock();
LTTNG_UST_CONTEXT_IP = 4,
LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5,
LTTNG_UST_CONTEXT_CPU_ID = 6,
+ LTTNG_UST_CONTEXT_APP_CONTEXT = 7,
};
struct lttng_ust_perf_counter_ctx {
union {
struct lttng_ust_perf_counter_ctx perf_counter;
+ struct {
+ /* Includes trailing '\0'. */
+ uint32_t provider_name_len;
+ uint32_t ctx_name_len;
+ } app_ctx;
char padding[LTTNG_UST_CONTEXT_PADDING2];
} u;
} LTTNG_PACKED;
* API used by sessiond.
*/
+struct lttng_ust_context_attr {
+ enum lttng_ust_context_type ctx;
+ union {
+ struct lttng_ust_perf_counter_ctx perf_counter;
+ struct {
+ char *provider_name;
+ char *ctx_name;
+ } app_ctx;
+ } u;
+};
+
/*
* Error values: all the following functions return:
* >= 0: Success (LTTNG_UST_OK)
int ustctl_create_event(int sock, struct lttng_ust_event *ev,
struct lttng_ust_object_data *channel_data,
struct lttng_ust_object_data **event_data);
-int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
+int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
struct lttng_ust_object_data *obj_data,
struct lttng_ust_object_data **context_data);
int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
}
static
-int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type)
+int trace_ust_context_type_event_to_ust(
+ enum lttng_event_context_type type)
{
int utype;
utype = LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER;
}
break;
+ case LTTNG_EVENT_CONTEXT_APP_CONTEXT:
+ utype = LTTNG_UST_CONTEXT_APP_CONTEXT;
+ break;
default:
utype = -1;
break;
struct ltt_ust_context *trace_ust_create_context(
struct lttng_event_context *ctx)
{
- struct ltt_ust_context *uctx;
+ struct ltt_ust_context *uctx = NULL;
int utype;
assert(ctx);
utype = trace_ust_context_type_event_to_ust(ctx->ctx);
if (utype < 0) {
ERR("Invalid UST context");
- return NULL;
+ goto end;
}
uctx = zmalloc(sizeof(struct ltt_ust_context));
- if (uctx == NULL) {
+ if (!uctx) {
PERROR("zmalloc ltt_ust_context");
- goto error;
+ goto end;
}
uctx->ctx.ctx = (enum lttng_ust_context_type) utype;
LTTNG_UST_SYM_NAME_LEN);
uctx->ctx.u.perf_counter.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0';
break;
+ case LTTNG_UST_CONTEXT_APP_CONTEXT:
+ {
+ char *provider_name = NULL, *ctx_name = NULL;
+
+ provider_name = strdup(ctx->u.app_ctx.provider_name);
+ if (!provider_name) {
+ goto error;
+ }
+ uctx->ctx.u.app_ctx.provider_name = provider_name;
+
+ ctx_name = strdup(ctx->u.app_ctx.ctx_name);
+ if (!ctx_name) {
+ goto error;
+ }
+ uctx->ctx.u.app_ctx.ctx_name = ctx_name;
+ break;
+ }
default:
break;
}
lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx);
-
+end:
return uctx;
-
error:
+ trace_ust_destroy_context(uctx);
return NULL;
}
struct ltt_ust_context *ctx =
caa_container_of(node, struct ltt_ust_context, node);
- free(ctx);
+ trace_ust_destroy_context(ctx);
}
/*
free(event);
}
+/*
+ * Cleanup ust context structure.
+ */
+void trace_ust_destroy_context(struct ltt_ust_context *ctx)
+{
+ assert(ctx);
+
+ if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) {
+ free(ctx->ctx.u.app_ctx.provider_name);
+ free(ctx->ctx.u.app_ctx.ctx_name);
+ }
+ free(ctx);
+}
+
/*
* URCU intermediate call to complete destroy event.
*/
/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
/* Context hash table nodes */
struct ltt_ust_context {
- struct lttng_ust_context ctx;
+ struct lttng_ust_context_attr ctx;
struct lttng_ht_node_ulong node;
struct cds_list_head list;
};
void trace_ust_destroy_session(struct ltt_ust_session *session);
void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
void trace_ust_destroy_event(struct ltt_ust_event *event);
+void trace_ust_destroy_context(struct ltt_ust_context *ctx);
int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
* Alloc new UST app context.
*/
static
-struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx)
+struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx)
{
struct ust_app_ctx *ua_ctx;
if (uctx) {
memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx));
+ if (uctx->ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) {
+ char *provider_name = NULL, *ctx_name = NULL;
+
+ provider_name = strdup(uctx->u.app_ctx.provider_name);
+ ctx_name = strdup(uctx->u.app_ctx.ctx_name);
+ if (!provider_name || !ctx_name) {
+ free(provider_name);
+ free(ctx_name);
+ goto error;
+ }
+
+ ua_ctx->ctx.u.app_ctx.provider_name = provider_name;
+ ua_ctx->ctx.u.app_ctx.ctx_name = ctx_name;
+ }
}
DBG3("UST app context %d allocated", ua_ctx->ctx.ctx);
-
-error:
return ua_ctx;
+error:
+ free(ua_ctx);
+ return NULL;
}
/*
struct ltt_ust_event *uevent;
struct ltt_ust_context *uctx;
struct ust_app_event *ua_event;
- struct ust_app_ctx *ua_ctx;
DBG2("UST app shadow copy of channel %s started", ua_chan->name);
ua_chan->tracing_channel_id = uchan->id;
cds_list_for_each_entry(uctx, &uchan->ctx_list, list) {
- ua_ctx = alloc_ust_app_ctx(&uctx->ctx);
+ struct ust_app_ctx *ua_ctx = alloc_ust_app_ctx(&uctx->ctx);
+
if (ua_ctx == NULL) {
continue;
}
static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key)
{
struct ust_app_ctx *ctx;
- const struct lttng_ust_context *key;
+ const struct lttng_ust_context_attr *key;
assert(node);
assert(_key);
goto no_match;
}
- /* Check the name in the case of perf thread counters. */
- if (key->ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) {
+ switch(key->ctx) {
+ case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
if (strncmp(key->u.perf_counter.name,
- ctx->ctx.u.perf_counter.name,
- sizeof(key->u.perf_counter.name))) {
+ ctx->ctx.u.perf_counter.name,
+ sizeof(key->u.perf_counter.name))) {
+ goto no_match;
+ }
+ break;
+ case LTTNG_UST_CONTEXT_APP_CONTEXT:
+ if (strcmp(key->u.app_ctx.provider_name,
+ ctx->ctx.u.app_ctx.provider_name) ||
+ strcmp(key->u.app_ctx.ctx_name,
+ ctx->ctx.u.app_ctx.ctx_name)) {
goto no_match;
}
+ break;
+ default:
+ break;
}
/* Match. */
*/
static
struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht,
- struct lttng_ust_context *uctx)
+ struct lttng_ust_context_attr *uctx)
{
struct lttng_ht_iter iter;
struct lttng_ht_node_ulong *node;
*/
static
int create_ust_app_channel_context(struct ust_app_session *ua_sess,
- struct ust_app_channel *ua_chan, struct lttng_ust_context *uctx,
+ struct ust_app_channel *ua_chan,
+ struct lttng_ust_context_attr *uctx,
struct ust_app *app)
{
int ret = 0;
/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 only,
struct ust_app_ctx {
int handle;
- struct lttng_ust_context ctx;
+ struct lttng_ust_context_attr ctx;
struct lttng_ust_object_data *obj;
struct lttng_ht_node_ulong node;
struct cds_list_head list;
/*
* Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
+ * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License, version 2 only, as
* Command value passed in the header.
*/
enum lttcomm_agent_command {
- AGENT_CMD_LIST = 1,
- AGENT_CMD_ENABLE = 2,
- AGENT_CMD_DISABLE = 3,
- AGENT_CMD_REG_DONE = 4, /* End registration process. */
+ AGENT_CMD_LIST = 1,
+ AGENT_CMD_ENABLE = 2,
+ AGENT_CMD_DISABLE = 3,
+ AGENT_CMD_REG_DONE = 4, /* End registration process. */
+ AGENT_CMD_APP_CTX_ENABLE = 5,
+ AGENT_CMD_APP_CTX_DISABLE = 6,
};
/*
*/
enum lttcomm_agent_ret_code {
/* Success, assumed to be the first entry */
- AGENT_RET_CODE_SUCCESS = 1,
+ AGENT_RET_CODE_SUCCESS = 1,
/* Invalid command */
- AGENT_RET_CODE_INVALID = 2,
+ AGENT_RET_CODE_INVALID = 2,
/* Unknown logger name */
- AGENT_RET_CODE_UNKNOWN_NAME = 3,
+ AGENT_RET_CODE_UNKNOWN_NAME = 3,
AGENT_RET_CODE_NR,
};
* Enable event command payload. Will be immediately followed by the
* variable-length string representing the filter expression.
*/
-struct lttcomm_agent_enable {
+struct lttcomm_agent_enable_event {
uint32_t loglevel_value;
uint32_t loglevel_type;
char name[LTTNG_SYMBOL_NAME_LEN];
/*
* Disable event command payload.
*/
-struct lttcomm_agent_disable {
+struct lttcomm_agent_disable_event {
char name[LTTNG_SYMBOL_NAME_LEN];
} LTTNG_PACKED;