+static
+int set_trace_name(bt_trace *trace, const char *name_suffix)
+{
+ int ret = 0;
+ const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
+ const bt_value *val;
+ GString *name;
+
+ name = g_string_new(NULL);
+ if (!name) {
+ BT_LOGE_STR("Failed to allocate a GString.");
+ 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.
+ */
+ val = bt_trace_class_borrow_environment_entry_value_by_name_const(
+ tc, "hostname");
+ if (val && bt_value_is_string(val)) {
+ g_string_append(name, bt_value_string_get(val));
+
+ if (name_suffix) {
+ g_string_append_c(name, G_DIR_SEPARATOR);
+ }
+ }
+
+ if (name_suffix) {
+ g_string_append(name, name_suffix);
+ }
+
+ ret = bt_trace_set_name(trace, name->str);
+ if (ret) {
+ goto end;
+ }
+
+ goto end;
+
+end:
+ if (name) {
+ g_string_free(name, TRUE);
+ }
+
+ return ret;
+}
+