#include "agent.h"
#include "ust-app.h"
#include "utils.h"
+#include "error.h"
+
+#define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS)
+
+/*
+ * Human readable agent return code.
+ */
+static const char *error_string_array[] = {
+ [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_SUCCESS) ] = "Success",
+ [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_INVALID) ] = "Invalid command",
+ [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_UNKNOWN_NAME) ] = "Unknown logger name",
+
+ /* Last element */
+ [ AGENT_RET_CODE_INDEX(AGENT_RET_CODE_NR) ] = "Unknown code",
+};
+
+static
+void log_reply_code(uint32_t in_reply_ret_code)
+{
+ int level = PRINT_DBG3;
+ /*
+ * reply_ret_code and in_reply_ret_code are kept separate to have a
+ * sanitized value (used to retrieve the human readable string) and the
+ * original value which is logged as-is.
+ */
+ uint32_t reply_ret_code = in_reply_ret_code;
+
+ if (reply_ret_code < AGENT_RET_CODE_SUCCESS ||
+ reply_ret_code >= AGENT_RET_CODE_NR) {
+ reply_ret_code = AGENT_RET_CODE_NR;
+ level = PRINT_ERR;
+ }
+
+ LOG(level, "Agent replied with retcode: %s (%"PRIu32")",
+ error_string_array[AGENT_RET_CODE_INDEX(
+ reply_ret_code)],
+ in_reply_ret_code);
+}
/*
* Match function for the events hash table lookup by name.
struct agent_event *event =
caa_container_of(node, struct agent_event, node);
- free(event);
+ agent_destroy_event(event);
}
/*
int ret, i, len = 0, offset = 0;
uint32_t nb_event;
size_t data_size;
+ uint32_t reply_ret_code;
struct lttng_event *tmp_events = NULL;
struct lttcomm_agent_list_reply *reply = NULL;
struct lttcomm_agent_list_reply_hdr reply_hdr;
goto error_io;
}
- switch (be32toh(reply_hdr.ret_code)) {
+ reply_ret_code = be32toh(reply_hdr.ret_code);
+ log_reply_code(reply_ret_code);
+ switch (reply_ret_code) {
case AGENT_RET_CODE_SUCCESS:
data_size = be32toh(reply_hdr.data_size) + sizeof(*reply);
break;
default:
- ERR("Agent returned an unknown code: %" PRIu32,
- be32toh(reply_hdr.ret_code));
- ret = LTTNG_ERR_FATAL;
+ ret = LTTNG_ERR_UNK;
goto error;
}
{
int ret;
uint64_t data_size;
+ uint32_t reply_ret_code;
struct lttcomm_agent_enable msg;
struct lttcomm_agent_generic_reply reply;
goto error_io;
}
- switch (be32toh(reply.ret_code)) {
+ reply_ret_code = be32toh(reply.ret_code);
+ log_reply_code(reply_ret_code);
+ switch (reply_ret_code) {
case AGENT_RET_CODE_SUCCESS:
break;
case AGENT_RET_CODE_UNKNOWN_NAME:
ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
goto error;
default:
- ERR("Agent returned an unknown code: %" PRIu32,
- be32toh(reply.ret_code));
- ret = LTTNG_ERR_FATAL;
+ ret = LTTNG_ERR_UNK;
goto error;
}
{
int ret;
uint64_t data_size;
+ uint32_t reply_ret_code;
struct lttcomm_agent_disable msg;
struct lttcomm_agent_generic_reply reply;
goto error_io;
}
- switch (be32toh(reply.ret_code)) {
+ reply_ret_code = be32toh(reply.ret_code);
+ log_reply_code(reply_ret_code);
+ switch (reply_ret_code) {
case AGENT_RET_CODE_SUCCESS:
break;
case AGENT_RET_CODE_UNKNOWN_NAME:
ret = LTTNG_ERR_UST_EVENT_NOT_FOUND;
goto error;
default:
- ERR("Agent returned an unknown code: %" PRIu32,
- be32toh(reply.ret_code));
- ret = LTTNG_ERR_FATAL;
+ ret = LTTNG_ERR_UNK;
goto error;
}
int agent_disable_event(struct agent_event *event,
enum lttng_domain_type domain)
{
- int ret;
+ int ret = LTTNG_OK;
struct agent_app *app;
struct lttng_ht_iter iter;
assert(event);
+ if (!event->enabled) {
+ goto end;
+ }
rcu_read_lock();
}
event->enabled = 0;
- ret = LTTNG_OK;
error:
rcu_read_unlock();
+end:
return ret;
}
assert(app);
DBG3("Agent adding app sock: %d and pid: %d to ht", app->sock->fd, app->pid);
-
- rcu_read_lock();
lttng_ht_add_unique_ulong(agent_apps_ht_by_sock, &app->node);
- rcu_read_unlock();
}
/*
DBG3("Agent adding from domain %d", agt->domain);
- rcu_read_lock();
lttng_ht_add_unique_u64(ht, &agt->node);
- rcu_read_unlock();
}
/*
int ret;
struct agent *agt;
- agt = zmalloc(sizeof(*agt));
+ agt = zmalloc(sizeof(struct agent));
if (!agt) {
goto error;
}
}
/*
- * Create a newly allocated agent event data structure. If name is valid, it's
- * copied into the created event.
+ * Create a newly allocated agent event data structure.
+ * Ownership of filter_expression is taken.
*
* Return a new object else NULL on error.
*/
struct agent_event *agent_create_event(const char *name,
- struct lttng_filter_bytecode *filter)
+ int loglevel, enum lttng_loglevel_type loglevel_type,
+ struct lttng_filter_bytecode *filter, char *filter_expression)
{
- struct agent_event *event;
+ struct agent_event *event = NULL;
DBG3("Agent create new event with name %s", name);
- event = zmalloc(sizeof(*event));
- if (!event) {
+ if (!name) {
+ ERR("Failed to create agent event; no name provided.");
goto error;
}
- if (name) {
- strncpy(event->name, name, sizeof(event->name));
- event->name[sizeof(event->name) - 1] = '\0';
- lttng_ht_node_init_str(&event->node, event->name);
+ event = zmalloc(sizeof(*event));
+ if (!event) {
+ goto error;
}
- if (filter) {
- event->filter = filter;
- }
+ strncpy(event->name, name, sizeof(event->name));
+ event->name[sizeof(event->name) - 1] = '\0';
+ lttng_ht_node_init_str(&event->node, event->name);
+ event->loglevel = loglevel;
+ event->loglevel_type = loglevel_type;
+ event->filter = filter;
+ event->filter_expression = filter_expression;
error:
return event;
}
assert(agt->events);
DBG3("Agent adding event %s", event->name);
-
- rcu_read_lock();
add_unique_agent_event(agt->events, event);
- rcu_read_unlock();
agt->being_used = 1;
}
assert(event);
free(event->filter);
+ free(event->filter_expression);
+ free(event->exclusion);
free(event);
}
DBG3("Agent destroy");
- /*
- * Just ignore if no events hash table exists. This is possible if for
- * instance an agent object was allocated but not initialized.
- */
- if (!agt->events) {
- return;
- }
-
rcu_read_lock();
cds_lfht_for_each_entry(agt->events->ht, &iter.iter, node, node) {
int ret;
struct lttng_ht_node_ulong *node;
struct lttng_ht_iter iter;
+ if (!agent_apps_ht_by_sock) {
+ return;
+ }
rcu_read_lock();
cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, node, node) {
struct agent_app *app;