init_db: add system_info_db parameter for make new db by another path 10/169910/2 accepted/tizen/4.0/unified/20180328.140008 submit/tizen_4.0/20180323.050904
authorDonghwan Jeong <dh.jeong@samsung.com>
Mon, 12 Feb 2018 05:31:41 +0000 (14:31 +0900)
committerDonghwan Jeong <dh.jeong@samsung.com>
Fri, 23 Mar 2018 02:18:26 +0000 (11:18 +0900)
It will be supported that the content can be chagned in system info at run-time.
So, system_info_db can make new system-info-db file by another path.

system_info_init_db -i --input=PATH   Make System info db by the PATH
ex) system_info_init_db -i /etc/config/model-config.xml

The new db file will be saved to '/opt/system/model_conf/system_info_db' path

Change-Id: I2ddde7e313ff5cc547b3592109fe1cf29ddbdd7b
Signed-off-by: Donghwan Jeong <dh.jeong@samsung.com>
CMakeLists.txt
packaging/capi-system-info.spec
src/init_db/system_info_db_init.c
src/system_info.c

index caef066dc4f9c01b47b8b6bd73cf753d48c96d8a..c6695c084611381e4dcf48adeb748a9e4b32d7d6 100644 (file)
@@ -32,6 +32,7 @@ ADD_DEFINITIONS("-DINFO_FILE_PATH=\"${INFO_FILE_PATH}\"")
 ADD_DEFINITIONS("-DTIZEN_ID_PATH=\"${TIZEN_ID_PATH}\"")
 ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"")
 ADD_DEFINITIONS("-DSYSTEM_INFO_DB_PATH=\"${DB_PATH}\"")
+ADD_DEFINITIONS("-DSYSTEM_INFO_DB_RUNTIME_PATH=\"${DB_RUNTIME_PATH}\"")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib")
 
index 7ec6d3704f697b84f992909063a68befabd57532..18ff38cad6f20022f503972bca945b17ceebbdd5 100644 (file)
@@ -38,6 +38,8 @@ cp %{SOURCE1001} .
 %define sysinfo_shared_path %{TZ_SYS_ETC}/sysinfo
 %define tizen_id_path %{sysinfo_shared_path}/tizenid
 %define db_path %{TZ_SYS_RO_ETC}/system_info_db
+%define model_config_path /opt/system/model-config
+%define db_runtime_path %{model_config_path}/system_info_db
 
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
@@ -47,7 +49,8 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
             -DMAJORVER=${MAJORVER} \
             -DFULLVER=%{version} \
             -DTIZEN_ID_PATH=%{tizen_id_path} \
-            -DDB_PATH=%{db_path}
+            -DDB_PATH=%{db_path} \
+            -DDB_RUNTIME_PATH=%{db_runtime_path}
 
 %__make %{?_smp_mflags}
 
@@ -59,9 +62,11 @@ cp -f script/make_info_file.sh %{buildroot}/etc/make_info_file.sh
 %install_service sysinit.target.wants tizenid.service
 
 mkdir -p %{buildroot}/%{sysinfo_shared_path}
+mkdir -p %{buildroot}/%{model_config_path}
 
 %posttrans
 /usr/bin/chsmack -a "System::Shared" -t %{sysinfo_shared_path}
+/usr/bin/chsmack -a "System::Shared" -t %{model_config_path}
 /usr/bin/system_info_init_db
 /sbin/ldconfig
 
@@ -74,6 +79,7 @@ mkdir -p %{buildroot}/%{sysinfo_shared_path}
 %attr(0744,root,-) /etc/make_info_file.sh
 %{_bindir}/system_info_init_db
 
+%attr(0664,root,system_share) %dir %{model_config_path}
 #tizenid
 %attr(0775,root,system_share) %dir %{sysinfo_shared_path}
 %{_bindir}/tizen_id
index 06ae5f38636459bd0c0e949fe8cfa058bee99da9..b7b68922204943059dd3419afe620a881180b5ec 100644 (file)
@@ -160,7 +160,7 @@ static int db_set_value_foreach_runtime(GDBM_FILE *db, xmlNode *node,
        return ret;
 }
 
-static int system_info_get_values_config_xml(GDBM_FILE *db)
+static int system_info_get_values_config_xml(GDBM_FILE *db, const char *path)
 {
        xmlDocPtr doc;
        xmlNodePtr cur;
@@ -171,15 +171,15 @@ static int system_info_get_values_config_xml(GDBM_FILE *db)
        if (!db || !*db)
                return -EINVAL;
 
-       doc = xmlParseFile(CONFIG_FILE_PATH);
+       doc = xmlParseFile(path);
        if (!doc) {
-               _E("cannot file open %s file!!!", CONFIG_FILE_PATH);
+               _E("cannot file open %s file!!!", path);
                return SYSTEM_INFO_ERROR_IO_ERROR;
        }
 
        cur = xmlDocGetRootElement(doc);
        if (!cur) {
-               _E("empty document %s file!!!", CONFIG_FILE_PATH);
+               _E("empty document %s file!!!", path);
                ret = -ENOENT;
                goto out;
        }
@@ -293,18 +293,24 @@ static int system_info_get_values_ini(GDBM_FILE *db)
        return 0;
 }
 
-static int system_info_create_db(void)
+static int system_info_create_db(const char *conf_path, char *db_path)
 {
        int ret;
        GDBM_FILE db;
 
-       db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_WRCREAT, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+       if (conf_path == NULL)
+               conf_path = CONFIG_FILE_PATH;
+
+       if (db_path == NULL)
+               db_path = SYSTEM_INFO_DB_PATH;
+
+       db = gdbm_open(db_path, 0, GDBM_WRCREAT, S_IRUSR | S_IRGRP | S_IROTH, NULL);
        if (!db) {
                _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno));
                return -ENOENT;
        }
 
