app initialization refactoring tizen_2.2 2.2.1_release submit/tizen_2.2/20131107.062028
authorYoung Ik Cho <youngik.cho@samsung.com>
Mon, 16 Sep 2013 09:27:57 +0000 (18:27 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Mon, 16 Sep 2013 09:27:57 +0000 (18:27 +0900)
Change-Id: Ie634aea0e7c3451788c5b00a0216229223cd435a
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
CMakeLists.txt
osp-service-app-loader/serviceapp_loader.c
osp-system-service-loader/systemservice_loader.c
osp-ui-app-loader/uiapp_loader.c
packaging/osp-loader.spec

index f2fea44..1de6d17 100644 (file)
@@ -6,6 +6,7 @@ INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs REQUIRED
        dlog
        appinfo
+       libprivilege-control
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
index 0ef9c53..f811216 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/capability.h>
 
 #include <dlog.h>
+#include <privilege-control.h>
 #include <appinfo.h>
 
 #undef LOG_TAG
@@ -57,35 +58,7 @@ print_args(int argc, char* argv[])
 static void
 adjust_privilege(const char* appid)
 {
-       void* handle = dlopen("libprivilege-control.so.0", RTLD_LAZY | RTLD_LOCAL);
-       if (!handle)
-       {
-               fprintf(stderr, "Cannot open libprivilege-control.so.0\n");
-               return;
-       }
-
-       char* msg = 0;
-       dlerror();
-
-       int (*ppriv_func)(const char*) = NULL;
-
-       ppriv_func = (int (*)(const char*))dlsym(handle, "set_privilege");
-       msg = dlerror();
-       if (msg != NULL)
-       {
-               fprintf(stderr, "Dlsym error: %s\n", msg);
-
-               dlclose(handle);
-               return;
-       }
-
-       int ret = (*ppriv_func)(appid);
-       if (ret < 0)
-       {
-               fprintf(stderr, "set_privilege() returned %d\n", ret);
-       }
-
-       dlclose(handle);
+       set_privilege(appid);
 }
 
 extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
@@ -132,8 +105,9 @@ adjust_capability(void)
 
        return 0;
 }
+
 static int
-osp_do_pre_exe(const char* bin_path)
+osp_do_pre_exe(const char* app_id, const char* bin_path)
 {
        int ret = 0;
        void* handle = NULL;
@@ -158,7 +132,7 @@ osp_do_pre_exe(const char* bin_path)
        }
        LOGI("dlsym() ok");
 
-       ret = do_pre_exec_fn(NULL, bin_path);
+       ret = do_pre_exec_fn(app_id, bin_path);
        if (ret < 0)
        {
                LOGE("Failed to do_pre_exe() (%d)", ret);
@@ -215,42 +189,50 @@ main(int argc, char* argv[])
 {
        void* real_handle = NULL;
        char* errormsg = 0;
-       char packageid[MAX_PACKAGEID + 1];
-       char executable_name[MAX_APP_EXECUTABLE_NAME];
-       char appid[MAX_APPID];
-
-       void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
-       int (*pRealMain)(int, char* []) = NULL;
-
-       memset(packageid, 0, sizeof(packageid));
-       memset(executable_name, 0, sizeof(executable_name));
-       memset(appid, 0, sizeof(appid));
+       const char* pid = NULL;
 
        LOGI("Initializing : argc %d, argv 0x%x.", argc, argv);
        //print_args(argc, argv);
 
-       // convert package path to package name
-       get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
-       snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+       if (appinfo_is_initialized() == 0)
+       {
+               // not initialized
+               char appid[MAX_APPID];
+               char packageid[MAX_PACKAGEID + 1];
+               char executable_name[MAX_APP_EXECUTABLE_NAME];
+
+               memset(appid, 0, sizeof(appid));
+               memset(packageid, 0, sizeof(packageid));
+               memset(executable_name, 0, sizeof(executable_name));
+
+               // convert package path to package name
+               get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
+               snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+
+               // initialize appid
+               appinfo_init(appid, 0);
+
+               LOGI("Non-preloading initialization done.");
+       }
+
+       pid = appinfo_get_appid();
 
 #ifdef _SECURE_LOG
-       LOGI("app is %s", appid);
+       LOGI("app is %s", pid);
 #endif
 
        if (getuid() == 0)
        {
                // self caging
-               osp_do_pre_exe(argv[0]);
+               osp_do_pre_exe(pid, argv[0]);
 
                // adjust privilege
-               adjust_privilege(appid);
+               adjust_privilege(pid);
        }
 
 
        adjust_capability();
 
-       // initialize appid
-       appinfo_init(appid, 0);
        appinfo_set_argv(argc, argv);
 
        // actual loading
@@ -266,7 +248,8 @@ main(int argc, char* argv[])
                return -1;
        }
 
-       pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(real_handle, "InitAppInfo");
+       void (*pAppInfoInit)() = NULL;
+       pAppInfoInit = (void (*)()) dlsym(real_handle, "AppInfo_Update");
        errormsg = dlerror();
        if (errormsg != NULL)
        {
@@ -276,6 +259,7 @@ main(int argc, char* argv[])
                return -1;
        }
 
+       int (*pRealMain)(int, char* []) = NULL;
        pRealMain = (int (*)(int, char*[])) dlsym(real_handle, "OspMain");
        errormsg = dlerror();
        if (errormsg != NULL)
@@ -286,7 +270,7 @@ main(int argc, char* argv[])
        }
 
        // actual initialization
