if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
goto err;
}
- if (sqlite3_open_v2(parser_db, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) {
+ if (__open_db(parser_db, &db, SQLITE_OPEN_READONLY) != SQLITE_OK) {
_LOGE("DB open fail\n");
free(parser_db);
goto err;
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
free(dbpath);
if (dbpath == NULL)
return PMINFO_R_ERROR;
- ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
+ ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
if (ret != SQLITE_OK) {
_LOGD("failed to open db: %d", ret);
free(dbpath);
return PMINFO_R_OK;
}
+#define BUSY_WAITING_USEC (1000000 / 10 / 2) /* 0.05 sec */
+#define BUSY_WAITING_MAX 20 /* wait for max 1 sec */
+static int __db_busy_handler(void *data, int count)
+{
+ if (count < BUSY_WAITING_MAX) {
+ usleep(BUSY_WAITING_USEC);
+ return 1;
+ } else {
+ /* sqlite3_prepare_v2 will return SQLITE_BUSY */
+ return 0;
+ }
+}
+
+int __open_db(const char *path, sqlite3 **db, int flags)
+{
+ int ret;
+
+ ret = sqlite3_open_v2(path, db, flags, NULL);
+ if (ret != SQLITE_OK)
+ return ret;
+
+ ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
+ if (ret != SQLITE_OK) {
+ _LOGE("failed to register busy handler: %s",
+ sqlite3_errmsg(*db));
+ sqlite3_close_v2(*db);
+ return ret;
+ }
+
+ return ret;
+}
int _add_label_info_into_list(const char *locale, char *value, GList **label);
int __pkginfo_check_installed_storage(package_x *pkginfo);
int __appinfo_check_installed_storage(application_x *appinfo);
+int __open_db(const char *path, sqlite3 **db, int flags);
#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
#define REGULAR_USER 5000