X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fwriter.c;h=3630b36b177abb9c253451419b5b10f8a9e90f3a;hp=8529a1e31a4d07f6c0bb9d5d7c3fa4483124e548;hb=12af6048688baa3c9731f92a477b352a2a571deb;hpb=c4e511dfb2a168ee45764b6f6e6190c400b76b4b diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index 8529a1e3..3630b36b 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -115,8 +115,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) 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; @@ -168,11 +167,17 @@ void bt_ctf_writer_destroy(struct bt_ctf_ref *ref) } 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) { - close(writer->metadata_fd); + if (close(writer->metadata_fd)) { + perror("close"); + abort(); + } } if (writer->environment) { @@ -352,7 +357,7 @@ const char *get_byte_order_string(int byte_order) } 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; @@ -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); - assert(!ret); + if (ret) { + goto end; + } context->current_indentation_level--; g_string_append(context->string, ";\n};\n\n"); +end: + return ret; } 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"); - 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); @@ -555,8 +566,9 @@ int validate_identifier(const char *input_string) 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; } @@ -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++) { - 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;