Fix: sessiond consumer thread should register as RCU thread
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index a1fbe5128f4983fab1e32bb8b9cf4d7576a3a570..5a7d153e568743c73365549bd9676311789b9c48 100644 (file)
@@ -1216,6 +1216,9 @@ static void *thread_manage_consumer(void *data)
 
        DBG("[thread] Manage consumer started");
 
+       rcu_register_thread();
+       rcu_thread_online();
+
        health_register(health_sessiond, HEALTH_SESSIOND_TYPE_CONSUMER);
 
        health_code_update();
@@ -1514,6 +1517,9 @@ error_poll:
        health_unregister(health_sessiond);
        DBG("consumer thread cleanup completed");
 
+       rcu_thread_offline();
+       rcu_unregister_thread();
+
        return NULL;
 }
 
@@ -2157,6 +2163,10 @@ static void *thread_registration_apps(void *data)
                                        ust_cmd = zmalloc(sizeof(struct ust_command));
                                        if (ust_cmd == NULL) {
                                                PERROR("ust command zmalloc");
+                                               ret = close(sock);
+                                               if (ret) {
+                                                       PERROR("close");
+                                               }
                                                goto error;
                                        }
 
@@ -2713,7 +2723,7 @@ static int copy_session_consumer(int domain, struct ltt_session *session)
                 * domain.
                 */
                if (session->kernel_session->consumer) {
-                       consumer_destroy_output(session->kernel_session->consumer);
+                       consumer_output_put(session->kernel_session->consumer);
                }
                session->kernel_session->consumer =
                        consumer_copy_output(session->consumer);
@@ -2727,7 +2737,7 @@ static int copy_session_consumer(int domain, struct ltt_session *session)
        case LTTNG_DOMAIN_UST:
                DBG3("Copying tracing session consumer output in UST session");
                if (session->ust_session->consumer) {
-                       consumer_destroy_output(session->ust_session->consumer);
+                       consumer_output_put(session->ust_session->consumer);
                }
                session->ust_session->consumer =
                        consumer_copy_output(session->consumer);
@@ -2847,7 +2857,7 @@ static int create_kernel_session(struct ltt_session *session)
                                session->kernel_session->consumer->dst.trace_path,
                                S_IRWXU | S_IRWXG, session->uid, session->gid);
                if (ret < 0) {
-                       if (ret != -EEXIST) {
+                       if (errno != EEXIST) {
                                ERR("Trace directory creation error");
                                goto error;
                        }
@@ -3267,8 +3277,34 @@ skip_domain:
        }
        case LTTNG_DISABLE_EVENT:
        {
+
+               /*
+                * FIXME: handle filter; for now we just receive the filter's
+                * bytecode along with the filter expression which are sent by
+                * liblttng-ctl and discard them.
+                *
+                * This fixes an issue where the client may block while sending
+                * the filter payload and encounter an error because the session
+                * daemon closes the socket without ever handling this data.
+                */
+               size_t count = cmd_ctx->lsm->u.disable.expression_len +
+                       cmd_ctx->lsm->u.disable.bytecode_len;
+
+               if (count) {
+                       char data[LTTNG_FILTER_MAX_LEN];
+
+                       DBG("Discarding disable event command payload of size %zu", count);
+                       while (count) {
+                               ret = lttcomm_recv_unix_sock(sock, data,
+                                       count > sizeof(data) ? sizeof(data) : count);
+                               if (ret < 0) {
+                                       goto error;
+                               }
+
+                               count -= (size_t) ret;
+                       }
+               }
                /* FIXME: passing packed structure to non-packed pointer */
-               /* TODO: handle filter */
                ret = cmd_disable_event(cmd_ctx->session, cmd_ctx->lsm->domain.type,
                                cmd_ctx->lsm->u.disable.channel_name,
                                &cmd_ctx->lsm->u.disable.event);
@@ -3766,7 +3802,35 @@ skip_domain:
        }
        case LTTNG_DATA_PENDING:
        {
-               ret = cmd_data_pending(cmd_ctx->session);
+               int pending_ret;
+
+               /* 1 byte to return whether or not data is pending */
+               ret = setup_lttng_msg(cmd_ctx, 1);
+               if (ret < 0) {
+                       goto setup_error;
+               }
+
+               pending_ret = cmd_data_pending(cmd_ctx->session);
+               /*
+                * FIXME
+                *
+                * This function may returns 0 or 1 to indicate whether or not
+                * there is data pending. In case of error, it should return an
+                * LTTNG_ERR code. However, some code paths may still return
+                * a nondescript error code, which we handle by returning an
+                * "unknown" error.
+                */
+               if (pending_ret == 0 || pending_ret == 1) {
+                       ret = LTTNG_OK;
+               } else if (pending_ret < 0) {
+                       ret = LTTNG_ERR_UNK;
+                       goto setup_error;
+               } else {
+                       ret = pending_ret;
+                       goto setup_error;
+               }
+
+               *cmd_ctx->llm->payload = (uint8_t) pending_ret;
                break;
        }
        case LTTNG_SNAPSHOT_ADD_OUTPUT:
@@ -4333,9 +4397,10 @@ static void *thread_manage_clients(void *data)
 
                health_code_update();
 
-               DBG("Sending response (size: %d, retcode: %s)",
+               DBG("Sending response (size: %d, retcode: %s (%d))",
                                cmd_ctx->lttng_msg_size,
-                               lttng_strerror(-cmd_ctx->llm->ret_code));
+                               lttng_strerror(-cmd_ctx->llm->ret_code),
+                               cmd_ctx->llm->ret_code);
                ret = send_unix_sock(sock, cmd_ctx->llm, cmd_ctx->lttng_msg_size);
                if (ret < 0) {
                        ERR("Failed to send data back to client");
This page took 0.024731 seconds and 4 git commands to generate.