OPT_NAME,
OPT_FILTER,
- OPT_EXCLUDE_NAMES,
+ OPT_EXCLUDE_NAME,
OPT_EVENT_NAME,
OPT_LOG_LEVEL,
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 },
/* 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`.
/* 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;
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.");
}
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")) {
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;
}
}
- /* 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;
}
}
}
/* 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;
}
}
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);
{ 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.");
* FIXME: find a good place to declare this since add trigger also uses it
*/
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);
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)
{
- int ret = 0;
- char **exclusions = NULL;
+ int ret;
/* Event name must be a valid globbing pattern to allow exclusions. */
if (!strutils_is_star_glob_pattern(event_name)) {
goto error;
}
- /* Split exclusions. */
- exclusions = strutils_split(exclusions_arg, ',', true);
- if (!exclusions) {
- goto error;
- }
-
/*
* If the event name is a star-at-end only globbing pattern,
* then we can validate the individual exclusions. Otherwise
* all exclusions are passed to the session daemon.
*/
if (strutils_is_star_at_the_end_only_glob_pattern(event_name)) {
- char * const *exclusion;
+ const char *const *exclusion;
for (exclusion = exclusions; *exclusion; exclusion++) {
if (!strutils_is_star_glob_pattern(*exclusion) ||
}
}
+ ret = 0;
+ goto end;
+
+error:
+ ret = -1;
+
+end:
+ return ret;
+}
+
+static int create_exclusion_list_and_validate(const char *event_name,
+ const char *exclusions_arg,
+ char ***exclusion_list)
+{
+ int ret = 0;
+ char **exclusions = NULL;
+
+ /* Split exclusions. */
+ exclusions = strutils_split(exclusions_arg, ',', true);
+ if (!exclusions) {
+ goto error;
+ }
+
+ if (validate_exclusion_list(event_name, (const char **) exclusions) !=
+ 0) {
+ goto error;
+ }
+
*exclusion_list = exclusions;
goto end;
# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"
-plan_tests 276
+plan_tests 285
FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
--condition event-rule-matches --domain=user --log-level=.. \
--action notify
+test_success "--exclude-name one" \
+ --condition event-rule-matches --domain=user --name='bernard*' --exclude-name=bernard-lermite \
+ --action notify
+
+test_success "--exclude-name two" \
+ --condition event-rule-matches --domain=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \
+ --action notify
+
skip $ist_root "non-root user: skipping kprobe tests" 18 || {
for type in kprobe kernel-probe; do
test_success "--condition event-rule-matches probe by symbol" \
--condition event-rule-matches --domain=kernel --type=syscall:nope \
--name=open
+test_failure "--exclude-name with non-glob name" \
+ "Error: Event jean: Exclusions can only be used with a globbing pattern" \
+ --condition event-rule-matches --domain=user --name='jean' --exclude-name jean-chretien \
+ --action notify
+
test_failure "--condition event-rule-matches --capture: missing argument (end of arg list)" \
'Error: While parsing argument #2 (`--capture`): Missing required argument for option `--capture`' \
--action notify \