X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fwriter.c;h=b0a35c6963d04245c1f4862f7ae74be3eb5069d6;hb=f6afb94e88f4fb2a47384559fe14ad82a3ec7f20;hp=8529a1e31a4d07f6c0bb9d5d7c3fa4483124e548;hpb=c4e511dfb2a168ee45764b6f6e6190c400b76b4b;p=babeltrace.git diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index 8529a1e3..b0a35c69 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -115,8 +116,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 +168,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 +358,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 +383,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 +434,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 +567,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 +745,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;