Add code for checking integrity 76/161076/3
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 21 Nov 2017 09:20:36 +0000 (18:20 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Wed, 22 Nov 2017 05:07:44 +0000 (14:07 +0900)
Change-Id: I48277013b5f1efe59e123efe909b926cface677d
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
alarm-manager.c

index b1b29ed7da902870754d9a3adf13277b366beeff..551a18226cc44fae6cf9ab26ee10f3c2665be7e8 100644 (file)
@@ -123,6 +123,7 @@ bool is_time_changed = false; /* for calculating next duetime */
 
 #define BILLION 1000000000 /* for calculating nano seconds */
 static time_t periodic_alarm_standard_time = 0;
+static bool is_db_corrupted = false;
 
 static int __is_ui_app(const char *appid, uid_t uid);
 static long __get_proper_interval(long interval, int alarm_type);
@@ -3995,6 +3996,19 @@ static int __db_busyhandler(void *pData, int count)
        }
 }
 
+int check_callback(void *pid, int argc, char **argv, char **notUsed2)
+{
+       if (strcmp(argv[0], "ok") != 0) {
+               ALARM_MGR_EXCEPTION_PRINT("check integrity result : %s" , argv[0]);
+               is_db_corrupted = true;
+               return -1;
+       } else {
+               ALARM_MGR_LOG_PRINT("check integrity result : %s" , argv[0]);
+       }
+
+       return 0;
+}
+
 static bool __initialize_db()
 {
        char *error_message = NULL;
@@ -4033,6 +4047,13 @@ static bool __initialize_db()
                }
        }
 
+       /* Check integrity of DB */
+       ret = sqlite3_exec(alarmmgr_db, "PRAGMA integrity_check", check_callback, NULL, 0);
+       if (ret != SQLITE_OK || is_db_corrupted) {
+               ALARM_MGR_EXCEPTION_PRINT("Loss alarm db's integrity");
+               goto recover;
+       }
+
        return true;
 
 recover: