+static
+int set_trace_name(struct ctx *ctx)
+{
+ GString *name;
+ int ret = 0;
+ struct bt_value *value = NULL;
+
+ assert(bt_ctf_trace_get_stream_class_count(ctx->trace) == 0);
+ name = g_string_new(NULL);
+ if (!name) {
+ ret = -1;
+ goto end;
+ }
+
+ /*
+ * Check if we have a trace environment string value named `hostname`.
+ * If so, use it as the trace name's prefix.
+ */
+ value = bt_ctf_trace_get_environment_field_value_by_name(ctx->trace,
+ "hostname");
+ if (bt_value_is_string(value)) {
+ const char *hostname;
+
+ ret = bt_value_string_get(value, &hostname);
+ assert(ret == 0);
+ g_string_append(name, hostname);
+
+ if (ctx->trace_name_suffix) {
+ g_string_append_c(name, G_DIR_SEPARATOR);
+ }
+ }
+
+ if (ctx->trace_name_suffix) {
+ g_string_append(name, ctx->trace_name_suffix);
+ }
+
+ ret = bt_ctf_trace_set_name(ctx->trace, name->str);
+ if (ret) {
+ goto error;
+ }
+
+ goto end;
+
+error:
+ ret = -1;
+
+end:
+ bt_put(value);
+
+ if (name) {
+ g_string_free(name, TRUE);
+ }
+
+ return ret;
+}
+