Fix: sessiond add missing socket close
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index c66548cd87d25495de8d87ebb275d5bea5adc557..cb3b17cdd59c2e19bb254d983711d58e38fbb7ec 100644 (file)
@@ -2157,6 +2157,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;
                                        }
 
@@ -3267,8 +3271,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 +3796,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 +4391,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");
@@ -5302,9 +5361,6 @@ int main(int argc, char **argv)
        void *status;
        const char *home_path, *env_app_timeout;
 
-       /* Initialize agent apps ht global variable */
-       agent_apps_ht_by_sock = NULL;
-
        init_kernel_workarounds();
 
        rcu_register_thread();
This page took 0.024373 seconds and 4 git commands to generate.