-       (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+       (*pAppInfoInit)();
        (*pRealMain)(argc, argv);
 
        LOGI("Osp application terminates.");
index 5d08a48..c39d36b 100644 (file)
@@ -140,7 +140,6 @@ main(int argc, char* argv[])
        char executable_name[MAX_APP_EXECUTABLE_NAME];
        char appid[MAX_APPID];
 
-       void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
        int (*pRealMain)(int, char* []) = NULL;
 
        memset(packageid, 0, sizeof(packageid));
@@ -184,7 +183,8 @@ main(int argc, char* argv[])
                return -1;
        }
 
-       pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(real_handle, "InitAppInfo");
+       void (*pAppInfoInit)() = NULL;
+       pAppInfoInit = (void (*)()) dlsym(real_handle, "AppInfo_Update");
        errormsg = dlerror();
        if (errormsg != NULL)
        {
@@ -204,7 +204,7 @@ main(int argc, char* argv[])
        }
 
        // actual initialization
-       (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+       (*pAppInfoInit)();
        (*pRealMain)(argc, argv);
 
        LOGI("Osp application terminates.");
index 28650b3..85bda97 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/capability.h>
 
 #include <dlog.h>
+#include <privilege-control.h>
 #include <appinfo.h>
 
 #undef LOG_TAG
@@ -60,35 +61,7 @@ print_args(int argc, char* argv[])
 static void
 adjust_privilege(const char* appid)
 {
-       void* handle = dlopen("libprivilege-control.so.0", RTLD_LAZY | RTLD_LOCAL);
-       if (!handle)
-       {
-               fprintf(stderr, "Cannot open libprivilege-control.so.0\n");
-               return;
-       }
-
-       char* msg = 0;
-       dlerror();
-
-       int (*ppriv_func)(const char*) = NULL;
-
-       ppriv_func = (int (*)(const char*))dlsym(handle, "set_privilege");
-       msg = dlerror();
-       if (msg != NULL)
-       {
-               fprintf(stderr, "Dlsym error: %s\n", msg);
-
-               dlclose(handle);
-               return;
-       }
-
-       int ret = (*ppriv_func)(appid);
-       if (ret < 0)
-       {
-               fprintf(stderr, "set_privilege() returned %d\n", ret);
-       }
-
-       dlclose(handle);
+       set_privilege(appid);
 }
 
 extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
@@ -137,7 +110,7 @@ adjust_capability(void)
 }
 
 static int
