trigger: consider domain on register and unregister
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 10 Feb 2020 01:33:55 +0000 (20:33 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 24 Nov 2020 20:52:45 +0000 (15:52 -0500)
This allows the sessiond to inform the client if a trigger that requires a
particular domain (event rule based condition, for example) is at all
valid.

This is useful to fail early when a trigger being registered requires an
unavailable tracer.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I660937e64b294f6239ba15faeef705438a93a41a

src/bin/lttng-sessiond/client.c
src/lib/lttng-ctl/lttng-ctl.c

index faf5d579fde6fbb7affa61267babdce675f6d844..3ccc29efceaf335a71ce0bc3c5d705aaefd90619 100644 (file)
@@ -769,8 +769,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
                int *sock_error)
 {
        int ret = LTTNG_OK;
-       int need_tracing_session = 1;
-       int need_domain;
+       bool need_tracing_session = true;
+       bool need_domain;
+       bool need_consumerd;
 
        DBG("Processing client command %d", cmd_ctx->lsm.cmd_type);
 
@@ -794,18 +795,27 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
        case LTTNG_SET_SESSION_SHM_PATH:
        case LTTNG_REGENERATE_METADATA:
        case LTTNG_REGENERATE_STATEDUMP:
-       case LTTNG_REGISTER_TRIGGER:
-       case LTTNG_UNREGISTER_TRIGGER:
        case LTTNG_ROTATE_SESSION:
        case LTTNG_ROTATION_GET_INFO:
        case LTTNG_ROTATION_SET_SCHEDULE:
        case LTTNG_SESSION_LIST_ROTATION_SCHEDULES:
        case LTTNG_CLEAR_SESSION:
        case LTTNG_LIST_TRIGGERS:
-               need_domain = 0;
+               need_domain = false;
+               break;
+       default:
+               need_domain = true;
+       }
+
+       /* Needs a functioning consumerd? */
+       switch (cmd_ctx->lsm.cmd_type) {
+       case LTTNG_REGISTER_TRIGGER:
+       case LTTNG_UNREGISTER_TRIGGER:
+               need_consumerd = false;
                break;
        default:
-               need_domain = 1;
+               need_consumerd = true;
+               break;
        }
 
        if (config.no_kernel && need_domain
@@ -848,6 +858,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
        case LTTNG_DATA_PENDING:
        case LTTNG_ROTATE_SESSION:
        case LTTNG_ROTATION_GET_INFO:
+       case LTTNG_REGISTER_TRIGGER:
        case LTTNG_LIST_TRIGGERS:
                break;
        default:
@@ -870,7 +881,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
        case LTTNG_REGISTER_TRIGGER:
        case LTTNG_UNREGISTER_TRIGGER:
        case LTTNG_LIST_TRIGGERS:
-               need_tracing_session = 0;
+               need_tracing_session = false;
                break;
        default:
                DBG("Getting session %s by name", cmd_ctx->lsm.session.name);
@@ -948,7 +959,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
                }
 
                /* Consumer is in an ERROR state. Report back to client */
-               if (uatomic_read(&kernel_consumerd_state) == CONSUMER_ERROR) {
+               if (need_consumerd && uatomic_read(&kernel_consumerd_state) ==
+                                                     CONSUMER_ERROR) {
                        ret = LTTNG_ERR_NO_KERNCONSUMERD;
                        goto error;
                }
@@ -999,8 +1011,10 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock,
                        ret = LTTNG_ERR_NO_UST;
                        goto error;
                }
+
                /* Consumer is in an ERROR state. Report back to client */
-               if (uatomic_read(&ust_consumerd_state) == CONSUMER_ERROR) {
+               if (need_consumerd && uatomic_read(&ust_consumerd_state) ==
+                                                     CONSUMER_ERROR) {
                        ret = LTTNG_ERR_NO_USTCONSUMERD;
                        goto error;
                }
index 91d6109e5383b77f8013d67aad18b374d4e131ba..a295667fea7855e594645e99b5c24520ea5976ec 100644 (file)
@@ -2971,6 +2971,7 @@ int lttng_register_trigger(struct lttng_trigger *trigger)
        struct lttng_payload message;
        struct lttng_payload reply;
        struct lttng_trigger *reply_trigger = NULL;
+       enum lttng_domain_type domain_type;
        const struct lttng_credentials user_creds = {
                .uid = LTTNG_OPTIONAL_INIT_VALUE(geteuid()),
                .gid = LTTNG_OPTIONAL_INIT_UNSET,
@@ -3015,6 +3016,11 @@ int lttng_register_trigger(struct lttng_trigger *trigger)
                goto end;
        }
 
+       domain_type = lttng_trigger_get_underlying_domain_type_restriction(
+                       trigger);
+
+       lsm.domain.type = domain_type;
+
        ret = lttng_dynamic_buffer_append(&message.buffer, &lsm, sizeof(lsm));
        if (ret) {
                ret = -LTTNG_ERR_NOMEM;
This page took 0.037758 seconds and 4 git commands to generate.