Fix: Don't assert on metadata generation failure
[babeltrace.git] / formats / ctf / writer / writer.c
index 8529a1e31a4d07f6c0bb9d5d7c3fa4483124e548..3630b36b177abb9c253451419b5b10f8a9e90f3a 100644 (file)
@@ -115,8 +115,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
                goto error_destroy;
        }
 
                goto error_destroy;
        }
 
-       writer->trace_dir_fd = open(path, O_RDONLY | O_DIRECTORY,
-               S_IRWXU | S_IRWXG);
+       writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG);
        if (writer->trace_dir_fd < 0) {
                perror("open");
                goto error_destroy;
        if (writer->trace_dir_fd < 0) {
                perror("open");
                goto error_destroy;
@@ -168,11 +167,17 @@ void bt_ctf_writer_destroy(struct bt_ctf_ref *ref)
        }
 
        if (writer->trace_dir_fd > 0) {
        }
 
        if (writer->trace_dir_fd > 0) {
-               close(writer->trace_dir_fd);
+               if (close(writer->trace_dir_fd)) {
+                       perror("close");
+                       abort();
+               }
        }
 
        if (writer->metadata_fd > 0) {
        }
 
        if (writer->metadata_fd > 0) {
-               close(writer->metadata_fd);
+               if (close(writer->metadata_fd)) {
+                       perror("close");
+                       abort();
+               }
        }
 
        if (writer->environment) {
        }
 
        if (writer->environment) {
@@ -352,7 +357,7 @@ const char *get_byte_order_string(int byte_order)
 }
 
 static
 }
 
 static
-void append_trace_metadata(struct bt_ctf_writer *writer,
+int append_trace_metadata(struct bt_ctf_writer *writer,
                struct metadata_context *context)
 {
        unsigned char *uuid = writer->uuid;
                struct metadata_context *context)
 {
        unsigned char *uuid = writer->uuid;
@@ -377,10 +382,14 @@ void append_trace_metadata(struct bt_ctf_writer *writer,
        g_string_assign(context->field_name, "");
        ret = bt_ctf_field_type_serialize(writer->trace_packet_header_type,
                context);
        g_string_assign(context->field_name, "");
        ret = bt_ctf_field_type_serialize(writer->trace_packet_header_type,
                context);
-       assert(!ret);
+       if (ret) {
+               goto end;
+       }
        context->current_indentation_level--;
 
        g_string_append(context->string, ";\n};\n\n");
        context->current_indentation_level--;
 
        g_string_append(context->string, ";\n};\n\n");
+end:
+       return ret;
 }
 
 static
 }
 
 static
@@ -424,7 +433,9 @@ char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer)
        context->field_name = g_string_sized_new(DEFAULT_IDENTIFIER_SIZE);
        context->string = g_string_sized_new(DEFAULT_METADATA_STRING_SIZE);
        g_string_append(context->string, "/* CTF 1.8 */\n\n");
        context->field_name = g_string_sized_new(DEFAULT_IDENTIFIER_SIZE);
        context->string = g_string_sized_new(DEFAULT_METADATA_STRING_SIZE);
        g_string_append(context->string, "/* CTF 1.8 */\n\n");
-       append_trace_metadata(writer, context);
+       if (append_trace_metadata(writer, context)) {
+               goto error;
+       }
        append_env_metadata(writer, context);
        g_ptr_array_foreach(writer->clocks,
                (GFunc)bt_ctf_clock_serialize, context);
        append_env_metadata(writer, context);
        g_ptr_array_foreach(writer->clocks,
                (GFunc)bt_ctf_clock_serialize, context);
@@ -555,8 +566,9 @@ int validate_identifier(const char *input_string)
 
        token = strtok_r(string, " ", &save_ptr);
        while (token) {
 
        token = strtok_r(string, " ", &save_ptr);
        while (token) {
-               if (g_hash_table_contains(reserved_keywords_set,
-                       GINT_TO_POINTER(g_quark_from_string(token)))) {
+               if (g_hash_table_lookup_extended(reserved_keywords_set,
+                       GINT_TO_POINTER(g_quark_from_string(token)),
+                       NULL, NULL)) {
                        ret = -1;
                        goto end;
                }
                        ret = -1;
                        goto end;
                }
@@ -732,8 +744,10 @@ void writer_init(void)
 
        reserved_keywords_set = g_hash_table_new(g_direct_hash, g_direct_equal);
        for (i = 0; i < reserved_keywords_count; i++) {
 
        reserved_keywords_set = g_hash_table_new(g_direct_hash, g_direct_equal);
        for (i = 0; i < reserved_keywords_count; i++) {
-               g_hash_table_add(reserved_keywords_set,
-               GINT_TO_POINTER(g_quark_from_string(reserved_keywords_str[i])));
+               gpointer quark = GINT_TO_POINTER(g_quark_from_string(
+                       reserved_keywords_str[i]));
+
+               g_hash_table_insert(reserved_keywords_set, quark, quark);
        }
 
        init_done = 1;
        }
 
        init_done = 1;
This page took 0.023169 seconds and 4 git commands to generate.