hdt: Using flush() for dumping data
authorErwan Velu <erwanaliasr1@gmail.com>
Mon, 21 Mar 2011 22:04:01 +0000 (23:04 +0100)
committerErwan Velu <erwanaliasr1@gmail.com>
Mon, 21 Mar 2011 22:04:01 +0000 (23:04 +0100)
This function ease the printing & generation of the dumped information &
files

com32/hdt/hdt-dump-cpu.c
com32/hdt/hdt-dump.c
com32/hdt/hdt-dump.h

index c0bb952..dc58a6f 100644 (file)
@@ -48,5 +48,6 @@ void dump_cpu(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item)
                snprintf(temp,sizeof(temp),"cpu.flags.%s",cpu_flags_names[i]);
                add_b(temp,get_cpu_flag_value_from_name(&hardware->cpu,cpu_flags_names[i]));
        }
-       print_and_flush(config,item);
+
+       flush("cpu",config,item);
 }
index 027a82e..9647eba 100644 (file)
@@ -75,6 +75,15 @@ int dumpprintf(FILE *p, const char *format, ...) {
    return rv;
 }
 
+void flush (char *filename, ZZJSON_CONFIG *config, ZZJSON ** item) { 
+   print_and_flush(config,item);
+   cpio_writefile(upload,filename,p_buf.buf,p_buf.len);
+   if (p_buf.buf) { 
+      memset(p_buf.buf,0,p_buf.size);
+      free(p_buf.buf); 
+   }
+}
+
 /**
  * dump - dump info
  **/
@@ -91,7 +100,6 @@ void dump(struct s_hardware *hardware)
     };
 
     detect_hardware(hardware);
-    dump_cpu(hardware, &config, &json);
 
     /* By now, we only support TFTP reporting */
     upload=&upload_tftp;
@@ -110,12 +118,9 @@ void dump(struct s_hardware *hardware)
     /* We initiate the cpio to send */
     cpio_init(upload,(const char **)arg);
 
-    cpio_writefile(upload,"cpu",p_buf.buf,p_buf.len);
+    dump_cpu(hardware, &config, &json);
 
     /* We close & flush the file to send */
     cpio_close(upload);
     flush_data(upload);
-    if (p_buf.buf) { 
-           free(p_buf.buf); 
-    }
 }
index 1ec6aa2..2f9dd6f 100644 (file)
@@ -46,5 +46,6 @@ extern struct print_buf p_buf;
 
 void print_and_flush(ZZJSON_CONFIG *config, ZZJSON **item);
 int dumpprintf(FILE *p, const char *format, ...);
+void flush (char *filename, ZZJSON_CONFIG *config, ZZJSON ** item);
 
 void dump_cpu(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item);