return run_command_no_wait(handle, &cmd);
}
+enum lttng_error_code notification_thread_command_get_trigger(
+ struct notification_thread_handle *handle,
+ const struct lttng_trigger *trigger,
+ struct lttng_trigger **real_trigger)
+{
+ int ret;
+ enum lttng_error_code ret_code;
+ struct notification_thread_command cmd = {};
+
+ init_notification_thread_command(&cmd);
+
+ cmd.type = NOTIFICATION_COMMAND_TYPE_GET_TRIGGER;
+ cmd.parameters.get_trigger.trigger = trigger;
+ ret = run_command_wait(handle, &cmd);
+ if (ret) {
+ ret_code = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ ret_code = cmd.reply_code;
+ *real_trigger = cmd.reply.get_trigger.trigger;
+
+end:
+ return ret_code;
+}
+
/*
* Takes ownership of the payload if present.
*/
NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS,
NOTIFICATION_COMMAND_TYPE_QUIT,
NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE,
+ NOTIFICATION_COMMAND_TYPE_GET_TRIGGER,
};
struct notification_thread_command {
enum client_transmission_status status;
} client_communication_update;
+ struct {
+ const struct lttng_trigger *trigger;
+ } get_trigger;
+
} parameters;
union {
struct {
struct lttng_triggers *triggers;
} list_triggers;
+ struct {
+ struct lttng_trigger *trigger;
+ } get_trigger;
} reply;
/* lttng_waiter on which to wait for command reply (optional). */
struct lttng_waiter reply_waiter;
void notification_thread_command_quit(
struct notification_thread_handle *handle);
+enum lttng_error_code notification_thread_command_get_trigger(
+ struct notification_thread_handle *handle,
+ const struct lttng_trigger *trigger,
+ struct lttng_trigger **real_trigger);
+
#endif /* NOTIFICATION_THREAD_COMMANDS_H */
return "REMOVE_TRACER_EVENT_SOURCE";
case NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS:
return "LIST_TRIGGERS";
+ case NOTIFICATION_COMMAND_TYPE_GET_TRIGGER:
+ return "GET_TRIGGER";
case NOTIFICATION_COMMAND_TYPE_QUIT:
return "QUIT";
case NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE:
return ret;
}
+static inline void get_trigger_info_for_log(const struct lttng_trigger *trigger,
+ const char **trigger_name,
+ uid_t *trigger_owner_uid)
+{
+ enum lttng_trigger_status trigger_status;
+
+ trigger_status = lttng_trigger_get_name(trigger, trigger_name);
+ switch (trigger_status) {
+ case LTTNG_TRIGGER_STATUS_OK:
+ break;
+ case LTTNG_TRIGGER_STATUS_UNSET:
+ *trigger_name = "(unset)";
+ break;
+ default:
+ abort();
+ }
+
+ trigger_status = lttng_trigger_get_owner_uid(trigger,
+ trigger_owner_uid);
+ assert(trigger_status == LTTNG_TRIGGER_STATUS_OK);
+}
+
+static int handle_notification_thread_command_get_trigger(
+ struct notification_thread_state *state,
+ const struct lttng_trigger *trigger,
+ struct lttng_trigger **registered_trigger,
+ enum lttng_error_code *_cmd_result)
+{
+ int ret = -1;
+ struct cds_lfht_iter iter;
+ struct lttng_trigger_ht_element *trigger_ht_element;
+ enum lttng_error_code cmd_result = LTTNG_ERR_TRIGGER_NOT_FOUND;
+ const char *trigger_name;
+ uid_t trigger_owner_uid;
+
+ rcu_read_lock();
+
+ cds_lfht_for_each_entry(
+ state->triggers_ht, &iter, trigger_ht_element, node) {
+ if (lttng_trigger_is_equal(
+ trigger, trigger_ht_element->trigger)) {
+ /* Take one reference on the return trigger. */
+ *registered_trigger = trigger_ht_element->trigger;
+ lttng_trigger_get(*registered_trigger);
+ ret = 0;
+ cmd_result = LTTNG_OK;
+ goto end;
+ }
+ }
+
+ /* Not a fatal error if the trigger is not found. */
+ get_trigger_info_for_log(trigger, &trigger_name, &trigger_owner_uid);
+ ERR("Failed to retrieve registered version of trigger: trigger name = '%s', trigger owner uid = %d",
+ trigger_name, (int) trigger_owner_uid);
+
+ ret = 0;
+
+end:
+ rcu_read_unlock();
+ *_cmd_result = cmd_result;
+ return ret;
+}
+
static
bool condition_is_supported(struct lttng_condition *condition)
{
cmd->reply_code = LTTNG_OK;
ret = 1;
goto end;
+ case NOTIFICATION_COMMAND_TYPE_GET_TRIGGER:
+ {
+ struct lttng_trigger *trigger = NULL;
+
+ ret = handle_notification_thread_command_get_trigger(state,
+ cmd->parameters.get_trigger.trigger, &trigger,
+ &cmd->reply_code);
+ cmd->reply.get_trigger.trigger = trigger;
+ break;
+ }
case NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE:
{
const enum client_transmission_status client_status =