-osp_do_pre_exe(const char* bin_path)
+osp_do_pre_exe(const char* app_id, const char* bin_path)
 {
        int ret = 0;
        void* handle = NULL;
@@ -162,7 +135,7 @@ osp_do_pre_exe(const char* bin_path)
        }
        LOGD("dlsym() ok");
 
-       ret = do_pre_exec_fn(NULL, bin_path);
+       ret = do_pre_exec_fn(app_id, bin_path);
        if (ret < 0)
        {
                LOGE("Failed to do_pre_exe() (%d)", ret);
@@ -219,42 +192,50 @@ main(int argc, char* argv[])
 {
        void* handle = NULL;
        char* errormsg = 0;
-       char packageid[MAX_PACKAGEID + 1];
-       char executable_name[MAX_APP_EXECUTABLE_NAME];
-       char appid[MAX_APPID];
-
-       void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
-       int (*pRealMain)(int, char* []) = NULL;
-
-       memset(packageid, 0, sizeof(packageid));
-       memset(executable_name, 0, sizeof(executable_name));
-       memset(appid, 0, sizeof(appid));
+       const char* pid = NULL;
 
        LOGI("Initializeing : argc %d, argv 0x%x.", argc, argv);
        //print_args(argc, argv);
 
-       // convert package path to package name
-       get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
-       snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+       if (appinfo_is_initialized() == 0)
+       {
+               // not initialized
+               char packageid[MAX_PACKAGEID + 1];
+               char executable_name[MAX_APP_EXECUTABLE_NAME];
+               char appid[MAX_APPID];
+
+               memset(packageid, 0, sizeof(packageid));
+               memset(executable_name, 0, sizeof(executable_name));
+               memset(appid, 0, sizeof(appid));
+
+               // convert package path to package name
+               get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
+               snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+
+               // initialize appid
+               appinfo_init(appid, 0);
+
+               LOGI("Non-preloading initialization done.");
+       }
+
+       pid = appinfo_get_appid();
 
 #ifdef _SECURE_LOG
-       LOGI("app is %s", appid);
+       LOGI("app is %s", pid);
 #endif
 
        if (getuid() == 0)
        {
                // self caging
-               osp_do_pre_exe(argv[0]);
+               osp_do_pre_exe(pid, argv[0]);
 
                // adjust privilege
-               adjust_privilege(appid);
+               adjust_privilege(pid);
        }
 
 
        adjust_capability();
 
-       // initialize appid
-       appinfo_init(appid, 0);
        appinfo_set_argv(argc, argv);
 
        // actual loading
@@ -270,7 +251,8 @@ main(int argc, char* argv[])
                return -1;
        }
 
-       pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(so_handle, "InitAppInfo");
+       void (*pAppInfoInit)() = NULL;
+       pAppInfoInit = (void (*)()) dlsym(so_handle, "AppInfo_Update");
        errormsg = dlerror();
        if (errormsg != NULL)
        {
@@ -288,6 +270,7 @@ main(int argc, char* argv[])
                return -1;
        }
 
+       int (*pRealMain)(int, char* []) = NULL;
        pRealMain = (int (*)(int, char*[])) dlsym(handle, "OspMain");
        errormsg = dlerror();
        if (errormsg != NULL)
@@ -299,7 +282,7 @@ main(int argc, char* argv[])
        }
 
        // actual initialization
-       (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+       (*pAppInfoInit)();
        (*pRealMain)(argc, argv);
 
        LOGI("Osp application terminates.");
index f8feba3..4c98a81 100644 (file)
@@ -1,14 +1,14 @@
 Name:          osp-loader
 Summary:       osp application loader
 Version:       1.2.2.1
-Release:       1
+Release:       2
 Group:         TO_BE/FILLED_IN
 License:       Apache-2.0
 Source0:       %{name}-%{version}.tar.gz
 BuildRequires: cmake
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(appinfo) >= 0.1.0
-Requires:      libprivilege-control
+BuildRequires: pkgconfig(libprivilege-control)
 
 # runtime requires
 Requires:      osp-env-config