tap-driver.sh: flush stdout after each test result
[babeltrace.git] / plugins / ctf / fs-sink / fs-sink-trace.c
index 375fff970996cdd5a5da14c5243b5c46a067e8f2..400b21d7e7a4ff625aca44605cf31861c93a88b9 100644 (file)
 #define BT_LOG_TAG "PLUGIN-CTF-FS-SINK-TRACE"
 #include "logging.h"
 
-#include <babeltrace/babeltrace.h>
+#include <babeltrace2/babeltrace.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <glib.h>
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/ctfser-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/ctfser-internal.h>
 
 #include "translate-trace-ir-to-ctf-ir.h"
 #include "translate-ctf-ir-to-tsdl.h"
@@ -139,18 +139,16 @@ GString *make_unique_trace_path(const char *path)
 static
 int lttng_validate_datetime(const char *datetime)
 {
-       GTimeZone *default_tz;
-       GDateTime *gdatetime = NULL;
+       GTimeVal tv;
        int ret = -1;
 
-       default_tz = g_time_zone_new_utc();
-       if (!default_tz) {
-               BT_LOGD("Failed to allocate timezone");
-               goto end;
-       }
-
-       gdatetime = g_date_time_new_from_iso8601(datetime, default_tz);
-       if (!gdatetime) {
+       /*
+        * We are using g_time_val_from_iso8601, as the safer/more modern
+        * alternative, g_date_time_new_from_iso8601, is only available in
+        * glib >= 2.56, and this is sufficient for our use case of validating
+        * the format.
+        */
+       if (!g_time_val_from_iso8601(datetime, &tv)) {
                BT_LOGD("Couldn't parse datetime as iso8601: date=\"%s\"", datetime);
                goto end;
        }
@@ -158,16 +156,6 @@ int lttng_validate_datetime(const char *datetime)
        ret = 0;
 
 end:
-       if (default_tz) {
-               g_time_zone_unref(default_tz);
-               default_tz = NULL;
-       }
-
-       if (gdatetime) {
-               g_date_time_unref(gdatetime);
-               gdatetime = NULL;
-       }
-
        return ret;
 }
 
@@ -178,20 +166,22 @@ int append_lttng_trace_path_ust_uid(GString *path, const bt_trace_class *tc)
        int ret;
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_buffering_id\"");
                goto error;
        }
 
-       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64, bt_value_integer_get(v));
+       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64,
+               bt_value_signed_integer_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "isa_length");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"isa_length\"");
                goto error;
        }
 
-       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit", bt_value_integer_get(v));
+       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit",
+               bt_value_signed_integer_get(v));
 
        ret = 0;
        goto end;
@@ -219,12 +209,12 @@ int append_lttng_trace_path_ust_pid(GString *path, const bt_trace_class *tc)
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"vpid\"");
                goto error;
        }
 
-       g_string_append_printf(path, "-%" PRId64, bt_value_integer_get(v));
+       g_string_append_printf(path, "-%" PRId64, bt_value_signed_integer_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
        if (!v || !bt_value_is_string(v)) {
@@ -285,20 +275,20 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
        }
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_major");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_major\"");
                goto error;
        }
 
-       tracer_major = bt_value_integer_get(v);
+       tracer_major = bt_value_signed_integer_get(v);
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_minor");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_minor\"");
                goto error;
        }
 
-       tracer_minor = bt_value_integer_get(v);
+       tracer_minor = bt_value_signed_integer_get(v);
 
        if (!(tracer_major >= 3 || (tracer_major == 2 && tracer_minor >= 11))) {
                BT_LOGD("Unsupported LTTng version for automatic trace path: major=%" PRId64 ", minor=%" PRId64,
@@ -499,6 +489,8 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
        tsdl = g_string_new(NULL);
        BT_ASSERT(tsdl);
        translate_trace_class_ctf_ir_to_tsdl(trace->tc, tsdl);
+
+       BT_ASSERT(trace->metadata_path);
        fh = fopen(trace->metadata_path->str, "wb");
        if (!fh) {
                BT_LOGF_ERRNO("In trace destruction listener: "
@@ -524,10 +516,8 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
                trace->path = NULL;
        }
 
-       if (trace->metadata_path) {
-               g_string_free(trace->metadata_path, TRUE);
-               trace->metadata_path = NULL;
-       }
+       g_string_free(trace->metadata_path, TRUE);
+       trace->metadata_path = NULL;
 
        fs_sink_ctf_trace_class_destroy(trace->tc);
        trace->tc = NULL;
This page took 0.026385 seconds and 4 git commands to generate.