Modify vconf_migration tool 98/137198/2
authorJiwoong Im <jiwoong.im@samsung.com>
Tue, 13 Jun 2017 07:45:15 +0000 (16:45 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Thu, 6 Jul 2017 10:49:34 +0000 (19:49 +0900)
- Instead of using vconf api, insert 2.4 vconf data directly to buxton db.

Change-Id: I473243468feb4f8238e336a772db52b0a19fdbed
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
migration/CMakeLists.txt
migration/vconf_migration.c
packaging/buxton2.spec
scripts/299.buxton2_upgrade.sh [moved from scripts/500.buxton2_upgrade.sh with 87% similarity]

index d7da168..269b714 100644 (file)
@@ -1,20 +1,19 @@
 # migration tool build
-
-PKG_CHECK_MODULES(V_PKGS REQUIRED vconf-internal-keys)
-
-FOREACH(flag ${V_PKGS_CFLAGS})
-       SET(VCONF_CFLAGS "${VCONF_CFLAGS} ${flag}")
-ENDFOREACH()
-SET(VCONF_CFLAGS "-fvisibility=hidden ${VCONF_CFLAGS}")
-
-
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/vconf-compat)
 
-ADD_EXECUTABLE(vconf_migration vconf_migration.c)
-TARGET_LINK_LIBRARIES(vconf_migration vconf)
-SET_TARGET_PROPERTIES(vconf_migration PROPERTIES
-       COMPILE_FLAGS ${VCONF_CFLAGS}
+SET(SRC
+       vconf_migration.c
+       ../common/common.c
+       ../common/direct.c
+       ../common/backends.c
+       ../common/config.c
+       ../common/serialize.c
+       ../common/cache.c
 )
 
+ADD_EXECUTABLE(vconf_migration ${SRC})
+SET_TARGET_PROPERTIES(vconf_migration PROPERTIES
+       LINK_FLAGS "-fPIE"
+)
+TARGET_LINK_LIBRARIES(vconf_migration vconf buxton2 -ldl)
 INSTALL(TARGETS vconf_migration DESTINATION bin)
index 3632a78..9f80102 100644 (file)
 #include <dirent.h>
 #include <inttypes.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <glib.h>
-#include <vconf.h>
+
+#include "direct.h"
+#include "common.h"
 
 #define BUF_LEN 1024
 
-static void _get_vconf_keys(const char *path, keylist_t *keylist)
+enum vconf_t {
+       VCONF_TYPE_NONE = 0,    /**< Vconf none type for Error detection */
+       VCONF_TYPE_STRING = 40, /**< Vconf string type */
+       VCONF_TYPE_INT = 41,    /**< Vconf integer type */
+       VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */
+       VCONF_TYPE_BOOL = 43,   /**< Vconf boolean type */
+       VCONF_TYPE_DIR          /**< Vconf directory type */
+};
+
+struct buxton_layer *system_layer;
+
+static void _set_vconf_key(const char *path)
 {
        int type = 0;
        FILE *fp = NULL;
@@ -39,14 +53,14 @@ static void _get_vconf_keys(const char *path, keylist_t *keylist)
 
        fp = fopen(path, "r+");
        if (fp == NULL) {
-               fprintf(stderr, "unable to open key path[%s] : %d", path, errno);
+               fprintf(stderr, "unable to open key path[%s] : %d\n", path, errno);
                return;
        }
 
        read_size = fread((void *)&type, sizeof(int), 1, fp);
        if ((read_size <= 0) || (read_size > sizeof(int))) {
                if (!ferror(fp)) {
-                       fprintf(stderr, "number of read items for type is 0 with false ferror. err : %d", errno);
+                       fprintf(stderr, "number of read items for type is 0 with false ferror. err : %d\n", errno);
                        errno = ENODATA;
                }
                goto out_func;
@@ -75,10 +89,13 @@ static void _get_vconf_keys(const char *path, keylist_t *keylist)
                        read_size = fread((void *)&value_int, sizeof(int), 1, fp);
                        if ((read_size <= 0) || (read_size > sizeof(int))) {
                                if (!ferror(fp))
-                                       fprintf(stderr, "number of read items for value is wrong. err : %d", errno);
+                                       fprintf(stderr, "number of read items for value is wrong. err : %d\n", errno);
                                goto out_func;
                        } else {
-                               vconf_keylist_add_int(keylist, keyname, value_int);
+                               struct buxton_value *v;
+                               v = buxton_value_create_int32(value_int);
+                               direct_set(system_layer, keyname, v);
+                               buxton_value_free(v);
                        }
 
                        break;
@@ -89,10 +106,13 @@ static void _get_vconf_keys(const char *path, keylist_t *keylist)
                        read_size = fread((void *)&value_dbl, sizeof(double), 1, fp);
                        if ((read_size <= 0) || (read_size > sizeof(double))) {
                                if (!ferror(fp))
-                                       fprintf(stderr, "number of read items for value is wrong. err : %d", errno);
+                                       fprintf(stderr, "number of read items for value is wrong. err : %d\n", errno);
                                goto out_func;
                        } else {
-                               vconf_keylist_add_dbl(keylist, keyname, value_dbl);
+                               struct buxton_value *v;
+                               v = buxton_value_create_double(value_dbl);
+                               direct_set(system_layer, keyname, v);
+                               buxton_value_free(v);
                        }
 
                        break;
@@ -103,10 +123,13 @@ static void _get_vconf_keys(const char *path, keylist_t *keylist)
                        read_size = fread((void *)&value_int, sizeof(int), 1, fp);
                        if ((read_size <= 0) || (read_size > sizeof(int))) {
                                if (!ferror(fp))
-                                       fprintf(stderr, "number of read items for value is wrong. err : %d", errno);
+                                       fprintf(stderr, "number of read items for value is wrong. err : %d\n", errno);
                                goto out_func;
                        } else {
-                               vconf_keylist_add_bool(keylist, keyname, value_int);
+                               struct buxton_value *v;
+                               v = buxton_value_create_boolean(value_int);
+                               direct_set(system_layer, keyname, v);
+                               buxton_value_free(v);
                        }
 
                        break;
@@ -135,12 +158,15 @@ static void _get_vconf_keys(const char *path, keylist_t *keylist)
                        }
 
                        if (ferror(fp)) {
-                               fprintf(stderr, "fgets error for getting string key : %d", errno);
+                               fprintf(stderr, "fgets error for getting string key : %d\n", errno);
                        } else {
+                               struct buxton_value *v;
                                if (value)
-                                       vconf_keylist_add_str(keylist, keyname, value);
+                                       v = buxton_value_create_string(value);
                                else
-                                       vconf_keylist_add_str(keylist, keyname, "");
+                                       v = buxton_value_create_string("");
+                               direct_set(system_layer, keyname, v);
+                               buxton_value_free(v);
                        }
                        if (value)
                                free(value);
@@ -159,14 +185,11 @@ static int _load_vconf_dir(const char *directory)
        struct dirent file_info;
        struct dirent *result;
        char buf[BUF_LEN];
-       keylist_t *keylist;
 
        dir = opendir(directory);
        if (!dir)
                return -1;
 
-       keylist = vconf_keylist_new();
-
        while (readdir_r(dir, &file_info, &result) == 0) {
                if (result == NULL)
                        break;
@@ -176,12 +199,9 @@ static int _load_vconf_dir(const char *directory)
                snprintf(buf, sizeof(buf), "%s/%s", directory,
                                file_info.d_name);
 
-               _get_vconf_keys(buf, keylist);
+               _set_vconf_key(buf);
        }
 
-       vconf_set(keylist);
-
-       vconf_keylist_free(keylist);
        closedir(dir);
 
        return 0;
@@ -189,14 +209,18 @@ static int _load_vconf_dir(const char *directory)
 
 int main(int argc, char *argv[])
 {
+       direct_init(MODULE_DIR, CONFPATH);
+       system_layer = buxton_create_layer("system");
+       buxton_layer_set_type(system_layer, BUXTON_LAYER_NORMAL);
+
        if (_load_vconf_dir("/opt/var/kdb/db") < 0)
-               fprintf(stderr, "fail to migrate db backend keys : %d", errno);
+               fprintf(stderr, "fail to migrate db backend keys : %d\n", errno);
 
        if (_load_vconf_dir("/opt/var/kdb/file") < 0)
-               fprintf(stderr, "fail to migrate file backend keys : %d", errno);
+               fprintf(stderr, "fail to migrate file backend keys : %d\n", errno);
 
-       if (_load_vconf_dir("/opt/var/kdb/memory_init/memory") < 0)
-               fprintf(stderr, "fail to migrate memory backend keys : %d", errno);
+       buxton_free_layer(system_layer);
+       direct_exit();
 
        return EXIT_SUCCESS;
 }
index d92ebd7..04c79e1 100644 (file)
@@ -139,7 +139,7 @@ install -m 755 -d %{buildroot}%{_unitdir}/sockets.target.wants
 ln -sf ../%{name}.socket %{buildroot}%{_unitdir}/sockets.target.wants/
 
 mkdir -p %{buildroot}%{upgrade_script_path}
-cp -f scripts/500.buxton2_upgrade.sh %{buildroot}%{upgrade_script_path}
+cp -f scripts/299.buxton2_upgrade.sh %{buildroot}%{upgrade_script_path}
 
 %post
 /sbin/ldconfig
@@ -189,7 +189,7 @@ chsmack -a System %{dbdir}/*
 %{_unitdir}/sockets.target.wants/%{name}.socket
 %attr(0700,buxton,buxton) %dir %{_localstatedir}/lib/%{name}
 %attr(0700,buxton,buxton) %dir %{basedbdir}
-%attr(0750,root,root) %{upgrade_script_path}/500.buxton2_upgrade.sh
+%attr(0750,root,root) %{upgrade_script_path}/299.buxton2_upgrade.sh
 %attr(0750,root,root) %{_bindir}/vconf_migration
 
 %files devel
similarity index 87%
rename from scripts/500.buxton2_upgrade.sh
rename to scripts/299.buxton2_upgrade.sh
index b03c976..9daf128 100644 (file)
@@ -10,7 +10,6 @@ VCONF_KEY_PATH=/opt/var/kdb
 buxton2ctl security-disable
 
 mkdir -p $RW_DB_PATH
-chown -R buxton:buxton $RW_DB_PATH
 chmod 700 $RW_DB_PATH
 chsmack -a System $RW_DB_PATH
 chsmack -t $RW_DB_PATH
@@ -20,3 +19,7 @@ then
        vconf_migration
        rm -r $VCONF_KEY_PATH
 fi
+
+chown -R buxton:buxton $RW_DB_PATH
+chmod 0600 $RW_DB_PATH/*
+chsmack -a System $RW_DB_PATH/*