OPT_CONDITION,
OPT_ACTION,
OPT_ID,
- OPT_USER_ID,
+ OPT_OWNER_UID,
OPT_RATE_POLICY,
OPT_NAME,
OPT_FILTER,
OPT_EXCLUDE_NAMES,
OPT_EVENT_NAME,
- OPT_LOGLEVEL,
- OPT_LOGLEVEL_ONLY,
+ OPT_LOG_LEVEL,
OPT_DOMAIN,
OPT_TYPE,
{ 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_LOG_LEVEL, 'l', "log-level", true },
{ OPT_EVENT_NAME, 'E', "event-name", true },
{ OPT_DOMAIN, 'd', "domain", true },
char ***exclusion_list);
/*
- * 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;
+ }
+
+ /* Only support VAL and VAL.. for now. */
+ if (log_level_min != log_level_max &&
+ log_level_max != LTTNG_LOGLEVEL_LOG4J_FATAL) {
+ 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_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,
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);
}
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:
{
}
}
- 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. */
}
}
- 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) {
free(filter);
free(name);
free(exclude_names);
- free(loglevel_str);
+ free(log_level_str);
free(location);
free(event_name);
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
{ 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,
};
char *error = NULL;
char *name = NULL;
int i;
- char *user_id = NULL;
+ char *owner_uid = NULL;
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;
}
}
}
- 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);
}
trigger_status = lttng_trigger_set_owner_uid(trigger, uid);
lttng_trigger_destroy(trigger);
free(error);
free(name);
- free(user_id);
+ free(owner_uid);
return ret;
}