Przeglądaj źródła

presence: convert module to use DB_TABLE_VERSION_ERROR helper

- convert module to use DB_TABLE_VERSION_ERROR helper
- unify error handling (properly close database on errors, null db handle)
Henning Westerholt 6 lat temu
rodzic
commit
ac2aa9a183
1 zmienionych plików z 15 dodań i 10 usunięć
  1. 15 10
      src/modules/presence/presence.c

+ 15 - 10
src/modules/presence/presence.c

@@ -363,14 +363,14 @@ static int mod_init(void)
 	/*verify table versions */
 	/*verify table versions */
 	if((db_check_table_version(&pa_dbf, pa_db, &presentity_table, P_TABLE_VERSION) < 0) ||
 	if((db_check_table_version(&pa_dbf, pa_db, &presentity_table, P_TABLE_VERSION) < 0) ||
 			(db_check_table_version(&pa_dbf, pa_db, &watchers_table, S_TABLE_VERSION) < 0)) {
 			(db_check_table_version(&pa_dbf, pa_db, &watchers_table, S_TABLE_VERSION) < 0)) {
-		LM_ERR("error during table version check\n");
-		return -1;
+		DB_TABLE_VERSION_ERROR(presentity_table);
+		goto dberror;
 	}
 	}
 
 
 	if(subs_dbmode != NO_DB &&
 	if(subs_dbmode != NO_DB &&
 			db_check_table_version(&pa_dbf, pa_db, &active_watchers_table, ACTWATCH_TABLE_VERSION) < 0) {
 			db_check_table_version(&pa_dbf, pa_db, &active_watchers_table, ACTWATCH_TABLE_VERSION) < 0) {
-		LM_ERR("wrong table version for %s\n", active_watchers_table.s);
-		return -1;
+		DB_TABLE_VERSION_ERROR(active_watchers_table);
+		goto dberror;
 	}
 	}
 
 
 	if(subs_dbmode != DB_ONLY) {
 	if(subs_dbmode != DB_ONLY) {
@@ -383,12 +383,12 @@ static int mod_init(void)
 		if(subs_htable== NULL)
 		if(subs_htable== NULL)
 		{
 		{
 			LM_ERR(" initializing subscribe hash table\n");
 			LM_ERR(" initializing subscribe hash table\n");
-			return -1;
+			goto dberror;
 		}
 		}
 		if(restore_db_subs()< 0)
 		if(restore_db_subs()< 0)
 		{
 		{
 			LM_ERR("restoring subscribe info from database\n");
 			LM_ERR("restoring subscribe info from database\n");
-			return -1;
+			goto dberror;
 		}
 		}
 	}
 	}
 
 
@@ -402,13 +402,13 @@ static int mod_init(void)
 		if(pres_htable== NULL)
 		if(pres_htable== NULL)
 		{
 		{
 			LM_ERR("initializing presentity hash table\n");
 			LM_ERR("initializing presentity hash table\n");
-			return -1;
+			goto dberror;
 		}
 		}
 
 
 		if(pres_htable_restore()< 0)
 		if(pres_htable_restore()< 0)
 		{
 		{
 			LM_ERR("filling in presentity hash table from database\n");
 			LM_ERR("filling in presentity hash table from database\n");
-			return -1;
+			goto dberror;
 		}
 		}
 	}
 	}
 
 
@@ -436,7 +436,7 @@ static int mod_init(void)
 		if ((pres_notifier_id = shm_malloc(sizeof(int) * pres_notifier_processes)) == NULL)
 		if ((pres_notifier_id = shm_malloc(sizeof(int) * pres_notifier_processes)) == NULL)
 		{
 		{
 			LM_ERR("allocating shared memory\n");
 			LM_ERR("allocating shared memory\n");
-			return -1;
+			goto dberror;
 		}
 		}
 
 
 		register_basic_timers(pres_notifier_processes);
 		register_basic_timers(pres_notifier_processes);
@@ -453,7 +453,7 @@ static int mod_init(void)
 		}
 		}
 		else {
 		else {
 			LM_ERR("invalid log facility configured\n");
 			LM_ERR("invalid log facility configured\n");
-			return -1;
+			goto dberror;
 		}
 		}
 	}
 	}
 	else {
 	else {
@@ -476,6 +476,11 @@ static int mod_init(void)
 	}
 	}
 
 
 	return 0;
 	return 0;
+
+dberror:
+	pa_dbf.close(pa_db);
+	pa_db = NULL;
+	return -1;
 }
 }
 
 
 /**
 /**