X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_trigger.c;h=ee5c353e4435a398089c2cb205d157c60e11af42;hp=b1ec6dd4780b11008a9583765b7ade979207e7d0;hb=b03a81fbbc65c1cf2e9abc67c56465137c788322;hpb=481c5310f698d32187c0f20bd0d1da3b8b696b06 diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index b1ec6dd47..ee5c353e4 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -7,6 +7,7 @@ #include #include +#include #include "../command.h" #include "../loglevel.h" @@ -45,7 +46,7 @@ enum { OPT_NAME, OPT_FILTER, - OPT_EXCLUDE_NAMES, + OPT_EXCLUDE_NAME, OPT_EVENT_NAME, OPT_LOG_LEVEL, @@ -65,7 +66,7 @@ enum { static const struct argpar_opt_descr event_rule_opt_descrs[] = { { OPT_FILTER, 'f', "filter", true }, { OPT_NAME, 'n', "name", true }, - { OPT_EXCLUDE_NAMES, 'x', "exclude-names", true }, + { OPT_EXCLUDE_NAME, 'x', "exclude-name", true }, { OPT_LOG_LEVEL, 'l', "log-level", true }, { OPT_EVENT_NAME, 'E', "event-name", true }, @@ -126,13 +127,25 @@ bool assign_event_rule_type(enum lttng_event_rule_type *dest, const char *arg) if (strcmp(arg, "tracepoint") == 0 || strcmp(arg, "logging") == 0) { *dest = LTTNG_EVENT_RULE_TYPE_TRACEPOINT; - } else if (strcmp (arg, "kprobe") == 0 || strcmp(arg, "kernel-probe") == 0) { + } else if (strcmp(arg, "kprobe") == 0 || + strcmp(arg, "kernel-probe") == 0) { *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE; - } else if (strcmp (arg, "uprobe") == 0 || strcmp(arg, "userspace-probe") == 0) { + } else if (strcmp(arg, "uprobe") == 0 || + strcmp(arg, "userspace-probe") == 0) { *dest = LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE; - } else if (strcmp (arg, "function") == 0) { + } else if (strcmp(arg, "function") == 0) { *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION; - } else if (strcmp (arg, "syscall") == 0) { + } else if (strncmp(arg, "syscall", strlen("syscall")) == 0) { + /* + * Matches the following: + * - syscall + * - syscall:entry + * - syscall:exit + * - syscall:entry+exit + * - syscall:* + * + * Validation for the right side is left to further usage sites. + */ *dest = LTTNG_EVENT_RULE_TYPE_SYSCALL; } else { ERR("Invalid `--type` value: %s", arg); @@ -175,11 +188,31 @@ end: return ret; } +static bool parse_syscall_emission_site_from_type(const char *str, + enum lttng_event_rule_syscall_emission_site_type *type) +{ + bool ret = false; + if (strcmp(str, "syscall") == 0 || + strcmp(str, "syscall:entry+exit") == 0) { + *type = LTTNG_EVENT_RULE_SYSCALL_EMISSION_SITE_ENTRY_EXIT; + } else if (strcmp(str, "syscall:entry") == 0) { + *type = LTTNG_EVENT_RULE_SYSCALL_EMISSION_SITE_ENTRY; + } else if (strcmp(str, "syscall:exit") == 0) { + *type = LTTNG_EVENT_RULE_SYSCALL_EMISSION_SITE_EXIT; + } else { + goto error; + } + + ret = true; + +error: + return ret; +} + /* This is defined in enable_events.c. */ LTTNG_HIDDEN -int create_exclusion_list_and_validate(const char *event_name, - const char *exclusions_arg, - char ***exclusion_list); +int validate_exclusion_list( + const char *event_name, const char *const *exclusions); /* * Parse `str` as a log level in domain `domain_type`. @@ -622,10 +655,13 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) struct filter_parser_ctx *parser_ctx = NULL; struct lttng_log_level_rule *log_level_rule = NULL; + /* Event rule type option */ + char *event_rule_type_str = NULL; + /* Tracepoint and syscall options. */ char *name = NULL; - char *exclude_names = NULL; - char **exclusion_list = NULL; + /* Array of strings. */ + struct lttng_dynamic_pointer_array exclude_names; /* For userspace / kernel probe and function. */ char *location = NULL; @@ -639,6 +675,9 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) lttng_dynamic_pointer_array_init(&res.capture_descriptors, destroy_event_expr); + + lttng_dynamic_pointer_array_init(&exclude_names, free); + state = argpar_state_create(*argc, *argv, event_rule_opt_descrs); if (!state) { ERR("Failed to allocate an argpar state."); @@ -681,6 +720,13 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } + /* Save the string for later use. */ + if (!assign_string(&event_rule_type_str, + item_opt->arg, + "--type/-t")) { + goto error; + } + break; case OPT_LOCATION: if (!assign_string(&location, @@ -712,14 +758,20 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } break; - case OPT_EXCLUDE_NAMES: - if (!assign_string(&exclude_names, - item_opt->arg, - "--exclude-names/-x")) { + case OPT_EXCLUDE_NAME: + { + int ret; + + ret = lttng_dynamic_pointer_array_add_pointer( + &exclude_names, + strdup(item_opt->arg)); + if (ret != 0) { + ERR("Failed to add pointer to dynamic pointer array."); goto error; } break; + } case OPT_LOG_LEVEL: if (!assign_string(&log_level_str, item_opt->arg, "--log-level/-l")) { @@ -805,8 +857,8 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - if (exclude_names) { - ERR("Can't use --exclude-names/-x with %s event rules.", + if (lttng_dynamic_pointer_array_get_count(&exclude_names) > 0) { + ERR("Can't use --exclude-name/-x with %s event rules.", lttng_event_rule_type_str( event_rule_type)); goto error; @@ -901,17 +953,23 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } } - /* If --exclude/-x was passed, split it into an exclusion list. */ - if (exclude_names) { + /* If --exclude-name/-x was passed, split it into an exclusion list. */ + if (lttng_dynamic_pointer_array_get_count(&exclude_names) > 0) { if (domain_type != LTTNG_DOMAIN_UST) { ERR("Event name exclusions are not yet implemented for %s event rules.", get_domain_str(domain_type)); goto error; } - if (create_exclusion_list_and_validate(name, - exclude_names, &exclusion_list) != 0) { - ERR("Failed to create exclusion list."); + if (validate_exclusion_list(name, + (const char **) exclude_names.array.buffer + .data + + ) != 0) { + /* + * Assume validate_exclusion_list already prints an + * error message. + */ goto error; } } @@ -961,17 +1019,25 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } /* Set exclusion list. */ - if (exclusion_list) { + if (lttng_dynamic_pointer_array_get_count(&exclude_names) > 0) { int n; - - for (n = 0; exclusion_list[n]; n++) { - event_rule_status = lttng_event_rule_tracepoint_add_exclusion( - res.er, - exclusion_list[n]); + int count = lttng_dynamic_pointer_array_get_count( + &exclude_names); + + for (n = 0; n < count; n++) { + const char *exclude_name = + lttng_dynamic_pointer_array_get_pointer( + &exclude_names, + n); + + event_rule_status = + lttng_event_rule_tracepoint_add_exclusion( + res.er, + exclude_name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set tracepoint exclusion list element '%s'", - exclusion_list[n]); + exclude_name); goto error; } } @@ -1077,8 +1143,15 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) case LTTNG_EVENT_RULE_TYPE_SYSCALL: { enum lttng_event_rule_status event_rule_status; + enum lttng_event_rule_syscall_emission_site_type emission_site_type; - res.er = lttng_event_rule_syscall_create(); + if (!parse_syscall_emission_site_from_type( + event_rule_type_str, &emission_site_type)) { + ERR("Failed to parse syscall type '%s'.", event_rule_type_str); + goto error; + } + + res.er = lttng_event_rule_syscall_create(emission_site_type); if (!res.er) { ERR("Failed to create syscall event rule."); goto error; @@ -1127,12 +1200,12 @@ end: argpar_state_destroy(state); free(filter); free(name); - free(exclude_names); + lttng_dynamic_pointer_array_reset(&exclude_names); free(log_level_str); free(location); free(event_name); + free(event_rule_type_str); - strutils_free_null_terminated_array_of_strings(exclusion_list); lttng_kernel_probe_location_destroy(kernel_probe_location); lttng_userspace_probe_location_destroy(userspace_probe_location); lttng_log_level_rule_destroy(log_level_rule); @@ -1152,7 +1225,7 @@ struct lttng_condition *handle_condition_event(int *argc, const char ***argv) goto error; } - c = lttng_condition_on_event_create(res.er); + c = lttng_condition_event_rule_matches_create(res.er); lttng_event_rule_destroy(res.er); res.er = NULL; if (!c) { @@ -1168,7 +1241,7 @@ struct lttng_condition *handle_condition_event(int *argc, const char ***argv) assert(expr); assert(*expr); - status = lttng_condition_on_event_append_capture_descriptor( + status = lttng_condition_event_rule_matches_append_capture_descriptor( c, *expr); if (status != LTTNG_CONDITION_STATUS_OK) { if (status == LTTNG_CONDITION_STATUS_UNSUPPORTED) { @@ -1194,151 +1267,6 @@ end: return c; } -static -struct lttng_condition *handle_condition_session_consumed_size(int *argc, const char ***argv) -{ - struct lttng_condition *cond = NULL; - struct argpar_state *state = NULL; - struct argpar_item *item = NULL; - const char *threshold_arg = NULL; - const char *session_name_arg = NULL; - uint64_t threshold; - char *error = NULL; - enum lttng_condition_status condition_status; - - state = argpar_state_create(*argc, *argv, event_rule_opt_descrs); - if (!state) { - ERR("Failed to allocate an argpar state."); - goto error; - } - - while (true) { - enum argpar_state_parse_next_status status; - - ARGPAR_ITEM_DESTROY_AND_RESET(item); - status = argpar_state_parse_next(state, &item, &error); - if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) { - ERR("%s", error); - goto error; - } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) { - /* Just stop parsing here. */ - break; - } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) { - break; - } - - assert(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK); - - if (item->type == ARGPAR_ITEM_TYPE_OPT) { - const struct argpar_item_opt *item_opt = - (const struct argpar_item_opt *) item; - - switch (item_opt->descr->id) { - default: - abort(); - } - } else { - const struct argpar_item_non_opt *item_non_opt; - - assert(item->type == ARGPAR_ITEM_TYPE_NON_OPT); - - item_non_opt = (const struct argpar_item_non_opt *) item; - - switch (item_non_opt->non_opt_index) { - case 0: - session_name_arg = item_non_opt->arg; - break; - case 1: - threshold_arg = item_non_opt->arg; - break; - default: - ERR("Unexpected argument `%s`.", - item_non_opt->arg); - goto error; - } - } - } - - *argc -= argpar_state_get_ingested_orig_args(state); - *argv += argpar_state_get_ingested_orig_args(state); - - if (!session_name_arg) { - ERR("Missing session name argument."); - goto error; - } - - if (!threshold_arg) { - ERR("Missing threshold argument."); - goto error; - } - - if (utils_parse_size_suffix(threshold_arg, &threshold) != 0) { - ERR("Failed to parse `%s` as a size.", threshold_arg); - goto error; - } - - cond = lttng_condition_session_consumed_size_create(); - if (!cond) { - ERR("Failed to allocate a session consumed size condition."); - goto error; - } - - condition_status = lttng_condition_session_consumed_size_set_session_name( - cond, session_name_arg); - if (condition_status != LTTNG_CONDITION_STATUS_OK) { - ERR("Failed to set session consumed size condition's session name to '%s'.", - session_name_arg); - goto error; - } - - condition_status = lttng_condition_session_consumed_size_set_threshold( - cond, threshold); - if (condition_status != LTTNG_CONDITION_STATUS_OK) { - ERR("Failed to set session consumed size condition threshold."); - goto error; - } - - goto end; - -error: - lttng_condition_destroy(cond); - cond = NULL; - -end: - argpar_state_destroy(state); - argpar_item_destroy(item); - free(error); - return cond; -} - -static -struct lttng_condition *handle_condition_buffer_usage_high(int *argc, const char ***argv) -{ - ERR("High buffer usage threshold conditions are unsupported for the moment."); - return NULL; -} - -static -struct lttng_condition *handle_condition_buffer_usage_low(int *argc, const char ***argv) -{ - ERR("Low buffer usage threshold conditions are unsupported for the moment."); - return NULL; -} - -static -struct lttng_condition *handle_condition_session_rotation_ongoing(int *argc, const char ***argv) -{ - ERR("Session rotation ongoing conditions are unsupported for the moment."); - return NULL; -} - -static -struct lttng_condition *handle_condition_session_rotation_completed(int *argc, const char ***argv) -{ - ERR("Session rotation completed conditions are unsupported for the moment."); - return NULL; -} - struct condition_descr { const char *name; struct lttng_condition *(*handler) (int *argc, const char ***argv); @@ -1347,11 +1275,6 @@ struct condition_descr { static const struct condition_descr condition_descrs[] = { { "event-rule-matches", handle_condition_event }, - { "on-session-consumed-size", handle_condition_session_consumed_size }, - { "on-buffer-usage-high", handle_condition_buffer_usage_high }, - { "on-buffer-usage-low", handle_condition_buffer_usage_low }, - { "on-session-rotation-ongoing", handle_condition_session_rotation_ongoing }, - { "on-session-rotation-completed", handle_condition_session_rotation_completed }, }; static @@ -1589,7 +1512,7 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, { OPT_RATE_POLICY, '\0', "rate-policy", true }, ARGPAR_OPT_DESCR_SENTINEL }; - + state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs); if (!state) { ERR("Failed to allocate an argpar state."); @@ -2110,13 +2033,14 @@ int cmd_add_trigger(int argc, const char **argv) struct lttng_dynamic_pointer_array actions; struct argpar_state *argpar_state = NULL; struct argpar_item *argpar_item = NULL; - struct lttng_action *action_group = NULL; + struct lttng_action *action_list = NULL; struct lttng_action *action = NULL; struct lttng_trigger *trigger = NULL; char *error = NULL; char *name = NULL; int i; char *owner_uid = NULL; + enum lttng_error_code ret_code; lttng_dynamic_pointer_array_init(&actions, lttng_actions_destructor); @@ -2246,8 +2170,8 @@ int cmd_add_trigger(int argc, const char **argv) goto error; } - action_group = lttng_action_group_create(); - if (!action_group) { + action_list = lttng_action_list_create(); + if (!action_list) { goto error; } @@ -2256,34 +2180,24 @@ int cmd_add_trigger(int argc, const char **argv) action = lttng_dynamic_pointer_array_steal_pointer(&actions, i); - status = lttng_action_group_add_action(action_group, action); + status = lttng_action_list_add_action(action_list, action); if (status != LTTNG_ACTION_STATUS_OK) { goto error; } /* - * The `lttng_action_group_add_action()` takes a reference to + * The `lttng_action_list_add_action()` takes a reference to * the action. We can destroy ours. */ lttng_action_destroy(action); action = NULL; } - trigger = lttng_trigger_create(condition, action_group); + trigger = lttng_trigger_create(condition, action_list); if (!trigger) { goto error; } - if (name) { - enum lttng_trigger_status trigger_status = - lttng_trigger_set_name(trigger, name); - - if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { - ERR("Failed to set trigger name."); - goto error; - } - } - if (owner_uid) { enum lttng_trigger_status trigger_status; char *end; @@ -2302,13 +2216,20 @@ int cmd_add_trigger(int argc, const char **argv) } } - ret = lttng_register_trigger(trigger); - if (ret) { - ERR("Failed to register trigger: %s.", lttng_strerror(ret)); + if (name) { + ret_code = lttng_register_trigger_with_name(trigger, name); + } else { + ret_code = lttng_register_trigger_with_automatic_name(trigger); + } + + if (ret_code != LTTNG_OK) { + ERR("Failed to register trigger: %s.", + lttng_strerror(-ret_code)); goto error; } MSG("Trigger registered successfully."); + ret = 0; goto end; @@ -2320,7 +2241,7 @@ end: argpar_item_destroy(argpar_item); lttng_dynamic_pointer_array_reset(&actions); lttng_condition_destroy(condition); - lttng_action_destroy(action_group); + lttng_action_destroy(action_list); lttng_action_destroy(action); lttng_trigger_destroy(trigger); free(error);