X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fust-ctl.c;h=2753b6f5ab639b593692c62292a5740cd08c653f;hp=7c8cc5ebb4084007736c53da9d76d542e6485e58;hb=44d3bd014f6ad217cff7e7c3dfaad76b1927c37b;hpb=82a3637f639486c07ff937ab03e1e9532379d26a diff --git a/ltt-sessiond/ust-ctl.c b/ltt-sessiond/ust-ctl.c index 7c8cc5ebb..2753b6f5a 100644 --- a/ltt-sessiond/ust-ctl.c +++ b/ltt-sessiond/ust-ctl.c @@ -17,194 +17,202 @@ */ #define _GNU_SOURCE -#include #include #include #include #include -#include "liblttsessiondcomm.h" -#include "lttngerr.h" +#include +#include + +#include "ust-comm.h" #include "ust-ctl.h" -#ifdef DISABLED /* - * find_session_ust_trace_by_pid - * - * Iterate over the session ust_traces and - * return a pointer or NULL if not found. + * Send registration done packet to the application. */ -static struct ltt_ust_trace *find_session_ust_trace_by_pid( - struct ltt_session *session, pid_t pid) +int ustctl_register_done(int sock) { - struct ltt_ust_trace *iter; + struct lttcomm_ust_msg command; + struct lttcomm_ust_reply *reply; + + DBG("Sending register done command to %d", sock); - cds_list_for_each_entry(iter, &session->ust_traces, list) { - if (iter->pid == pid) { - /* Found */ - return iter; - } + command.cmd = LTTNG_UST_REGISTER_DONE; + command.handle = LTTNG_UST_ROOT_HANDLE; + + reply = ustcomm_send_command(sock, &command); + if (reply == NULL) { + goto error; } - return NULL; -} + if (reply->ret_code != LTTCOMM_OK) { + DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code)); + goto error; + } -/* - * get_trace_count_per_session - * - * Return the total count of traces (ust and kernel) - * for the specified session. - */ -int get_trace_count_per_session(struct ltt_session *session) -{ - return session->ust_trace_count; + return 0; + +error: + return -1; } /* - * get_traces_per_session - * - * Fill the lttng_trace array of all the - * available trace of the session. + * Create an UST session on the tracer. */ -/* -void get_traces_per_session(struct ltt_session *session, struct lttng_trace *traces) +int ustctl_create_session(int sock, struct ltt_ust_session *session) { - int i = 0; - struct ltt_ust_trace *ust_iter; - struct lttng_trace trace; - - DBG("Getting userspace traces for session %s", session->name); - - cds_list_for_each_entry(ust_iter, &session->ust_traces, list) { - trace.type = USERSPACE; - trace.pid = ust_iter->pid; - strncpy(trace.name, ust_iter->name, sizeof(trace.name)); - trace.name[sizeof(trace.name) - 1] = '\0'; - memcpy(&traces[i], &trace, sizeof(trace)); - memset(&trace, 0, sizeof(trace)); - i++; - } + struct lttcomm_ust_msg command; + struct lttcomm_ust_reply *reply = NULL; - DBG("Getting kernel traces for session %s", session->name); + command.cmd = LTTNG_UST_SESSION; + command.handle = LTTNG_UST_ROOT_HANDLE; - if (session->kern_session_count > 0) { - trace.type = KERNEL; - strncpy(trace.name, "kernel", 6); - memcpy(&traces[i], &trace, sizeof(trace)); + reply = ustcomm_send_command(sock, &command); + if (reply == NULL) { + goto error; } + + if (reply->ret_code != LTTCOMM_OK) { + DBG("Return code: %s", lttcomm_get_readable_code(reply->ret_code)); + goto error; + } + + /* Save session handle */ + session->handle = reply->ret_val; + free(reply); + + DBG2("ustctl create session command successful"); + return 0; + +error: + free(reply); + return -1; } -*/ /* - * ust_create_trace - * - * Create an userspace trace using pid. - * This trace is then appended to the current session - * ust trace list. + * Create UST channel to the tracer. */ -int ust_create_trace(struct command_ctx *cmd_ctx) +int ustctl_create_channel(int sock, struct ltt_ust_session *session, + struct lttng_channel *channel) { - int ret; - struct ltt_ust_trace *trace; - - DBG("Creating trace for pid %d", cmd_ctx->lsm->pid); + struct lttcomm_ust_msg command; + struct lttcomm_ust_reply *reply = NULL; + struct ltt_ust_channel *uchan; - trace = malloc(sizeof(struct ltt_ust_trace)); - if (trace == NULL) { - perror("malloc"); - ret = -1; + uchan = trace_ust_create_channel(channel, session->path); + if (uchan == NULL) { goto error; } - /* Init */ - trace->pid = cmd_ctx->lsm->pid; - trace->shmid = 0; - /* NOTE: to be removed. Trace name will no longer be - * required for LTTng userspace tracer. For now, we set it - * to 'auto' for API compliance. - */ - snprintf(trace->name, 5, "auto"); - - ret = ustctl_create_trace(cmd_ctx->ust_sock, trace->name); - if (ret < 0) { - ret = LTTCOMM_CREATE_FAIL; - goto error_create; + memset(&command, 0, sizeof(command)); + + command.cmd = LTTNG_UST_CHANNEL; + command.handle = session->handle; + + /* Copy channel attributes to command */ + memcpy(&command.u.channel, &uchan->attr, sizeof(command.u.channel)); + + reply = ustcomm_send_command(sock, &command); + if (reply == NULL) { + goto error; } - /* Check if current session is valid */ - if (cmd_ctx->session) { - cds_list_add(&trace->list, &cmd_ctx->session->ust_traces); - cmd_ctx->session->ust_trace_count++; + if (reply->ret_code != LTTCOMM_OK) { + DBG("Return code (%d): %s", reply->ret_code, + lttcomm_get_readable_code(reply->ret_code)); + goto error; } - return LTTCOMM_OK; + uchan->handle = reply->ret_val; + + /* Add channel to session */ + cds_list_add(&uchan->list, &session->channels.head); + session->channels.count++; + + free(reply); + + return 0; -error_create: - free(trace); error: - return ret; + free(reply); + return -1; } /* - * ust_start_trace - * - * Start a trace. This trace, identified by the pid, must be - * in the current session ust_traces list. + * Enable UST channel. */ -int ust_start_trace(struct command_ctx *cmd_ctx) +int ustctl_enable_channel(int sock, struct ltt_ust_session *session, + struct ltt_ust_channel *chan) { - int ret; - struct ltt_ust_trace *trace; + struct lttcomm_ust_msg command; + struct lttcomm_ust_reply *reply = NULL; - DBG("Starting trace for pid %d", cmd_ctx->lsm->pid); + memset(&command, 0, sizeof(command)); - trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid); - if (trace == NULL) { - ret = LTTCOMM_NO_TRACE; + command.cmd = LTTNG_UST_ENABLE; + command.handle = chan->handle; + + reply = ustcomm_send_command(sock, &command); + if (reply == NULL) { goto error; } - ret = ustctl_start_trace(cmd_ctx->ust_sock, "auto"); - if (ret < 0) { - ret = LTTCOMM_START_FAIL; + if (reply->ret_code != LTTCOMM_OK) { + DBG("Return code (%d): %s", reply->ret_code, + lttcomm_get_readable_code(reply->ret_code)); + goto error; + } else if (reply->handle != chan->handle) { + ERR("Receive wrong handle from UST reply on enable channel"); goto error; } - ret = LTTCOMM_OK; + chan->enabled = 1; + free(reply); + + DBG2("ustctl enable channel successful for sock %d", sock); + return 0; error: - return ret; + free(reply); + return -1; } /* - * ust_stop_trace - * - * Stop a trace. This trace, identified by the pid, must be - * in the current session ust_traces list. + * Disable UST channel. */ -int ust_stop_trace(struct command_ctx *cmd_ctx) +int ustctl_disable_channel(int sock, struct ltt_ust_session *session, + struct ltt_ust_channel *chan) { - int ret; - struct ltt_ust_trace *trace; + struct lttcomm_ust_msg command; + struct lttcomm_ust_reply *reply = NULL; + + memset(&command, 0, sizeof(command)); - DBG("Stopping trace for pid %d", cmd_ctx->lsm->pid); + command.cmd = LTTNG_UST_DISABLE; + command.handle = chan->handle; - trace = find_session_ust_trace_by_pid(cmd_ctx->session, cmd_ctx->lsm->pid); - if (trace == NULL) { - ret = LTTCOMM_NO_TRACE; + reply = ustcomm_send_command(sock, &command); + if (reply == NULL) { goto error; } - ret = ustctl_stop_trace(cmd_ctx->ust_sock, trace->name); - if (ret < 0) { - ret = LTTCOMM_STOP_FAIL; + if (reply->ret_code != LTTCOMM_OK) { + DBG("Return code (%d): %s", reply->ret_code, + lttcomm_get_readable_code(reply->ret_code)); + goto error; + } else if (reply->handle != chan->handle) { + ERR("Receive wrong handle from UST reply on enable channel"); goto error; } - ret = LTTCOMM_OK; + chan->enabled = 1; + free(reply); + + DBG2("ustctl disable channel successful for sock %d", sock); + return 0; error: - return ret; + free(reply); + return -1; } -#endif -