Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Misc cleanups.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 6 Nov 2013 06:47:24 +0000 (07:47 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 6 Nov 2013 14:15:20 +0000 (15:15 +0100)
* stat'ing the directory before mkdir is just wrong (race condition),
  remove this test and let fopen report any error;
* use mode 0777 for mkdir, and let the user adjust his umask;
* use xbt_free() instead of free();
* remove useless tests before xbt_{dict,dynar}_free();
* and the usual reindent.
(cherry picked from commit 332285d51119f8f98270655bf88f485a9f914df1)

src/instr/instr_TI_trace.c
src/instr/instr_trace.c

index 5846c77..036c757 100644 (file)
@@ -8,7 +8,8 @@
 #include "xbt/xbt_os_time.h"
 #include "simgrid/sg_config.h"
 
-
+#include <errno.h>
+#include <string.h>
 #include <sys/stat.h>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_TI_trace, instr_trace, "tracing event system");
@@ -48,54 +49,46 @@ void TRACE_TI_start(void)
 
 void TRACE_TI_end(void)
 {
-  if(tracing_files)xbt_dict_free(&tracing_files);
+  xbt_dict_free(&tracing_files);
   fclose(tracing_file);
   char *filename = TRACE_get_filename();
   XBT_DEBUG("Filename %s is closed", filename);
 }
 
-void print_TICreateContainer(paje_event_t event){
+void print_TICreateContainer(paje_event_t event)
+{
+  //if we are in the mode with only one file
+  static FILE *temp = NULL;
 
-  char* folder_name = bprintf("%s_files",TRACE_get_filename());
-  if(tracing_files==NULL){
+  if (tracing_files == NULL) {
     tracing_files = xbt_dict_new_homogeneous(NULL);
-    struct stat st;
-    if (stat(folder_name, &st) == -1) {
-        mkdir(folder_name, 0700);
-    }
     //generate unique run id with time
-    prefix=xbt_os_time();
+    prefix = xbt_os_time();
   }
 
-  //Open a file for each new container
-  char *filename = NULL;
-
-
-  //if we are in the mode with only one file
-  static FILE* temp = NULL;
-
-  if (!xbt_cfg_get_boolean(_sg_cfg_set, "tracing/smpi/format/ti_one_file") || temp ==NULL){
-    filename = bprintf("%s/%f_%s.txt", folder_name, prefix, ((createContainer_t) event->data)->container->name);
-    temp=fopen(filename, "w");
-    if(temp==NULL){
-    xbt_die("Tracefile %s could not be opened for writing.",
-           filename);
-    }
+  if (!xbt_cfg_get_boolean(_sg_cfg_set, "tracing/smpi/format/ti_one_file")
+      || temp == NULL) {
+    char *folder_name = bprintf("%s_files", TRACE_get_filename());
+    char *filename = bprintf("%s/%f_%s.txt", folder_name, prefix,
+                             ((createContainer_t) event->data)->container->name);
+    mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
+    temp = fopen(filename, "w"); /* FIXME: file is never closed */
+    if (temp == NULL)
+      xbt_die("Tracefile %s could not be opened for writing: %s",
+              filename, strerror(errno));
     fprintf(tracing_file, "%s\n", filename);
 
+    xbt_free(folder_name);
+    xbt_free(filename);
   }
 
-
-
-  xbt_dict_set(tracing_files, ((createContainer_t) event->data)->container->name, (void*)temp, NULL);
-
-  //Append its path to the main file
-  free(folder_name);
-  free(filename);
+  xbt_dict_set(tracing_files,
+               ((createContainer_t) event->data)->container->name,
+               (void *) temp, NULL);
 }
 
-
-void print_TIDestroyContainer(paje_event_t event){
+void print_TIDestroyContainer(paje_event_t event)
+{
   xbt_dict_remove(tracing_files, ((destroyContainer_t) event->data)->container->name);
 }
 
index e37756a..005ec35 100644 (file)
@@ -27,8 +27,6 @@ s_instr_trace_writer_t active_writer = {
     print_NULL, print_NULL
 };
 
-
-
 xbt_dynar_t buffer = NULL;
 
 void dump_comment (const char *comment)
@@ -59,12 +57,14 @@ void dump_comment_file (const char *filename)
   fclose(file);
 }
 
-void TRACE_init(){
-   buffer = xbt_dynar_new(sizeof(paje_event_t), NULL);
+void TRACE_init()
+{
+  buffer = xbt_dynar_new(sizeof(paje_event_t), NULL);
 }
 
-void TRACE_finalize(){
-  if (buffer) xbt_dynar_free(&buffer);
+void TRACE_finalize()
+{
+  xbt_dynar_free(&buffer);
 }
 
 double TRACE_last_timestamp_to_dump = 0;