+ ret = config_writer_open_element(writer,
+ config_element_channels);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ cds_list_for_each_entry(kchan, &session->kernel_session->channel_list.head,
+ list) {
+ ret = save_kernel_channel(writer, kchan);
+ if (ret != LTTNG_OK) {
+ goto end;
+ }
+ }
+
+ /* /channels */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ ret = LTTNG_OK;
+end:
+ return ret;
+}
+
+static
+const char *get_config_domain_str(enum lttng_domain_type domain)
+{
+ const char *str_dom;
+
+ switch (domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ str_dom = config_domain_type_kernel;
+ break;
+ case LTTNG_DOMAIN_UST:
+ str_dom = config_domain_type_ust;
+ break;
+ case LTTNG_DOMAIN_JUL:
+ str_dom = config_domain_type_jul;
+ break;
+ case LTTNG_DOMAIN_LOG4J:
+ str_dom = config_domain_type_log4j;
+ break;
+ case LTTNG_DOMAIN_PYTHON:
+ str_dom = config_domain_type_python;
+ break;
+ default:
+ assert(0);
+ }
+
+ return str_dom;
+}
+
+/* Return LTTNG_OK on success else a LTTNG_ERR* code. */
+static int save_process_attr_tracker(struct config_writer *writer,
+ struct ltt_session *sess,
+ int domain,
+ enum lttng_process_attr process_attr)
+{
+ int ret = LTTNG_OK;
+ const char *element_id_tracker, *element_target_id, *element_id;
+ const struct process_attr_tracker *tracker;
+ enum lttng_tracking_policy tracking_policy;
+ struct lttng_process_attr_values *values = NULL;
+
+ switch (process_attr) {
+ case LTTNG_PROCESS_ATTR_PROCESS_ID:
+ element_id_tracker = config_element_process_attr_tracker_pid;
+ element_target_id = config_element_process_attr_pid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
+ element_id_tracker = config_element_process_attr_tracker_vpid;
+ element_target_id = config_element_process_attr_vpid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ case LTTNG_PROCESS_ATTR_USER_ID:
+ element_id_tracker = config_element_process_attr_tracker_uid;
+ element_target_id = config_element_process_attr_uid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
+ element_id_tracker = config_element_process_attr_tracker_vuid;
+ element_target_id = config_element_process_attr_vuid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ case LTTNG_PROCESS_ATTR_GROUP_ID:
+ element_id_tracker = config_element_process_attr_tracker_gid;
+ element_target_id = config_element_process_attr_gid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
+ element_id_tracker = config_element_process_attr_tracker_vgid;
+ element_target_id = config_element_process_attr_vgid_value;
+ element_id = config_element_process_attr_id;
+ break;
+ default:
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ switch (domain) {
+ case LTTNG_DOMAIN_KERNEL:
+ {
+ tracker = kernel_get_process_attr_tracker(
+ sess->kernel_session, process_attr);
+ assert(tracker);
+ break;
+ }
+ case LTTNG_DOMAIN_UST:
+ {
+ tracker = trace_ust_get_process_attr_tracker(
+ sess->ust_session, process_attr);
+ assert(tracker);
+ break;
+ }
+ case LTTNG_DOMAIN_JUL:
+ case LTTNG_DOMAIN_LOG4J:
+ case LTTNG_DOMAIN_PYTHON:
+ default:
+ ret = LTTNG_ERR_UNSUPPORTED_DOMAIN;
+ goto end;
+ }
+
+ tracking_policy = process_attr_tracker_get_tracking_policy(tracker);
+ if (tracking_policy == LTTNG_TRACKING_POLICY_INCLUDE_ALL) {
+ /* Tracking all, nothing to output. */
+ ret = LTTNG_OK;
+ goto end;
+ }
+
+ ret = config_writer_open_element(writer, element_id_tracker);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ ret = config_writer_open_element(
+ writer, config_element_process_attr_values);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ if (tracking_policy == LTTNG_TRACKING_POLICY_INCLUDE_SET) {
+ unsigned int i, count;
+ enum process_attr_tracker_status status =
+ process_attr_tracker_get_inclusion_set(
+ tracker, &values);
+
+ if (status != PROCESS_ATTR_TRACKER_STATUS_OK) {
+ ret = LTTNG_ERR_NOMEM;
+ goto end;
+ }
+
+ count = _lttng_process_attr_values_get_count(values);
+
+ for (i = 0; i < count; i++) {
+ unsigned int integral_value = UINT_MAX;
+ const char *name = NULL;
+ const struct process_attr_value *value =
+ lttng_process_attr_tracker_values_get_at_index(
+ values, i);
+
+ assert(value);
+ ret = config_writer_open_element(
+ writer, element_target_id);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ switch (value->type) {
+ case LTTNG_PROCESS_ATTR_VALUE_TYPE_PID:
+ integral_value =
+ (unsigned int) value->value.pid;
+ break;
+ case LTTNG_PROCESS_ATTR_VALUE_TYPE_UID:
+ integral_value =
+ (unsigned int) value->value.uid;
+ break;
+ case LTTNG_PROCESS_ATTR_VALUE_TYPE_GID:
+ integral_value =
+ (unsigned int) value->value.gid;
+ break;
+ case LTTNG_PROCESS_ATTR_VALUE_TYPE_USER_NAME:
+ name = value->value.user_name;
+ assert(name);
+ break;
+ case LTTNG_PROCESS_ATTR_VALUE_TYPE_GROUP_NAME:
+ name = value->value.group_name;
+ assert(name);
+ break;
+ default:
+ abort();
+ }
+
+ if (name) {
+ ret = config_writer_write_element_string(writer,
+ config_element_name, name);
+ } else {
+ ret = config_writer_write_element_unsigned_int(
+ writer, element_id,
+ integral_value);
+ }
+
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ /* /$element_target_id */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+ }
+ }
+
+ /* /values */
+ ret = config_writer_close_element(writer);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ /* /$element_id_tracker */
+ ret = config_writer_close_element(writer);