#include <ctype.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/file.h>
#include <glib.h>
#include <system_info.h>
return SYSTEM_INFO_ERROR_IO_ERROR;
}
+ /* flock for writable database */
+ if (strncmp(db_path, SYSTEM_INFO_DB_RW_PATH, strlen(db_path) + 1) == 0) {
+ if (flock(fileno(fp), LOCK_SH) < 0)
+ _E("Failed to acquire shared flock, %m");
+ }
+
key_internal_len = strlen(key_internal);
while ((temp = fgets(buf, sizeof(buf), fp))) {
if (!strncmp(buf, key_internal, key_internal_len) && buf[key_internal_len] == ' ') {
else
snprintf(key_internal, sizeof(key_internal), "%s:%s:%s", tag_s, key, type);
+ /* user-defined feature (by system-info-tool) takes top priority */
+ ret = db_search_value(SYSTEM_INFO_DB_RW_PATH, key_internal, value, len);
+ if (ret == SYSTEM_INFO_ERROR_NONE)
+ return ret;
+
pthread_mutex_lock(&fmutex);
if (!hashtable) {
hashtable = g_hash_table_new_full(g_str_hash, g_str_equal, destroy_key_value, destroy_key_value);
}
}
- if (access(SYSTEM_INFO_DB_RW_PATH, R_OK) == 0) {
- ret = db_search_value(SYSTEM_INFO_DB_RW_PATH, key_internal, value, len);
- } else {
- int retval1;
- int retval2;
- char *buffer1;
- char *buffer2;
-
- buffer1 = (char *) calloc(len, sizeof(char));
- buffer2 = (char *) calloc(len, sizeof(char));
- if (!buffer1 || !buffer2) {
- free(buffer1);
- free(buffer2);
- pthread_mutex_unlock(&fmutex);
- return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
- }
-
- retval1 = db_search_value(SYSTEM_INFO_DB_RO_PATH, key_internal, buffer1, len);
- retval2 = db_search_value(SYSTEM_INFO_HAL_DB_RO_PATH, key_internal, buffer2, len);
-
- if (retval1 == SYSTEM_INFO_ERROR_NONE && retval2 == SYSTEM_INFO_ERROR_NONE) {
- ret = db_join_value(buffer1, buffer2, type, value, len);
- } else if (retval1 == SYSTEM_INFO_ERROR_NONE) {
- ret = SYSTEM_INFO_ERROR_NONE;
- strncpy(value, buffer1, len);
- } else if (retval2 == SYSTEM_INFO_ERROR_NONE) {
- ret = SYSTEM_INFO_ERROR_NONE;
- strncpy(value, buffer2, len);
- } else {
- ret = SYSTEM_INFO_ERROR_IO_ERROR;
- }
+ int retval1;
+ int retval2;
+ char *buffer1;
+ char *buffer2;
+ buffer1 = (char *) calloc(len, sizeof(char));
+ buffer2 = (char *) calloc(len, sizeof(char));
+ if (!buffer1 || !buffer2) {
free(buffer1);
free(buffer2);
+ pthread_mutex_unlock(&fmutex);
+ return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ retval1 = db_search_value(SYSTEM_INFO_DB_RO_PATH, key_internal, buffer1, len);
+ retval2 = db_search_value(SYSTEM_INFO_HAL_DB_RO_PATH, key_internal, buffer2, len);
+
+ if (retval1 == SYSTEM_INFO_ERROR_NONE && retval2 == SYSTEM_INFO_ERROR_NONE) {
+ ret = db_join_value(buffer1, buffer2, type, value, len);
+ } else if (retval1 == SYSTEM_INFO_ERROR_NONE) {
+ ret = SYSTEM_INFO_ERROR_NONE;
+ strncpy(value, buffer1, len);
+ } else if (retval2 == SYSTEM_INFO_ERROR_NONE) {
+ ret = SYSTEM_INFO_ERROR_NONE;
+ strncpy(value, buffer2, len);
+ } else {
+ ret = SYSTEM_INFO_ERROR_IO_ERROR;
}
+ free(buffer1);
+ free(buffer2);
+
if (ret == SYSTEM_INFO_ERROR_NONE)
g_hash_table_insert(hashtable, strdup(key_internal), strdup(value));