X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fclient.c;h=e9553bf1d1ddfbcd6ce4f3457c814bf22d02ffc9;hb=refs%2Fheads%2Fsow-2019-0007-2-rev1;hp=8eff1650ebfe1036f83fced7929f0e136c044ffd;hpb=a7a533cd65d544e8beebabcca5fe906e27af4707;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/client.c b/src/bin/lttng-sessiond/client.c index 8eff1650e..e9553bf1d 100644 --- a/src/bin/lttng-sessiond/client.c +++ b/src/bin/lttng-sessiond/client.c @@ -1,33 +1,29 @@ /* - * Copyright (C) 2011 - David Goulet - * Mathieu Desnoyers - * 2013 - Jérémie Galarneau + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2013 Jérémie Galarneau * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include -#include -#include -#include +#include "common/buffer-view.h" +#include "common/dynamic-buffer.h" +#include "common/sessiond-comm/sessiond-comm.h" +#include "lttng/lttng-error.h" +#include "lttng/tracker.h" #include +#include #include #include -#include #include -#include #include +#include +#include +#include +#include +#include +#include #include "client.h" #include "lttng-sessiond.h" @@ -39,6 +35,7 @@ #include "utils.h" #include "manage-consumer.h" #include "clear.h" +#include "agent-thread.h" static bool is_root; @@ -191,7 +188,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) case LTTNG_CONSUMER64_UST: { if (config.consumerd64_lib_dir.value) { - char *tmp; + const char *tmp; size_t tmplen; char *tmpnew; @@ -228,7 +225,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) case LTTNG_CONSUMER32_UST: { if (config.consumerd32_lib_dir.value) { - char *tmp; + const char *tmp; size_t tmplen; char *tmpnew; @@ -499,6 +496,7 @@ static int create_kernel_session(struct ltt_session *session) session->kernel_session->gid = session->gid; session->kernel_session->output_traces = session->output_traces; session->kernel_session->snapshot_mode = session->snapshot_mode; + session->kernel_session->is_live_session = session->live_timer != 0; return LTTNG_OK; @@ -541,7 +539,6 @@ static int receive_userspace_probe(struct command_ctx *cmd_ctx, int sock, { int fd, ret; struct lttng_userspace_probe_location *probe_location; - const struct lttng_userspace_probe_location_lookup_method *lookup = NULL; struct lttng_dynamic_buffer probe_location_buffer; struct lttng_buffer_view buffer_view; @@ -601,30 +598,7 @@ static int receive_userspace_probe(struct command_ctx *cmd_ctx, int sock, * Set the file descriptor received from the client through the unix * socket in the probe location. */ - lookup = lttng_userspace_probe_location_get_lookup_method(probe_location); - if (!lookup) { - ret = LTTNG_ERR_PROBE_LOCATION_INVAL; - goto error; - } - - /* - * From the kernel tracer's perspective, all userspace probe event types - * are all the same: a file and an offset. - */ - switch (lttng_userspace_probe_location_lookup_method_get_type(lookup)) { - case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF: - ret = lttng_userspace_probe_location_function_set_binary_fd( - probe_location, fd); - break; - case LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT: - ret = lttng_userspace_probe_location_tracepoint_set_binary_fd( - probe_location, fd); - break; - default: - ret = LTTNG_ERR_PROBE_LOCATION_INVAL; - goto error; - } - + ret = lttng_userspace_probe_location_set_binary_fd(probe_location, fd); if (ret) { ret = LTTNG_ERR_PROBE_LOCATION_INVAL; goto error; @@ -719,6 +693,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, int ret = LTTNG_OK; int need_tracing_session = 1; int need_domain; + int need_consumerd = 1; DBG("Processing client command %d", cmd_ctx->lsm->cmd_type); @@ -742,19 +717,29 @@ 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; break; default: need_domain = 1; } + /* Needs a functioning consumerd */ + switch (cmd_ctx->lsm->cmd_type) { + case LTTNG_REGISTER_TRIGGER: + case LTTNG_UNREGISTER_TRIGGER: + need_consumerd = 0; + break; + default: + need_consumerd = 1; + break; + } + if (config.no_kernel && need_domain && cmd_ctx->lsm->domain.type == LTTNG_DOMAIN_KERNEL) { if (!is_root) { @@ -789,11 +774,14 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, case LTTNG_LIST_CHANNELS: case LTTNG_LIST_EVENTS: case LTTNG_LIST_SYSCALLS: - case LTTNG_LIST_TRACKER_IDS: + case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: + case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY: + case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET: case LTTNG_DATA_PENDING: case LTTNG_ROTATE_SESSION: case LTTNG_ROTATION_GET_INFO: - case LTTNG_SESSION_LIST_ROTATION_SCHEDULES: + case LTTNG_REGISTER_TRIGGER: + case LTTNG_LIST_TRIGGERS: break; default: /* Setup lttng message with no payload */ @@ -814,6 +802,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, case LTTNG_SAVE_SESSION: case LTTNG_REGISTER_TRIGGER: case LTTNG_UNREGISTER_TRIGGER: + case LTTNG_LIST_TRIGGERS: need_tracing_session = 0; break; default: @@ -892,7 +881,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; } @@ -937,14 +927,21 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int *sock, case LTTNG_DOMAIN_JUL: case LTTNG_DOMAIN_LOG4J: case LTTNG_DOMAIN_PYTHON: + if (!agent_tracing_is_enabled()) { + ret = LTTNG_ERR_AGENT_TRACING_DISABLED; + goto error; + } + /* Fallthrough */ case LTTNG_DOMAIN_UST: { if (!ust_app_supported()) { 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; } @@ -1205,148 +1202,196 @@ error_add_context: kernel_poll_pipe[1]); break; } - case LTTNG_TRACK_ID: + case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE: + case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE: { - struct lttng_tracker_id *id = NULL; - enum lttng_tracker_id_status status; - - id = lttng_tracker_id_create(); - if (!id) { - ret = LTTNG_ERR_NOMEM; + struct lttng_dynamic_buffer payload; + struct lttng_buffer_view payload_view; + const bool add_value = + cmd_ctx->lsm->cmd_type == + LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE; + const size_t name_len = + cmd_ctx->lsm->u.process_attr_tracker_add_remove_include_value + .name_len; + const enum lttng_domain_type domain_type = + (enum lttng_domain_type) + cmd_ctx->lsm->domain.type; + const enum lttng_process_attr process_attr = + (enum lttng_process_attr) cmd_ctx->lsm->u + .process_attr_tracker_add_remove_include_value + .process_attr; + const enum lttng_process_attr_value_type value_type = + (enum lttng_process_attr_value_type) cmd_ctx + ->lsm->u + .process_attr_tracker_add_remove_include_value + .value_type; + struct process_attr_value *value; + enum lttng_error_code ret_code; + + /* Receive remaining variable length payload if applicable. */ + if (name_len > LOGIN_NAME_MAX) { + /* + * POSIX mandates user and group names that are at least + * 8 characters long. Note that although shadow-utils + * (useradd, groupaadd, etc.) use 32 chars as their + * limit (from bits/utmp.h, UT_NAMESIZE), + * LOGIN_NAME_MAX is defined to 256. + */ + ERR("Rejecting process attribute tracker value %s as the provided exceeds the maximal allowed length: argument length = %zu, maximal length = %d", + add_value ? "addition" : "removal", + name_len, LOGIN_NAME_MAX); + ret = LTTNG_ERR_INVALID; goto error; } - switch (cmd_ctx->lsm->u.id_tracker.id_type) { - case LTTNG_ID_ALL: - status = lttng_tracker_id_set_all(id); - break; - case LTTNG_ID_VALUE: - status = lttng_tracker_id_set_value( - id, cmd_ctx->lsm->u.id_tracker.u.value); - break; - case LTTNG_ID_STRING: - { - const size_t var_len = cmd_ctx->lsm->u.id_tracker.u.var_len; - char *string = NULL; - - string = zmalloc(var_len); - if (!string) { - lttng_tracker_id_destroy(id); + lttng_dynamic_buffer_init(&payload); + if (name_len != 0) { + /* + * Receive variable payload for user/group name + * arguments. + */ + ret = lttng_dynamic_buffer_set_size(&payload, name_len); + if (ret) { + ERR("Failed to allocate buffer to receive payload of %s process attribute tracker value argument", + add_value ? "add" : "remove"); ret = LTTNG_ERR_NOMEM; - goto error; + goto error_add_remove_tracker_value; } - DBG("Receiving var len tracker id string from client"); - ret = lttcomm_recv_unix_sock(*sock, string, var_len); + + ret = lttcomm_recv_unix_sock( + *sock, payload.data, name_len); if (ret <= 0) { - DBG("Nothing received"); + ERR("Failed to receive payload of %s process attribute tracker value argument", + add_value ? "add" : "remove"); *sock_error = 1; - free(string); - lttng_tracker_id_destroy(id); - ret = LTTNG_ERR_INVALID; - goto error; - } - if (strnlen(string, var_len) != var_len - 1) { - DBG("String received as tracker ID is not NULL-terminated"); - free(string); - lttng_tracker_id_destroy(id); - ret = LTTNG_ERR_INVALID; - goto error; + ret = LTTNG_ERR_INVALID_PROTOCOL; + goto error_add_remove_tracker_value; } + } - status = lttng_tracker_id_set_string(id, string); - free(string); - break; + payload_view = lttng_buffer_view_from_dynamic_buffer( + &payload, 0, name_len); + /* + * Validate the value type and domains are legal for the process + * attribute tracker that is specified and convert the value to + * add/remove to the internal sessiond representation. + */ + ret_code = process_attr_value_from_comm(domain_type, + process_attr, value_type, + &cmd_ctx->lsm->u.process_attr_tracker_add_remove_include_value + .integral_value, + &payload_view, &value); + if (ret_code != LTTNG_OK) { + ret = ret_code; + goto error_add_remove_tracker_value; + } + + if (add_value) { + ret = cmd_process_attr_tracker_inclusion_set_add_value( + cmd_ctx->session, domain_type, + process_attr, value); + } else { + ret = cmd_process_attr_tracker_inclusion_set_remove_value( + cmd_ctx->session, domain_type, + process_attr, value); } - default: - lttng_tracker_id_destroy(id); - ret = LTTNG_ERR_INVALID; + process_attr_value_destroy(value); + error_add_remove_tracker_value: + lttng_dynamic_buffer_reset(&payload); + break; + } + case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY: + { + enum lttng_tracking_policy tracking_policy; + const enum lttng_domain_type domain_type = + (enum lttng_domain_type) + cmd_ctx->lsm->domain.type; + const enum lttng_process_attr process_attr = + (enum lttng_process_attr) cmd_ctx->lsm->u + .process_attr_tracker_get_tracking_policy + .process_attr; + + ret = cmd_process_attr_tracker_get_tracking_policy( + cmd_ctx->session, domain_type, process_attr, + &tracking_policy); + if (ret != LTTNG_OK) { goto error; } - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ERR("Invalid value for tracker id"); - ret = LTTNG_ERR_INVALID; - lttng_tracker_id_destroy(id); + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, + &(uint32_t){tracking_policy}, sizeof(uint32_t)); + if (ret < 0) { + ret = LTTNG_ERR_NOMEM; goto error; } - - ret = cmd_track_id(cmd_ctx->session, - cmd_ctx->lsm->u.id_tracker.tracker_type, - cmd_ctx->lsm->domain.type, id); - lttng_tracker_id_destroy(id); + ret = LTTNG_OK; break; } - case LTTNG_UNTRACK_ID: + case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY: { - struct lttng_tracker_id *id = NULL; - enum lttng_tracker_id_status status; - - id = lttng_tracker_id_create(); - - switch (cmd_ctx->lsm->u.id_tracker.id_type) { - case LTTNG_ID_ALL: - status = lttng_tracker_id_set_all(id); - break; - case LTTNG_ID_VALUE: - status = lttng_tracker_id_set_value( - id, cmd_ctx->lsm->u.id_tracker.u.value); - break; - case LTTNG_ID_STRING: - { - const size_t var_len = cmd_ctx->lsm->u.id_tracker.u.var_len; - char *string = NULL; - - string = zmalloc(var_len); - if (!string) { - ret = LTTNG_ERR_NOMEM; - lttng_tracker_id_destroy(id); - goto error; - } - DBG("Receiving var len tracker id string from client"); - ret = lttcomm_recv_unix_sock(*sock, string, var_len); - if (ret <= 0) { - DBG("Nothing received"); - *sock_error = 1; - lttng_tracker_id_destroy(id); - free(string); - ret = LTTNG_ERR_INVALID; - goto error; - } - if (strnlen(string, var_len) != var_len - 1) { - DBG("String received as tracker ID is not NULL-terminated"); - lttng_tracker_id_destroy(id); - free(string); - ret = LTTNG_ERR_INVALID; - goto error; - } - status = lttng_tracker_id_set_string(id, string); - free(string); - break; + const enum lttng_tracking_policy tracking_policy = + (enum lttng_tracking_policy) cmd_ctx->lsm->u + .process_attr_tracker_set_tracking_policy + .tracking_policy; + const enum lttng_domain_type domain_type = + (enum lttng_domain_type) + cmd_ctx->lsm->domain.type; + const enum lttng_process_attr process_attr = + (enum lttng_process_attr) cmd_ctx->lsm->u + .process_attr_tracker_set_tracking_policy + .process_attr; + + ret = cmd_process_attr_tracker_set_tracking_policy( + cmd_ctx->session, domain_type, process_attr, + tracking_policy); + if (ret != LTTNG_OK) { + goto error; } - default: - lttng_tracker_id_destroy(id); - ret = LTTNG_ERR_INVALID; + break; + } + case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET: + { + struct lttng_process_attr_values *values; + struct lttng_dynamic_buffer reply; + const enum lttng_domain_type domain_type = + (enum lttng_domain_type) + cmd_ctx->lsm->domain.type; + const enum lttng_process_attr process_attr = + (enum lttng_process_attr) cmd_ctx->lsm->u + .process_attr_tracker_get_inclusion_set + .process_attr; + + ret = cmd_process_attr_tracker_get_inclusion_set( + cmd_ctx->session, domain_type, process_attr, + &values); + if (ret != LTTNG_OK) { goto error; } - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ERR("Invalid tracker id"); - lttng_tracker_id_destroy(id); - ret = LTTNG_ERR_INVALID; - goto error; + lttng_dynamic_buffer_init(&reply); + ret = lttng_process_attr_values_serialize(values, &reply); + if (ret < 0) { + goto error_tracker_get_inclusion_set; } - ret = cmd_untrack_id(cmd_ctx->session, - cmd_ctx->lsm->u.id_tracker.tracker_type, - cmd_ctx->lsm->domain.type, id); - lttng_tracker_id_destroy(id); + ret = setup_lttng_msg_no_cmd_header( + cmd_ctx, reply.data, reply.size); + if (ret < 0) { + ret = LTTNG_ERR_NOMEM; + goto error_tracker_get_inclusion_set; + } + ret = LTTNG_OK; + + error_tracker_get_inclusion_set: + lttng_process_attr_values_destroy(values); + lttng_dynamic_buffer_reset(&reply); break; } case LTTNG_ENABLE_EVENT: { struct lttng_event *ev = NULL; struct lttng_event_exclusion *exclusion = NULL; - struct lttng_filter_bytecode *bytecode = NULL; + struct lttng_bytecode *bytecode = NULL; char *filter_expression = NULL; /* Handle exclusion events and receive it from the client. */ @@ -1565,92 +1610,6 @@ error_add_context: ret = LTTNG_OK; break; } - case LTTNG_LIST_TRACKER_IDS: - { - struct lttcomm_tracker_command_header cmd_header; - struct lttng_tracker_ids *ids = NULL; - size_t nr_ids, i; - struct lttng_dynamic_buffer buf; - - ret = cmd_list_tracker_ids( - cmd_ctx->lsm->u.id_tracker.tracker_type, - cmd_ctx->session, cmd_ctx->lsm->domain.type, - &ids); - if (ret != LTTNG_OK) { - goto error; - } - - nr_ids = lttng_tracker_ids_get_count(ids); - lttng_dynamic_buffer_init(&buf); - for (i = 0; i < nr_ids; i++) { - const struct lttng_tracker_id *id; - struct lttcomm_tracker_id_header id_hdr; - size_t var_data_len = 0; - enum lttng_tracker_id_status status; - const char *string; - int value; - - id = lttng_tracker_ids_get_at_index(ids, i); - if (!id) { - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - - memset(&id_hdr, 0, sizeof(id_hdr)); - id_hdr.type = lttng_tracker_id_get_type(id); - switch (id_hdr.type) { - case LTTNG_ID_ALL: - break; - case LTTNG_ID_VALUE: - status = lttng_tracker_id_get_value(id, &value); - id_hdr.u.value = value; - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - break; - case LTTNG_ID_STRING: - status = lttng_tracker_id_get_string( - id, &string); - if (status != LTTNG_TRACKER_ID_STATUS_OK) { - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - - id_hdr.u.var_data_len = var_data_len = - strlen(string) + 1; - break; - default: - ret = LTTNG_ERR_INVALID; - goto error_list_tracker; - } - ret = lttng_dynamic_buffer_append( - &buf, &id_hdr, sizeof(id_hdr)); - if (ret) { - ret = LTTNG_ERR_NOMEM; - goto error_list_tracker; - } - ret = lttng_dynamic_buffer_append( - &buf, string, var_data_len); - if (ret) { - ret = LTTNG_ERR_NOMEM; - goto error_list_tracker; - } - } - - cmd_header.nb_tracker_id = nr_ids; - ret = setup_lttng_msg(cmd_ctx, buf.data, buf.size, &cmd_header, - sizeof(cmd_header)); - error_list_tracker: - lttng_tracker_ids_destroy(ids); - lttng_dynamic_buffer_reset(&buf); - if (ret < 0) { - goto setup_error; - } - - ret = LTTNG_OK; - break; - } case LTTNG_SET_CONSUMER_URI: { size_t nb_uri, len; @@ -2009,8 +1968,33 @@ error_add_context: } case LTTNG_REGISTER_TRIGGER: { + struct lttng_dynamic_buffer payload; + struct lttng_trigger *return_trigger; + + lttng_dynamic_buffer_init(&payload); ret = cmd_register_trigger(cmd_ctx, *sock, - notification_thread_handle); + notification_thread_handle, &return_trigger); + if (ret != LTTNG_OK) { + goto error; + } + + ret = lttng_trigger_serialize(return_trigger, &payload, NULL); + if (ret) { + ERR("Failed to serialize trigger in reply to \"register trigger\" command"); + ret = LTTNG_ERR_NOMEM; + lttng_trigger_destroy(return_trigger); + goto error; + } + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, payload.data, + payload.size); + if (ret) { + lttng_trigger_destroy(return_trigger); + ret = LTTNG_ERR_NOMEM; + goto error; + } + lttng_trigger_destroy(return_trigger); + lttng_dynamic_buffer_reset(&payload); + ret = LTTNG_OK; break; } case LTTNG_UNREGISTER_TRIGGER: @@ -2123,6 +2107,37 @@ error_add_context: ret = cmd_clear_session(cmd_ctx->session, sock); break; } + case LTTNG_LIST_TRIGGERS: + { + struct lttng_dynamic_buffer payload; + struct lttng_triggers *return_triggers; + + lttng_dynamic_buffer_init(&payload); + ret = cmd_list_triggers(cmd_ctx, *sock, + notification_thread_handle, &return_triggers); + if (ret != LTTNG_OK) { + goto error; + } + + ret = lttng_triggers_serialize(return_triggers, &payload); + if (ret) { + ERR("Failed to serialize triggers in reply to \"list triggers\" command"); + ret = LTTNG_ERR_NOMEM; + lttng_triggers_destroy(return_triggers); + goto error; + } + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, payload.data, + payload.size); + if (ret) { + ret = LTTNG_ERR_NOMEM; + lttng_triggers_destroy(return_triggers); + goto error; + } + lttng_dynamic_buffer_reset(&payload); + lttng_triggers_destroy(return_triggers); + ret = LTTNG_OK; + break; + } default: ret = LTTNG_ERR_UND; break;