#include <ctype.h>
#include <stdio.h>
+#include <string.h>
#include "../command.h"
#include "../loglevel.h"
OPT_CONDITION,
OPT_ACTION,
OPT_ID,
- OPT_USER_ID,
+ OPT_OWNER_UID,
OPT_RATE_POLICY,
OPT_NAME,
OPT_FILTER,
- OPT_EXCLUDE_NAMES,
+ OPT_EXCLUDE_NAME,
OPT_EVENT_NAME,
- OPT_LOGLEVEL,
- OPT_LOGLEVEL_ONLY,
+ OPT_LOG_LEVEL,
OPT_DOMAIN,
-
- OPT_FUNCTION,
- OPT_PROBE,
- OPT_USERSPACE_PROBE,
- OPT_SYSCALL,
- OPT_TRACEPOINT,
+ OPT_TYPE,
+ OPT_LOCATION,
OPT_MAX_SIZE,
OPT_DATA_URL,
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_LOGLEVEL, '\0', "loglevel", true },
- { OPT_LOGLEVEL_ONLY, '\0', "loglevel-only", true },
+ { OPT_EXCLUDE_NAME, 'x', "exclude-name", true },
+ { OPT_LOG_LEVEL, 'l', "log-level", true },
{ OPT_EVENT_NAME, 'E', "event-name", true },
{ OPT_DOMAIN, 'd', "domain", true },
-
- /* Event rule types */
- { OPT_FUNCTION, '\0', "function", true },
- { OPT_PROBE, '\0', "probe", true },
- { OPT_USERSPACE_PROBE, '\0', "userspace-probe", true },
- { OPT_SYSCALL, '\0', "syscall" },
- { OPT_TRACEPOINT, '\0', "tracepoint" },
+ { OPT_TYPE, 't', "type", true },
+ { OPT_LOCATION, 'L', "location", true },
/* Capture descriptor */
{ OPT_CAPTURE, '\0', "capture", true },
}
static
-bool assign_event_rule_type(enum lttng_event_rule_type *dest,
- enum lttng_event_rule_type src)
+bool assign_event_rule_type(enum lttng_event_rule_type *dest, const char *arg)
{
bool ret;
- if (*dest == LTTNG_EVENT_RULE_TYPE_UNKNOWN || *dest == src) {
- *dest = src;
- ret = true;
+ if (*dest != LTTNG_EVENT_RULE_TYPE_UNKNOWN) {
+ ERR("More than one `--type` was specified.");
+ goto error;
+ }
+
+ 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) {
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE;
+ } else if (strcmp(arg, "kernel:uprobe") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE;
+ } else if (strcmp(arg, "function") == 0) {
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION;
+ } else if (strncmp(arg, "syscall", strlen("syscall")) == 0 ||
+ strncmp(arg, "kernel:syscall",
+ strlen("kernel:syscall")) == 0) {
+ /*
+ * Matches the following:
+ * - syscall
+ * - syscall:entry
+ * - syscall:exit
+ * - syscall:entry+exit
+ * - syscall:*
+ * - kernel:syscall
+ * - kernel:syscall:entry
+ * - kernel:syscall:exit
+ * - kernel:syscall:entry+exit
+ * - kernel:syscall:*
+ *
+ * Validation for the right side is left to further usage sites.
+ */
+ *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL;
} else {
- ERR("Multiple event types specified.");
- ret = false;
+ ERR("Invalid `--type` value: %s", arg);
+ goto error;
}
+ ret = true;
+ goto end;
+
+error:
+ ret = false;
+
+end:
return ret;
}
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);
+static bool parse_syscall_emission_site_from_type(const char *str,
+ enum lttng_event_rule_kernel_syscall_emission_site *type)
+{
+ bool ret = false;
+ const char kernel_prefix[] = "kernel:";
+ const size_t kernel_prefix_len = sizeof(kernel_prefix) - 1;
+
+ /*
+ * If the passed string is of the form "kernel:syscall*", move the
+ * pointer passed "kernel:".
+ */
+ if (strncmp(str, kernel_prefix, kernel_prefix_len) == 0) {
+ str = &str[kernel_prefix_len];
+ }
+
+ if (strcmp(str, "syscall") == 0 ||
+ strcmp(str, "syscall:entry+exit") == 0) {
+ *type = LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY_EXIT;
+ } else if (strcmp(str, "syscall:entry") == 0) {
+ *type = LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_ENTRY;
+ } else if (strcmp(str, "syscall:exit") == 0) {
+ *type = LTTNG_EVENT_RULE_KERNEL_SYSCALL_EMISSION_SITE_EXIT;
+ } else {
+ goto error;
+ }
+
+ ret = true;
+
+error:
+ return ret;
+}
/*
- * Parse `str` as a log level in domain `domain_type`. Return -1 if the string
- * is not recognized as a valid log level.
+ * Parse `str` as a log level in domain `domain_type`.
+ *
+ * Return the log level in `*log_level`. Return true in `*log_level_only` if
+ * the string specifies exactly this log level, false if it specifies at least
+ * this log level.
+ *
+ * Return true if the string was successfully parsed as a log level string.
*/
-static
-int parse_loglevel_string(const char *str, enum lttng_domain_type domain_type)
+static bool parse_log_level_string(const char *str,
+ enum lttng_domain_type domain_type,
+ int *log_level,
+ bool *log_level_only)
{
+ bool ret;
+
switch (domain_type) {
case LTTNG_DOMAIN_UST:
{
- enum lttng_loglevel loglevel;
- const int ret = loglevel_name_to_value(str, &loglevel);
+ enum lttng_loglevel log_level_min, log_level_max;
+ if (!loglevel_parse_range_string(
+ str, &log_level_min, &log_level_max)) {
+ goto error;
+ }
+
+ /* Only support VAL and VAL.. for now. */
+ if (log_level_min != log_level_max &&
+ log_level_max != LTTNG_LOGLEVEL_EMERG) {
+ goto error;
+ }
- return ret == -1 ? ret : (int) loglevel;
+ *log_level = (int) log_level_min;
+ *log_level_only = log_level_min == log_level_max;
+ break;
}
case LTTNG_DOMAIN_LOG4J:
{
- enum lttng_loglevel_log4j loglevel;
- const int ret = loglevel_log4j_name_to_value(str, &loglevel);
+ enum lttng_loglevel_log4j log_level_min, log_level_max;
+ if (!loglevel_log4j_parse_range_string(
+ str, &log_level_min, &log_level_max)) {
+ goto error;
+ }
- return ret == -1 ? ret : (int) loglevel;
+ /* Only support VAL and VAL.. for now. */
+ if (log_level_min != log_level_max &&
+ log_level_max != LTTNG_LOGLEVEL_LOG4J_FATAL) {
+ goto error;
+ }
+
+ *log_level = (int) log_level_min;
+ *log_level_only = log_level_min == log_level_max;
+ break;
}
case LTTNG_DOMAIN_JUL:
{
- enum lttng_loglevel_jul loglevel;
- const int ret = loglevel_jul_name_to_value(str, &loglevel);
+ enum lttng_loglevel_jul log_level_min, log_level_max;
+ if (!loglevel_jul_parse_range_string(
+ str, &log_level_min, &log_level_max)) {
+ goto error;
+ }
+
+ /* Only support VAL and VAL.. for now. */
+ if (log_level_min != log_level_max &&
+ log_level_max != LTTNG_LOGLEVEL_JUL_SEVERE) {
+ goto error;
+ }
- return ret == -1 ? ret : (int) loglevel;
+ *log_level = (int) log_level_min;
+ *log_level_only = log_level_min == log_level_max;
+ break;
}
case LTTNG_DOMAIN_PYTHON:
{
- enum lttng_loglevel_python loglevel;
- const int ret = loglevel_python_name_to_value(str, &loglevel);
+ enum lttng_loglevel_python log_level_min, log_level_max;
+ if (!loglevel_python_parse_range_string(
+ str, &log_level_min, &log_level_max)) {
+ goto error;
+ }
- return ret == -1 ? ret : (int) loglevel;
+ /* Only support VAL and VAL.. for now. */
+ if (log_level_min != log_level_max &&
+ log_level_max !=
+ LTTNG_LOGLEVEL_PYTHON_CRITICAL) {
+ goto error;
+ }
+
+ *log_level = (int) log_level_min;
+ *log_level_only = log_level_min == log_level_max;
+ break;
}
default:
/* Invalid domain type. */
abort();
}
+
+ ret = true;
+ goto end;
+
+error:
+ ret = false;
+
+end:
+ return ret;
}
static int parse_kernel_probe_opts(const char *source,
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;
- /* Holds the argument of --probe / --userspace-probe. */
- char *probe_source = NULL;
- char *probe_event_name = NULL;
+ /* For userspace / kernel probe and function. */
+ char *location = NULL;
+ char *event_name = NULL;
/* Filter. */
char *filter = NULL;
/* Log level. */
- char *loglevel_str = NULL;
- bool loglevel_only = false;
+ char *log_level_str = 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.");
switch (item_opt->descr->id) {
/* Domains. */
case OPT_DOMAIN:
- if (!assign_domain_type(&domain_type, item_opt->arg)) {
- goto error;
- }
-
- break;
-
- /* Event rule types */
- case OPT_FUNCTION:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION)) {
+ if (!assign_domain_type(&domain_type,
+ item_opt->arg)) {
goto error;
}
break;
- case OPT_PROBE:
+ case OPT_TYPE:
if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE)) {
+ item_opt->arg)) {
goto error;
}
- if (!assign_string(&probe_source, item_opt->arg,
- "--probe")) {
+ /* Save the string for later use. */
+ if (!assign_string(&event_rule_type_str,
+ item_opt->arg,
+ "--type/-t")) {
goto error;
}
break;
- case OPT_USERSPACE_PROBE:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE)) {
- goto error;
- }
-
- if (!assign_string(&probe_source, item_opt->arg,
- "--userspace-probe")) {
+ case OPT_LOCATION:
+ if (!assign_string(&location,
+ item_opt->arg,
+ "--location/-L")) {
goto error;
}
break;
case OPT_EVENT_NAME:
- if (!assign_string(&probe_event_name,
+ if (!assign_string(&event_name,
item_opt->arg,
"--event-name/-E")) {
goto error;
}
- break;
- case OPT_SYSCALL:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_SYSCALL)) {
- goto error;
- }
-
- break;
- case OPT_TRACEPOINT:
- if (!assign_event_rule_type(&event_rule_type,
- LTTNG_EVENT_RULE_TYPE_TRACEPOINT)) {
- goto error;
- }
-
break;
case OPT_FILTER:
if (!assign_string(&filter, item_opt->arg,
}
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_LOGLEVEL:
- case OPT_LOGLEVEL_ONLY:
- if (!assign_string(&loglevel_str, item_opt->arg,
- "--loglevel/--loglevel-only")) {
+ }
+ case OPT_LOG_LEVEL:
+ if (!assign_string(&log_level_str,
+ item_opt->arg, "--log-level/-l")) {
goto error;
}
- loglevel_only = item_opt->descr->id ==
- OPT_LOGLEVEL_ONLY;
break;
case OPT_CAPTURE:
{
*/
switch (event_rule_type) {
case LTTNG_EVENT_RULE_TYPE_TRACEPOINT:
- case LTTNG_EVENT_RULE_TYPE_SYSCALL:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL:
if (!name) {
name = strdup("*");
}
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;
}
/*
+ * Option --location is only applicable to (and mandatory for) event
+ * rules of type {k,u}probe and function.
+ *
* Option --event-name is only applicable to event rules of type probe.
- * If omitted, it defaults to the probe location.
+ * If omitted, it defaults to the location.
*/
switch (event_rule_type) {
case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE:
- case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE:
- if (!probe_event_name) {
- probe_event_name = strdup(probe_source);
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION:
+ if (!location) {
+ ERR("Event rule of type %s requires a --location.",
+ lttng_event_rule_type_str(event_rule_type));
+ goto error;
+ }
+
+ if (!event_name) {
+ event_name = strdup(location);
}
break;
default:
- if (probe_event_name) {
+ if (location) {
+ ERR("Can't use --location with %s event rules.",
+ lttng_event_rule_type_str(event_rule_type));
+ goto error;
+ }
+
+ if (event_name) {
ERR("Can't use --event-name with %s event rules.",
lttng_event_rule_type_str(
event_rule_type));
switch (event_rule_type) {
case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE:
case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION:
- case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE:
- case LTTNG_EVENT_RULE_TYPE_SYSCALL:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL:
if (domain_type != LTTNG_DOMAIN_KERNEL) {
ERR("Event type not available for user-space tracing.");
goto error;
if (filter && domain_type == LTTNG_DOMAIN_KERNEL) {
switch (event_rule_type) {
case LTTNG_EVENT_RULE_TYPE_TRACEPOINT:
- case LTTNG_EVENT_RULE_TYPE_SYSCALL:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL:
break;
default:
ERR("Filter expressions are not supported for %s event rules.",
}
}
- /* 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, &exclude_names) != 0) {
+ /*
+ * Assume validate_exclusion_list already prints an
+ * error message.
+ */
goto error;
}
}
- if (loglevel_str && event_rule_type != LTTNG_EVENT_RULE_TYPE_TRACEPOINT) {
- ERR("Log levels are only applicable to tracepoint event rules.");
- goto error;
+ if (log_level_str) {
+ if (event_rule_type != LTTNG_EVENT_RULE_TYPE_TRACEPOINT) {
+ ERR("Log levels are only applicable to tracepoint event rules.");
+ goto error;
+ }
+
+ if (domain_type == LTTNG_DOMAIN_KERNEL) {
+ ERR("Log levels are not supported by the kernel tracer.");
+ goto error;
+ }
}
/* Finally, create the event rule object. */
}
/* Set pattern. */
- event_rule_status = lttng_event_rule_tracepoint_set_pattern(
+ event_rule_status = lttng_event_rule_tracepoint_set_name_pattern(
res.er, name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set tracepoint event rule's pattern to '%s'.",
}
/* 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_name_pattern_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;
}
}
}
- if (loglevel_str) {
- int loglevel;
-
- if (domain_type == LTTNG_DOMAIN_KERNEL) {
- ERR("Log levels are not supported by the kernel tracer.");
- goto error;
- }
-
- loglevel = parse_loglevel_string(
- loglevel_str, domain_type);
- if (loglevel < 0) {
- ERR("Failed to parse `%s` as a log level.",
- loglevel_str);
+ /*
+ * ".." is the same as passing no log level option and
+ * correspond the the "ANY" case.
+ */
+ if (log_level_str && strcmp(log_level_str, "..") != 0) {
+ int log_level;
+ bool log_level_only;
+
+ if (!parse_log_level_string(log_level_str, domain_type,
+ &log_level, &log_level_only)) {
+ ERR("Failed to parse log level string `%s`.",
+ log_level_str);
goto error;
}
- if (loglevel_only) {
- log_level_rule = lttng_log_level_rule_exactly_create(loglevel);
+ if (log_level_only) {
+ log_level_rule = lttng_log_level_rule_exactly_create(log_level);
} else {
- log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create(loglevel);
+ log_level_rule = lttng_log_level_rule_at_least_as_severe_as_create(log_level);
}
if (log_level_rule == NULL) {
enum lttng_event_rule_status event_rule_status;
ret = parse_kernel_probe_opts(
- probe_source, &kernel_probe_location);
+ location, &kernel_probe_location);
if (ret) {
ERR("Failed to parse kernel probe location.");
goto error;
event_rule_status =
lttng_event_rule_kernel_probe_set_event_name(
- res.er, probe_event_name);
+ res.er, event_name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set kprobe event rule's name to '%s'.",
- probe_event_name);
+ event_name);
goto error;
}
break;
}
- case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE:
{
int ret;
enum lttng_event_rule_status event_rule_status;
ret = parse_userspace_probe_opts(
- probe_source, &userspace_probe_location);
+ location, &userspace_probe_location);
if (ret) {
ERR("Failed to parse user space probe location.");
goto error;
}
- res.er = lttng_event_rule_userspace_probe_create(userspace_probe_location);
+ res.er = lttng_event_rule_kernel_uprobe_create(userspace_probe_location);
if (!res.er) {
ERR("Failed to create userspace probe event rule.");
goto error;
}
event_rule_status =
- lttng_event_rule_userspace_probe_set_event_name(
- res.er, probe_event_name);
+ lttng_event_rule_kernel_uprobe_set_event_name(
+ res.er, event_name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set user space probe event rule's name to '%s'.",
- probe_event_name);
+ event_name);
goto error;
}
break;
}
- case LTTNG_EVENT_RULE_TYPE_SYSCALL:
+ case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL:
{
enum lttng_event_rule_status event_rule_status;
+ enum lttng_event_rule_kernel_syscall_emission_site emission_site;
+
+ if (!parse_syscall_emission_site_from_type(
+ event_rule_type_str, &emission_site)) {
+ ERR("Failed to parse syscall type '%s'.", event_rule_type_str);
+ goto error;
+ }
- res.er = lttng_event_rule_syscall_create();
+ res.er = lttng_event_rule_kernel_syscall_create(emission_site);
if (!res.er) {
ERR("Failed to create syscall event rule.");
goto error;
}
- event_rule_status = lttng_event_rule_syscall_set_pattern(
+ event_rule_status = lttng_event_rule_kernel_syscall_set_name_pattern(
res.er, name);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set syscall event rule's pattern to '%s'.",
}
if (filter) {
- event_rule_status = lttng_event_rule_syscall_set_filter(
+ event_rule_status = lttng_event_rule_kernel_syscall_set_filter(
res.er, filter);
if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
ERR("Failed to set syscall event rule's filter to '%s'.",
argpar_state_destroy(state);
free(filter);
free(name);
- free(exclude_names);
- free(loglevel_str);
- free(probe_source);
- free(probe_event_name);
+ 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);
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) {
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) {
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);
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
static struct lttng_rate_policy *parse_rate_policy(const char *policy_str)
{
- int num_token;
- char **tokens = NULL;
+ int ret;
+ size_t num_token = 0;
+ struct lttng_dynamic_pointer_array tokens;
struct lttng_rate_policy *policy = NULL;
enum lttng_rate_policy_type policy_type;
unsigned long long value;
char *policy_value_str;
assert(policy_str);
+ lttng_dynamic_pointer_array_init(&tokens, NULL);
- /*
- * rate policy fields are separated by ':'.
- */
- tokens = strutils_split(policy_str, ':', 1);
- num_token = strutils_array_of_strings_len(tokens);
+ /* Rate policy fields are separated by ':'. */
+ ret = strutils_split(policy_str, ':', 1, &tokens);
+ if (ret == 0) {
+ num_token = lttng_dynamic_pointer_array_get_count(&tokens);
+ }
/*
* Early sanity check that the number of parameter is exactly 2.
goto end;
}
- policy_type_str = tokens[0];
- policy_value_str = tokens[1];
+ policy_type_str = lttng_dynamic_pointer_array_get_pointer(&tokens, 0);
+ policy_value_str = lttng_dynamic_pointer_array_get_pointer(&tokens, 1);
/* Parse the type. */
if (strcmp(policy_type_str, "once-after") == 0) {
}
end:
- strutils_free_null_terminated_array_of_strings(tokens);
+ lttng_dynamic_pointer_array_reset(&tokens);
return policy;
}
{ 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.");
{ OPT_CONDITION, '\0', "condition", true },
{ OPT_ACTION, '\0', "action", true },
{ OPT_NAME, '\0', "name", true },
- { OPT_USER_ID, '\0', "user-id", true },
+ { OPT_OWNER_UID, '\0', "owner-uid", true },
ARGPAR_OPT_DESCR_SENTINEL,
};
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 *user_id = NULL;
+ char *owner_uid = NULL;
+ enum lttng_error_code ret_code;
lttng_dynamic_pointer_array_init(&actions, lttng_actions_destructor);
break;
}
- case OPT_USER_ID:
+ case OPT_OWNER_UID:
{
- if (!assign_string(&user_id, item_opt->arg,
- "--user-id")) {
+ if (!assign_string(&owner_uid, item_opt->arg,
+ "--owner-uid")) {
goto error;
}
goto error;
}
- action_group = lttng_action_group_create();
- if (!action_group) {
+ action_list = lttng_action_list_create();
+ if (!action_list) {
goto error;
}
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 (user_id) {
+ if (owner_uid) {
enum lttng_trigger_status trigger_status;
char *end;
long long uid;
errno = 0;
- uid = strtol(user_id, &end, 10);
- if (end == user_id || *end != '\0' || errno != 0) {
- ERR("Failed to parse `%s` as a user id.", user_id);
+ uid = strtol(owner_uid, &end, 10);
+ if (end == owner_uid || *end != '\0' || errno != 0) {
+ ERR("Failed to parse `%s` as a user id.", owner_uid);
+ goto error;
}
trigger_status = lttng_trigger_set_owner_uid(trigger, uid);
}
}
- 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;
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);
free(name);
- free(user_id);
+ free(owner_uid);
return ret;
}