-       ret = system_info_get_values_config_xml(&db);
+       ret = system_info_get_values_config_xml(&db, conf_path);
        if (ret < 0)
                _E("Failed to get keys and values from xml(%d)", ret);
 
@@ -327,6 +333,8 @@ static void show_help(void)
        printf("  -l --lang=LANG    System info specific language target (capi/webapi/csapi)\n");
        printf("  -g --tag=TAG      System info tag to update (platform/custom)\n");
        printf("  -v --value=VALUE  System info value to update\n");
+       printf("  -i --input=PATH   System info get input argument from several source\n");
+       printf("  -o --output=PATH  System info get output argument from several source\n");
 }
 
 static int system_info_update_db(int argc, char *argv[])
@@ -340,6 +348,8 @@ static int system_info_update_db(int argc, char *argv[])
        char tag[KEY_MAX] = {0};
        char value[KEY_MAX] = {0};
        char value_bool[LANG_MAX] = {0};
+       char conf_path[KEY_MAX] = {0};
+       char db_path[KEY_MAX] = {0};
        enum language lang = LANG_MAX;
        int rt;
 
@@ -348,12 +358,14 @@ static int system_info_update_db(int argc, char *argv[])
                { "type",  required_argument, 0, 0 },
                { "tag",   required_argument, 0, 0 },
                { "value", required_argument, 0, 0 },
+               { "input", required_argument, 0, 0 },
+               { "output", required_argument, 0, 0 },
                { "help",  no_argument,       0, 0 },
                { 0,       0,                 0, 0 },
        };
 
        while (1) {
-               opt = getopt_long(argc, argv, "k:t:g:v:l:h",
+               opt = getopt_long(argc, argv, "k:t:g:v:l:i:o:h",
                                long_options, NULL);
                if (opt < 0)
                        break;
@@ -370,6 +382,12 @@ static int system_info_update_db(int argc, char *argv[])
                case 'v':
                        snprintf(value, sizeof(value), "%s", optarg);
                        break;
+               case 'i':
+                       snprintf(conf_path, sizeof(conf_path), "%s", optarg);
+                       break;
+               case 'o':
+                       snprintf(db_path, sizeof(db_path), "%s", optarg);
+                       break;
                case 'l':
                        for (rt = 0; rt < LANG_MAX; rt++) {
                                if (!runtime[rt].xml_prop)
@@ -391,6 +409,11 @@ static int system_info_update_db(int argc, char *argv[])
                }
        }
 
+       if (conf_path[0] != '\0' && db_path[0] != '\0') {
+               printf("Make system info db(%s) by %s\n", db_path, conf_path);
+               return system_info_create_db(conf_path, db_path);
+       }
+
        failed = false;
        if (key[0] == '\0') {
                printf("Invalid Parameter: no key\n");
@@ -452,7 +475,7 @@ static int system_info_update_db(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
        if (argc == 1)
-               return system_info_create_db();
+               return system_info_create_db(NULL, NULL);
 
        return system_info_update_db(argc, argv);
 }
index f89f9067991eb2187e3c67b34c28bd9110cac574..cb90d1cec8c5ae0ea19af2bde341da5b8f1320b0 100644 (file)
@@ -43,6 +43,8 @@ extern const struct runtime runtime[LANG_MAX];
 GHashTable *hashtable = NULL;
 static pthread_mutex_t fmutex = PTHREAD_MUTEX_INITIALIZER;
 
+static char *system_info_db_path;
+
 enum tag_type {
        TAG_TYPE_PLATFORM,
        TAG_TYPE_CUSTOM,
@@ -78,6 +80,7 @@ static void destroy_key_value(gpointer data)
 static int db_get_value(enum tag_type tag, const char *key,
                const char *type, char *value, size_t len)
 {
+       char *db_path;
        char key_internal[KEY_MAX];
        GDBM_FILE db = NULL;
        datum d_key;
@@ -118,7 +121,12 @@ static int db_get_value(enum tag_type tag, const char *key,
                }
        }
 
-       db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+       if (access(SYSTEM_INFO_DB_RUNTIME_PATH, R_OK) == 0)
+               db_path = SYSTEM_INFO_DB_RUNTIME_PATH;
+       else
+               db_path = SYSTEM_INFO_DB_PATH;
+
+       db = gdbm_open(db_path, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
        if (!db) {
                _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno)); //LCOV_EXCL_LINE
                pthread_mutex_unlock(&fmutex);
@@ -214,7 +222,14 @@ static int system_info_get_type(enum tag_type tag, const char *key,
                }
        }
 
-       db = gdbm_open(SYSTEM_INFO_DB_PATH, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
+       if (!system_info_db_path) {
+               if (access(SYSTEM_INFO_DB_RUNTIME_PATH, R_OK) == 0)
+                       system_info_db_path = SYSTEM_INFO_DB_RUNTIME_PATH;
+               else
+                       system_info_db_path = SYSTEM_INFO_DB_PATH;
+       }
+
+       db = gdbm_open(system_info_db_path, 0, GDBM_READER, S_IRUSR | S_IRGRP | S_IROTH, NULL);
        if (!db) {
                _E("Failed to open db (%d, %s)", gdbm_errno, gdbm_strerror(gdbm_errno)); //LCOV_EXCL_LINE
                pthread_mutex_unlock(&fmutex);