@@ -112,7 +112,12 @@ static void md_sqlite_copy_db(struct md_writer_sqlite *mws, uint8_t from_timeout
112112 num_failed ++ ;
113113 }
114114
115- //todo: copy db
115+ if (mws -> num_system_events ) {
116+ retval = md_inventory_system_copy_db (mws );
117+
118+ if (retval == RETVAL_FAILURE )
119+ num_failed ++ ;
120+ }
116121
117122 if (num_failed != 0 ) {
118123 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "%u DB dump(s) failed\n" , num_failed );
@@ -279,7 +284,7 @@ static sqlite3* md_sqlite_configure_db(struct md_writer_sqlite *mws, const char
279284}
280285
281286static int md_sqlite_configure (struct md_writer_sqlite * mws ,
282- const char * db_filename , uint32_t node_id , const char * nodeid_file , uint32_t db_interval ,
287+ const char * db_filename , uint32_t node_id , uint32_t db_interval ,
283288 uint32_t db_events , const char * meta_prefix , const char * gps_prefix ,
284289 const char * monitor_prefix , const char * usage_prefix ,
285290 const char * system_prefix )
@@ -295,7 +300,7 @@ static int md_sqlite_configure(struct md_writer_sqlite *mws,
295300 mws -> node_id = node_id ;
296301 } else {
297302#ifdef MONROE
298- mws -> node_id = system_helpers_get_nodeid (nodeid_file );
303+ mws -> node_id = system_helpers_get_nodeid (mws -> node_id_file );
299304#endif
300305 }
301306
@@ -427,7 +432,8 @@ static int md_sqlite_configure(struct md_writer_sqlite *mws,
427432 }
428433
429434 if (mws -> node_id && (md_sqlite_update_nodeid_db (mws , UPDATE_EVENT_ID ) ||
430- md_sqlite_update_nodeid_db (mws , UPDATE_UPDATES_ID ))) {
435+ md_sqlite_update_nodeid_db (mws , UPDATE_UPDATES_ID ) ||
436+ md_sqlite_update_nodeid_db (mws , UPDATE_SYSTEM_ID ))) {
431437 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "Could not update old ements with id 0\n" );
432438 return RETVAL_FAILURE ;
433439 }
@@ -468,7 +474,7 @@ int32_t md_sqlite_init(void *ptr, json_object* config)
468474 struct md_writer_sqlite * mws = ptr ;
469475 uint32_t node_id = 0 , interval = DEFAULT_TIMEOUT , num_events = EVENT_LIMIT ;
470476 const char * db_filename = NULL , * meta_prefix = NULL , * gps_prefix = NULL ,
471- * monitor_prefix = NULL , * nodeid_file = NULL , * usage_prefix = NULL ,
477+ * monitor_prefix = NULL , * usage_prefix = NULL ,
472478 * output_format = NULL , * system_prefix = NULL ;
473479
474480 json_object * subconfig ;
@@ -479,7 +485,7 @@ int32_t md_sqlite_init(void *ptr, json_object* config)
479485 else if (!strcmp (key , "nodeid" ))
480486 node_id = (uint32_t ) json_object_get_int (val );
481487 else if (!strcmp (key , "nodeid_file" ))
482- nodeid_file = json_object_get_string (val );
488+ mws -> node_id_file = strdup ( json_object_get_string (val ) );
483489 else if (!strcmp (key , "meta_prefix" ))
484490 meta_prefix = json_object_get_string (val );
485491 else if (!strcmp (key , "gps_prefix" ))
@@ -547,7 +553,7 @@ int32_t md_sqlite_init(void *ptr, json_object* config)
547553
548554 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "Done configuring SQLite handle\n" );
549555
550- return md_sqlite_configure (mws , db_filename , node_id , nodeid_file , interval ,
556+ return md_sqlite_configure (mws , db_filename , node_id , interval ,
551557 num_events , meta_prefix , gps_prefix , monitor_prefix , usage_prefix ,
552558 system_prefix );
553559}
@@ -571,6 +577,8 @@ static uint8_t md_sqlite_check_valid_tstamp(struct md_writer_sqlite *mws)
571577 if (md_sqlite_update_timestamp_db (mws , UPDATE_EVENT_TSTAMP ,
572578 real_boot_time ) ||
573579 md_sqlite_update_timestamp_db (mws , UPDATE_UPDATES_TSTAMP ,
580+ real_boot_time ) ||
581+ md_sqlite_update_timestamp_db (mws , UPDATE_SYSTEM_TSTAMP ,
574582 real_boot_time )) {
575583 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "Could not update tstamp in database\n" );
576584 return RETVAL_FAILURE ;
@@ -591,7 +599,8 @@ static uint8_t md_sqlite_check_session_id(struct md_writer_sqlite *mws)
591599 }
592600
593601 if (md_sqlite_update_session_id_db (mws , UPDATE_EVENT_SESSION_ID ) ||
594- md_sqlite_update_session_id_db (mws , UPDATE_UPDATES_SESSION_ID )) {
602+ md_sqlite_update_session_id_db (mws , UPDATE_UPDATES_SESSION_ID ) ||
603+ md_sqlite_update_session_id_db (mws , UPDATE_SYSTEM_SESSION_ID )) {
595604 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "Could not update session id in database\n" );
596605 mws -> timeout_handle -> intvl = DEFAULT_TIMEOUT ;
597606 mws -> session_id = 0 ;
@@ -704,10 +713,12 @@ static void md_sqlite_handle_timeout(void *ptr)
704713 if (!mws -> node_id ) {
705714#ifdef OPENWRT
706715 mws -> node_id = system_helpers_get_nodeid ();
707-
708- if (mws -> node_id )
709- META_PRINT_SYSLOG (mws -> parent , LOG_INFO , "Got nodeid %d\n" , mws -> node_id );
716+ #else
717+ mws -> node_id = system_helpers_get_nodeid (mws -> node_id_file );
710718#endif
719+ if (mws -> node_id ) {
720+ META_PRINT_SYSLOG (mws -> parent , LOG_INFO , "Got nodeid %d\n" , mws -> node_id );
721+ }
711722
712723 if (!mws -> node_id ) {
713724 META_PRINT_SYSLOG (mws -> parent , LOG_INFO , "No node id found\n" );
@@ -716,7 +727,8 @@ static void md_sqlite_handle_timeout(void *ptr)
716727 }
717728
718729 if (md_sqlite_update_nodeid_db (mws , UPDATE_EVENT_ID ) ||
719- md_sqlite_update_nodeid_db (mws , UPDATE_UPDATES_ID )) {
730+ md_sqlite_update_nodeid_db (mws , UPDATE_UPDATES_ID ) ||
731+ md_sqlite_update_nodeid_db (mws , UPDATE_SYSTEM_ID )) {
720732 META_PRINT_SYSLOG (mws -> parent , LOG_ERR , "Could not update node id in database\n" );
721733
722734 mws -> timeout_handle -> intvl = DEFAULT_TIMEOUT ;
0 commit comments