#include "agent.h"
#include "ust-app.h"
#include "utils.h"
-#include "error.h"
+#include "common/error.h"
#define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS)
}
/* Filter expression */
- if (strncmp(event->filter_expression, key->filter_expression,
- strlen(event->filter_expression)) != 0) {
+ if (!!event->filter_expression != !!key->filter_expression) {
+ /* One has a filter expression, the other does not */
goto no_match;
}
+ if (event->filter_expression) {
+ if (strncmp(event->filter_expression, key->filter_expression,
+ strlen(event->filter_expression)) != 0) {
+ goto no_match;
+ }
+ }
+
return 1;
no_match:
for (i = 0; i < nb_event; i++) {
offset += len;
- strncpy(tmp_events[i].name, reply->payload + offset,
- sizeof(tmp_events[i].name));
+ if (lttng_strncpy(tmp_events[i].name, reply->payload + offset,
+ sizeof(tmp_events[i].name))) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
tmp_events[i].pid = app->pid;
tmp_events[i].enabled = -1;
len = strlen(reply->payload + offset) + 1;
}
data_size = sizeof(msg) + filter_expression_length;
- ret = send_header(app->sock, data_size, AGENT_CMD_ENABLE, 0);
- if (ret < 0) {
- goto error_io;
- }
-
memset(&msg, 0, sizeof(msg));
msg.loglevel_value = htobe32(event->loglevel_value);
msg.loglevel_type = htobe32(event->loglevel_type);
- strncpy(msg.name, event->name, sizeof(msg.name));
+ if (lttng_strncpy(msg.name, event->name, sizeof(msg.name))) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
msg.filter_expression_length = htobe32(filter_expression_length);
+ ret = send_header(app->sock, data_size, AGENT_CMD_ENABLE, 0);
+ if (ret < 0) {
+ goto error_io;
+ }
+
bytes_to_send = zmalloc(data_size);
if (!bytes_to_send) {
ret = LTTNG_ERR_NOMEM;
app->pid, app->sock->fd);
data_size = sizeof(msg);
+ memset(&msg, 0, sizeof(msg));
+ if (lttng_strncpy(msg.name, event->name, sizeof(msg.name))) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
ret = send_header(app->sock, data_size, AGENT_CMD_DISABLE, 0);
if (ret < 0) {
goto error_io;
}
- memset(&msg, 0, sizeof(msg));
- strncpy(msg.name, event->name, sizeof(msg.name));
ret = send_payload(app->sock, &msg, sizeof(msg));
if (ret < 0) {
goto error_io;
}
static
-struct agent_app_ctx *create_app_ctx(struct lttng_event_context *ctx)
+struct agent_app_ctx *create_app_ctx(const struct lttng_event_context *ctx)
{
struct agent_app_ctx *agent_ctx = NULL;
*
* Return LTTNG_OK on success or else a LTTNG_ERR* code.
*/
-int agent_enable_context(struct lttng_event_context *ctx,
+int agent_enable_context(const struct lttng_event_context *ctx,
enum lttng_domain_type domain)
{
int ret;
agent_ctx = create_app_ctx(ctx);
if (!agent_ctx) {
+ ret = LTTNG_ERR_NOMEM;
goto error_unlock;
}
/* Enable event on agent application through TCP socket. */
ret = app_context_op(app, agent_ctx, AGENT_CMD_APP_CTX_ENABLE);
+ destroy_app_ctx(agent_ctx);
if (ret != LTTNG_OK) {
- destroy_app_ctx(agent_ctx);
goto error_unlock;
}
}
*
* Return LTTNG_OK on success or else a LTTNG_ERR* code.
*/
-int disable_context(struct agent_app_ctx *ctx, enum lttng_domain_type domain)
+static int disable_context(struct agent_app_ctx *ctx,
+ enum lttng_domain_type domain)
{
int ret = LTTNG_OK;
struct agent_app *app;
/*
* Unique add of a agent context to an agent object.
*/
-int agent_add_context(struct lttng_event_context *ctx, struct agent *agt)
+int agent_add_context(const struct lttng_event_context *ctx, struct agent *agt)
{
int ret = LTTNG_OK;
struct agent_app_ctx *agent_ctx = NULL;