+ 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;
+ }
+
+ 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_add_remove_tracker_value;
+ }
+
+ ret = lttcomm_recv_unix_sock(
+ *sock, payload.data, name_len);
+ if (ret <= 0) {
+ ERR("Failed to receive payload of %s process attribute tracker value argument",
+ add_value ? "add" : "remove");
+ *sock_error = 1;
+ ret = LTTNG_ERR_INVALID_PROTOCOL;
+ goto error_add_remove_tracker_value;
+ }
+ }
+
+ 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);
+ }
+ process_attr_value_destroy(value);
+ error_add_remove_tracker_value:
+ lttng_dynamic_buffer_reset(&payload);