diff options
author | Hyunbin Lee <hyunbin.lee@samsung.com> | 2013-12-10 15:08:21 +0900 |
---|---|---|
committer | Hyunbin Lee <hyunbin.lee@samsung.com> | 2013-12-10 15:09:22 +0900 |
commit | 71d7dd515a1cfc84283af757cc58b5e3aaca06fe (patch) | |
tree | 031be4443528479be634c6229dcfa1d526b4c311 | |
parent | d68a3ad8d9c02097484054857d0f9876ece5a2ac (diff) | |
parent | 74039c0ded55c0f2e4fe697a37e6dbe4e0d1bebc (diff) | |
download | env-config-71d7dd515a1cfc84283af757cc58b5e3aaca06fe.tar.gz env-config-71d7dd515a1cfc84283af757cc58b5e3aaca06fe.tar.bz2 env-config-71d7dd515a1cfc84283af757cc58b5e3aaca06fe.zip |
Sync with tizen_2.2submit/tizen/20131211.081950accepted/tizen/mobile/20131216.220312
Change-Id: I231927e53e41d950a784743e818aea5df9af61a2
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | appinfo/CMakeLists.txt | 2 | ||||
-rw-r--r-- | appinfo/appinfo.c | 12 | ||||
-rw-r--r-- | appinfo/appinfo.h | 2 | ||||
-rw-r--r-- | packaging/osp-env-config.spec | 17 | ||||
-rw-r--r-- | src/osp-env-config.c (renamed from osp-env-config.c) | 311 | ||||
-rw-r--r-- | usr/etc/app-storage-exclude-dirs.list | 23 |
7 files changed, 180 insertions, 197 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 01516e6..aa0fc33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,10 +5,11 @@ SET(this_target osp-env-config) INCLUDE_DIRECTORIES( /usr/include/vconf /usr/include/dlog + appinfo ) SET (${this_target}_SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/osp-env-config.c + src/osp-env-config.c ) ADD_SUBDIRECTORY(appinfo) @@ -20,7 +21,11 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined -Wl,--as-needed") -TARGET_LINK_LIBRARIES(${this_target} "-lvconf -ldlog") +ADD_DEPENDENCIES(${this_target} appinfo) + +TARGET_LINK_LIBRARIES(${this_target} "-ldl -lvconf -ldlog") +TARGET_LINK_LIBRARIES(${this_target} appinfo) + SET_TARGET_PROPERTIES(${this_target} PROPERTIES @@ -33,4 +38,3 @@ INSTALL(TARGETS ${this_target} DESTINATION ${LIB_INSTALL_DIR} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/usr/etc/app-storage-exclude-dirs.list DESTINATION ../usr/etc) diff --git a/appinfo/CMakeLists.txt b/appinfo/CMakeLists.txt index 9718a86..a46236d 100644 --- a/appinfo/CMakeLists.txt +++ b/appinfo/CMakeLists.txt @@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(this_target appinfo) SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.1.1") +SET(VERSION "${VERSION_MAJOR}.1.2") #INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) diff --git a/appinfo/appinfo.c b/appinfo/appinfo.c index 5078f24..b93f840 100644 --- a/appinfo/appinfo.c +++ b/appinfo/appinfo.c @@ -365,6 +365,18 @@ int appinfo_update_submode_execname_and_appid(const char* execname) return 1; } +int appinfo_update_submode_appid(const char* appid) +{ + if (appid == NULL) + { + return 0; + } + + strncpy(__appid, appid, MAX_APPID); + + return 1; +} + #ifdef __cplusplus } #endif diff --git a/appinfo/appinfo.h b/appinfo/appinfo.h index ea7963d..fa28ece 100644 --- a/appinfo/appinfo.h +++ b/appinfo/appinfo.h @@ -144,6 +144,8 @@ int appinfo_get_argv(int* argc, char*** argv); int appinfo_update_submode_execname_and_appid(const char* execname); +int appinfo_update_submode_appid(const char* appid); + #ifdef __cplusplus } #endif diff --git a/packaging/osp-env-config.spec b/packaging/osp-env-config.spec index 007b62d..27f130d 100644 --- a/packaging/osp-env-config.spec +++ b/packaging/osp-env-config.spec @@ -1,7 +1,7 @@ Name: osp-env-config Summary: osp application environment cofiguration serivce Version: 1.2.2.1 -Release: 2 +Release: 4 Group: System/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -29,15 +29,23 @@ osp application environment cofiguration serivce (devel) cp %{SOURCE1001} . %build +%if 0%{?tizen_build_binary_release_type_eng} +CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE" +%endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` + %ifarch %{ix86} x86_64 %if 0%{?simulator} -CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_ -D_SECURE_LOG" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +CFLAGS="$CFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} %else -CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_SECURE_LOG" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +CFLAGS="$CFLAGS -D_OSP_DEBUG_ -D_OSP_X86_" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} %endif %else -CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_ -D_SECURE_LOG" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%if 0%{?tizen_build_binary_release_type_eng} +CFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_ -DTIZEN_ENGINEER_MODE" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%else +CFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" %cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%endif %endif # Call make instruction with smp support @@ -60,7 +68,6 @@ cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license /usr/share/license/%{name} %{_libdir}/*.so* %{_libdir}/osp/libappinfo.so* -/usr/etc/app-storage-exclude-dirs.list %files devel %{_includedir}/osp/*.h diff --git a/osp-env-config.c b/src/osp-env-config.c index f259cdf..b42c102 100644 --- a/osp-env-config.c +++ b/src/osp-env-config.c @@ -31,9 +31,11 @@ #include <sys/prctl.h> #include <sys/vfs.h> #include <fcntl.h> +#include <dlfcn.h> #include <dlog.h> #include <vconf.h> +#include <appinfo.h> #undef LOG_TAG #define LOG_TAG "ENV_CONFIG" @@ -41,21 +43,23 @@ #define _MAX_PACKAGEID_LENGTH 10 #define _MAX_APIVERSION_LENGTH 3 -#ifdef _SECURE_LOG -#define _SECURE_LOGI LOGI -#define _SECURE_LOGE LOGE +#ifdef TIZEN_ENGINEER_MODE +#define _SECURE_LOGI SECURE_LOGI +#define _SECURE_LOGE SECURE_LOGE #else #define _SECURE_LOGI(...) #define _SECURE_LOGE(...) #endif -static const char* _OSP_COMPAT_SHARED_PATH = "/opt/usr/share/.osp-compat/\0"; -static const char* _EXT_OSP_HOME_PATH = "/opt/storage/sdcard/osp/\0"; +static const char _OSP_COMPAT_SHARED_PATH[] = "/opt/usr/share/.osp-compat/"; +static const char _EXT_OSP_HOME_PATH[] = "/opt/storage/sdcard/osp/"; +static const char OSP_COMPAT_LIB[] = "/usr/lib/osp/libosp-compat.so"; +static const int MAX_PACKAGE_ID = NAME_MAX; struct _path_info { char src_path[PATH_MAX]; - char dest_path[PATH_MAX]; + const char dest_path[PATH_MAX]; }; struct _dir_info @@ -74,12 +78,21 @@ get_app_rootpath_from_path(const char* bin_path) char* app_rootpath = NULL; char* delimiter = NULL; size_t length = 0; - /* e.g., The specified bin_path is "/opt/apps/com.samsung.basicapp/bin/basicapp" */ + /* e.g., The specified bin_path is "/opt/apps/com.samsung.basicapp/bin/basicapp" */ length = strlen(bin_path); + if (length > (PATH_MAX - 1)) + { + LOGE("bin path (%s) is too long", bin_path); + return NULL; + } + app_rootpath = (char *)malloc(length + 1); if(app_rootpath == NULL) + { + LOGE("malloc() failed, errno: %d (%s)", errno, strerror(errno)); return NULL; + } memset(app_rootpath, '\0', length + 1); strncpy(app_rootpath, bin_path, length); @@ -95,68 +108,6 @@ get_app_rootpath_from_path(const char* bin_path) return app_rootpath; } -static void -get_package_id_from_app_rootpath(const char* app_rootpath, char* package_id) -{ - const char* p = NULL; - if (strncmp(app_rootpath, "/opt/apps/org.tizen.", 19) == 0) - { - p = strrchr(app_rootpath, '.') + 1; - } - else - { - p = strrchr(app_rootpath, '/') + 1; - } - strncpy(package_id, p, _MAX_PACKAGEID_LENGTH); - package_id[_MAX_PACKAGEID_LENGTH] = '\0'; - _SECURE_LOGI("package id: %s", package_id); -} - -#if 0 -static void -get_package_id_from_package_name(const char* package_name, char* package_id) -{ - char* tmpbuf = NULL; - - if (strncmp(package_name, "com", 3) == 0) - { // in case of com.samsung.#osp#[package_id]#[serviceid] - tmpbuf = strstr(package_name, "#osp#"); - if (tmpbuf != NULL) - { - strncpy(package_id, tmpbuf + 5, _MAX_PACKAGEID_LENGTH); - } - } - else if (strncmp(package_name, "osp", 3) == 0) - { // in case of osp.[package_id].#osp#[serviceid] - tmpbuf = strstr(package_name, "osp."); - if (tmpbuf != NULL) - { - strncpy(package_id, tmpbuf + 4, _MAX_PACKAGEID_LENGTH); - } - } - else if (strncmp(package_name, "org.tizen", 9) == 0) - { - // in case of org.tizen.[package_id]#[serviceid] - tmpbuf = strstr(package_name, "org.tizen."); - if (tmpbuf != NULL) - { - strncpy(package_id, tmpbuf + 10, _MAX_PACKAGEID_LENGTH); - } - } - else if (strlen(package_name) == 10) - { - strncpy(package_id, package_name, _MAX_PACKAGEID_LENGTH); - } - else - { - LOGE("package name is invalid (%s)", package_name); - } - - package_id[_MAX_PACKAGEID_LENGTH] = '\0'; - _SECURE_LOGI("package_id: %s", package_id); -} -#endif - static int internal_is_mounted(const char* pkgid) { @@ -259,7 +210,7 @@ static int mount_native_paths(const char* app_rootpath) { int i = 0; - static const struct _path_info mount_info[] = + const struct _path_info mount_info[] = { //{ "/bin", "./bin" }, { "/csa", "./csa" }, @@ -270,13 +221,12 @@ mount_native_paths(const char* app_rootpath) { "/lib", "./lib" }, { "/mnt", "./mnt" }, { "/proc", "./proc" }, - { "/sbin", "./sbin" }, { "/smack", "./smack" }, - { "/srv", "./srv" }, { "/sys", "./sys" }, { "/sys/kernel/debug", "./sys/kernel/debug" }, { "/tmp", "./tmp" }, { "/usr", "./usr" }, + { "/usr/share/locale", "./usr/share/locale" }, { "/var", "./var" }, { "/var/run", "./var/run" }, { "/opt", "./opt" }, @@ -316,10 +266,13 @@ mount_osp_internal_paths(const char* app_rootpath, const char* pkgid) int i = 0; char osp_share_pkgid_path[PATH_MAX] = {0, }; char osp_share2_pkgid_path[PATH_MAX] = {0, }; - struct _path_info mount_info[] = + struct _path_info mount_info1[] = { { "\0", "./data/Share" }, - { "\0", "./data/Share2" }, + { "\0", "./data/Share2" } + }; + const struct _path_info mount_info2[] = + { { "/opt/usr/share/.osp-compat/share", "./Share" }, { "/opt/usr/share/.osp-compat/share2", "./Share2" }, { "/opt/usr/media", "./Media" } @@ -327,14 +280,14 @@ mount_osp_internal_paths(const char* app_rootpath, const char* pkgid) strncpy(osp_share_pkgid_path, _OSP_COMPAT_SHARED_PATH, strlen(_OSP_COMPAT_SHARED_PATH)); strncat(osp_share_pkgid_path, "share/", 6); - strncat(osp_share_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_share_pkgid_path, pkgid, MAX_PACKAGE_ID); strncpy(osp_share2_pkgid_path, _OSP_COMPAT_SHARED_PATH, strlen(_OSP_COMPAT_SHARED_PATH)); strncat(osp_share2_pkgid_path, "share2/", 7); - strncat(osp_share2_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_share2_pkgid_path, pkgid, MAX_PACKAGE_ID); - strncpy(mount_info[0].src_path, osp_share_pkgid_path, strlen(osp_share_pkgid_path)); - strncpy(mount_info[1].src_path, osp_share2_pkgid_path, strlen(osp_share2_pkgid_path)); + strncpy(mount_info1[0].src_path, osp_share_pkgid_path, PATH_MAX - 1); + strncpy(mount_info1[1].src_path, osp_share2_pkgid_path, PATH_MAX - 1); if (chdir(app_rootpath) != 0) { @@ -342,17 +295,32 @@ mount_osp_internal_paths(const char* app_rootpath, const char* pkgid) return -1; } - for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); ++i) + for (i = 0; i < sizeof(mount_info1)/sizeof(struct _path_info); ++i) { - if (mount(mount_info[i].src_path, mount_info[i].dest_path, NULL, MS_BIND, NULL) != 0) + if (mount(mount_info1[i].src_path, mount_info1[i].dest_path, NULL, MS_BIND, NULL) != 0) { LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)", - mount_info[i].src_path, mount_info[i].dest_path, errno, strerror(errno)); + mount_info1[i].src_path, mount_info1[i].dest_path, errno, strerror(errno)); int j = 0; for (j = i; j > 0; --j) { - umount2(mount_info[j-1].dest_path, MNT_DETACH); + umount2(mount_info1[j-1].dest_path, MNT_DETACH); + } + return -1; + } + } + for (i = 0; i < sizeof(mount_info2)/sizeof(struct _path_info); ++i) + { + if (mount(mount_info2[i].src_path, mount_info2[i].dest_path, NULL, MS_BIND, NULL) != 0) + { + LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)", + mount_info2[i].src_path, mount_info2[i].dest_path, errno, strerror(errno)); + + int j = 0; + for (j = i; j > 0; --j) + { + umount2(mount_info2[j-1].dest_path, MNT_DETACH); } return -1; } @@ -365,12 +333,10 @@ static int mount_linux_paths(const char* app_rootpath) { int i = 0; - static const struct _path_info mount_info[] = + const struct _path_info mount_info[] = { { "/bin", "./bin" }, - { "/cache", "./cache" }, { "/csa", "./csa" }, - { "/data", "./data" }, { "/dev", "./dev" }, { "/dev/pts", "./dev/pts" }, { "/dev/shm", "./dev/shm" }, @@ -381,15 +347,13 @@ mount_linux_paths(const char* app_rootpath) { "/mnt", "./mnt" }, { "/proc", "./proc" }, { "/run", "./run" }, - { "/sbin", "./sbin" }, { "/smack", "./smack" }, - { "/srv", "./srv" }, { "/sys", "./sys" }, { "/sys/fs/cgroup", "./sys/fs/cgroup" }, { "/sys/fs/cgroup/systemd", "./sys/fs/cgroup/systemd" }, - { "/system", "./system" }, { "/tmp", "./tmp" }, { "/usr", "./usr" }, + { "/usr/share/locale", "./usr/share/locale" }, { "/var", "./var" }, { "/var/run", "./var/run" }, { "/opt", "./opt" }, @@ -406,7 +370,7 @@ mount_linux_paths(const char* app_rootpath) for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); ++i) { - if (i == 27) // /opt/storage/sdcard + if (i == 23) // /opt/storage/sdcard { int mmc_mounted = 0; int ret = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_mounted); @@ -446,7 +410,7 @@ create_osp_external_paths(const char* app_rootpath, const char* pkgid) char osp_ext_apps_pkgid_share2_path[PATH_MAX] = {0, }; char osp_ext_share_pkgid_path[PATH_MAX] = {0, }; char osp_ext_share2_pkgid_path[PATH_MAX] = {0, }; - struct _dir_info external_dirs[] = + const struct _dir_info external_dirs1[] = { { "./HomeExt", 0000, 0 }, { "./ShareExt", 0000, 0 }, @@ -455,41 +419,44 @@ create_osp_external_paths(const char* app_rootpath, const char* pkgid) { "/opt/storage/sdcard/osp/apps", 0777, 0 }, { "/opt/storage/sdcard/osp/share", 0777, 0 }, { "/opt/storage/sdcard/osp/share2", 0777, 0 }, - { "\0", 0777, 0}, - { "\0", 0777, 0}, - { "\0", 0777, 0}, - { "\0", 0777, 0}, - { "\0", 0777, 0}, { "/opt/storage/sdcard/Images", 0777, 0 }, { "/opt/storage/sdcard/Sounds", 0777, 0 }, { "/opt/storage/sdcard/Videos", 0777, 0 }, { "/opt/storage/sdcard/Others", 0777, 0 } }; + struct _dir_info external_dirs2[] = + { + { "\0", 0777, 0}, + { "\0", 0777, 0}, + { "\0", 0777, 0}, + { "\0", 0777, 0}, + { "\0", 0777, 0} + }; int i = 0; strncpy(osp_ext_apps_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_apps_pkgid_path, "apps/", 5); - strncat(osp_ext_apps_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_apps_pkgid_path, pkgid, MAX_PACKAGE_ID); - strncpy(osp_ext_apps_pkgid_share_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path)); + strncpy(osp_ext_apps_pkgid_share_path, osp_ext_apps_pkgid_path, PATH_MAX - 1); strncat(osp_ext_apps_pkgid_share_path, "/Share", 6); - strncpy(osp_ext_apps_pkgid_share2_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path)); + strncpy(osp_ext_apps_pkgid_share2_path, osp_ext_apps_pkgid_path, PATH_MAX - 1); strncat(osp_ext_apps_pkgid_share2_path, "/Share2", 7); strncpy(osp_ext_share_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_share_pkgid_path, "share/", 6); - strncat(osp_ext_share_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_share_pkgid_path, pkgid, MAX_PACKAGE_ID); strncpy(osp_ext_share2_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_share2_pkgid_path, "share2/", 7); - strncat(osp_ext_share2_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_share2_pkgid_path, pkgid, MAX_PACKAGE_ID); - strncpy(external_dirs[7].path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path)); - strncpy(external_dirs[8].path, osp_ext_apps_pkgid_share_path, strlen(osp_ext_apps_pkgid_share_path)); - strncpy(external_dirs[9].path, osp_ext_apps_pkgid_share2_path, strlen(osp_ext_apps_pkgid_share2_path)); - strncpy(external_dirs[10].path, osp_ext_share_pkgid_path, strlen(osp_ext_share_pkgid_path)); - strncpy(external_dirs[11].path, osp_ext_share2_pkgid_path, strlen(osp_ext_share2_pkgid_path)); + strncpy(external_dirs2[0].path, osp_ext_apps_pkgid_path, PATH_MAX - 1); + strncpy(external_dirs2[1].path, osp_ext_apps_pkgid_share_path, PATH_MAX - 1); + strncpy(external_dirs2[2].path, osp_ext_apps_pkgid_share2_path, PATH_MAX - 1); + strncpy(external_dirs2[3].path, osp_ext_share_pkgid_path, PATH_MAX - 1); + strncpy(external_dirs2[4].path, osp_ext_share2_pkgid_path, PATH_MAX - 1); if (chdir(app_rootpath) != 0) { @@ -497,12 +464,21 @@ create_osp_external_paths(const char* app_rootpath, const char* pkgid) return -1; } - for (i = 0; i < sizeof(external_dirs)/sizeof(struct _dir_info); i++) + for (i = 0; i < sizeof(external_dirs1)/sizeof(struct _dir_info); i++) { - int ret = mkdir(external_dirs[i].path, external_dirs[i].mode); + int ret = mkdir(external_dirs1[i].path, external_dirs1[i].mode); if (ret == -1 && errno != 17) // EEXIST { - LOGE("mkdir() failed, path: %s, errno: %d (%s)", external_dirs[i].path, errno, strerror(errno)); + LOGE("mkdir() failed, path: %s, errno: %d (%s)", external_dirs1[i].path, errno, strerror(errno)); + return -1; + } + } + for (i = 0; i < sizeof(external_dirs2)/sizeof(struct _dir_info); i++) + { + int ret = mkdir(external_dirs2[i].path, external_dirs2[i].mode); + if (ret == -1 && errno != 17) // EEXIST + { + LOGE("mkdir() failed, path: %s, errno: %d (%s)", external_dirs2[i].path, errno, strerror(errno)); return -1; } } @@ -516,11 +492,14 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid) char osp_ext_apps_pkgid_path[PATH_MAX] = {0, }; char osp_ext_share_pkgid_path[PATH_MAX] = {0, }; char osp_ext_share2_pkgid_path[PATH_MAX] = {0, }; - struct _path_info mount_info[] = + struct _path_info mount_info1[] = { { "/opt/storage/sdcard", "./Storagecard/Media" }, { "/opt/storage/sdcard/osp/share", "./ShareExt" }, - { "/opt/storage/sdcard/osp/share2", "./Share2Ext" }, + { "/opt/storage/sdcard/osp/share2", "./Share2Ext" } + }; + struct _path_info mount_info2[] = + { { "\0", "./HomeExt" }, { "\0", "./HomeExt/Share" }, { "\0", "./HomeExt/Share2" } @@ -529,19 +508,19 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid) strncpy(osp_ext_apps_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_apps_pkgid_path, "apps/", 5); - strncat(osp_ext_apps_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_apps_pkgid_path, pkgid, MAX_PACKAGE_ID); strncpy(osp_ext_share_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_share_pkgid_path, "share/", 6); - strncat(osp_ext_share_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_share_pkgid_path, pkgid, MAX_PACKAGE_ID); strncpy(osp_ext_share2_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH)); strncat(osp_ext_share2_pkgid_path, "share2/", 7); - strncat(osp_ext_share2_pkgid_path, pkgid, strlen(pkgid)); + strncat(osp_ext_share2_pkgid_path, pkgid, MAX_PACKAGE_ID); - strncpy(mount_info[3].src_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path)); - strncpy(mount_info[4].src_path, osp_ext_share_pkgid_path, strlen(osp_ext_share_pkgid_path)); - strncpy(mount_info[5].src_path, osp_ext_share2_pkgid_path, strlen(osp_ext_share2_pkgid_path)); + strncpy(mount_info2[0].src_path, osp_ext_apps_pkgid_path, PATH_MAX - 1); + strncpy(mount_info2[1].src_path, osp_ext_share_pkgid_path, PATH_MAX - 1); + strncpy(mount_info2[2].src_path, osp_ext_share2_pkgid_path, PATH_MAX - 1); if (chdir(app_rootpath) != 0) { @@ -550,17 +529,32 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid) } LOGI("app_rootpath: %s", app_rootpath); - for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); i++) + for (i = 0; i < sizeof(mount_info1)/sizeof(struct _path_info); i++) { - if (mount(mount_info[i].src_path, mount_info[i].dest_path, NULL, MS_BIND, NULL) != 0) + if (mount(mount_info1[i].src_path, mount_info1[i].dest_path, NULL, MS_BIND, NULL) != 0) { LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)", - mount_info[i].src_path, mount_info[i].dest_path, errno, strerror(errno)); + mount_info1[i].src_path, mount_info1[i].dest_path, errno, strerror(errno)); int j = 0; for (j = i; j > 0; --j) { - umount2(mount_info[j-1].dest_path, MNT_DETACH); + umount2(mount_info1[j-1].dest_path, MNT_DETACH); + } + return -1; + } + } + for (i = 0; i < sizeof(mount_info2)/sizeof(struct _path_info); i++) + { + if (mount(mount_info2[i].src_path, mount_info2[i].dest_path, NULL, MS_BIND, NULL) != 0) + { + LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)", + mount_info2[i].src_path, mount_info2[i].dest_path, errno, strerror(errno)); + + int j = 0; + for (j = i; j > 0; --j) + { + umount2(mount_info2[j-1].dest_path, MNT_DETACH); } return -1; } @@ -570,16 +564,16 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid) } int -do_pre_exe(const char* package_name, const char* bin_path, const char* package_id) +do_pre_exe(const char* app_rootpath, const char* package_id) { - char* app_rootpath = NULL; int mmc_mounted = 0; - /* e.g., app_rootdir is "/opt/usr/apps/[pkgId] */ - app_rootpath = get_app_rootpath_from_path(bin_path); - - _SECURE_LOGI("[data_caging] do_pre_exe() was called, package name: %s, package id: %s, binary: %s, app root: %s", - package_name, package_id, bin_path, app_rootpath); + // preload libosp-compat.so.1 for compatibility + void* handle = dlopen(OSP_COMPAT_LIB, RTLD_GLOBAL); + if (handle) + { + LOGI("%s is preloaded.", OSP_COMPAT_LIB); + } umask(0000); @@ -636,17 +630,15 @@ do_pre_exe(const char* package_name, const char* bin_path, const char* package_i goto ERROR; } - free(app_rootpath); umask(0022); - LOGI("[data_caging] do_pre_exec() succeeded."); + LOGI("[data_caging] do_pre_exe() succeeded."); return 0; ERROR: - free(app_rootpath); umask(0022); - LOGI("[data_caging] do_pre_exec() failed."); + LOGI("[data_caging] do_pre_exe() failed."); return -1; } @@ -674,7 +666,7 @@ do_virtual_root(const char* virtual_root_path, const char* package_id) } if (chdir("/") != 0) { - LOGE("chdir() failed. path: /data, errno: %d (%s)", errno, strerror(errno)); + LOGE("chdir() failed. path: /, errno: %d (%s)", errno, strerror(errno)); goto ERROR; } LOGI("chroot() succeeded."); @@ -692,55 +684,44 @@ ERROR: } int -do_pre_exec(const char* package_name, const char* bin_path) +do_pre_exec(const char* app_id, const char* bin_path) { - char* app_rootpath = NULL; char app_compat_path[PATH_MAX] = { 0, }; - const char app_compat_file[] = "/info/compat.info\0"; - char package_id[_MAX_PACKAGEID_LENGTH + 1] = { 0, }; - char osp_app_data_path[PATH_MAX] = { 0, }; + const char app_compat_file[] = "/info/compat.info"; + char app_data_path[PATH_MAX] = { 0, }; int osp_compat = 0; - _SECURE_LOGI("do_pre_exec() is called, package name: %s, binary path: %s", package_name, bin_path); + const char* app_rootpath = get_app_rootpath_from_path(bin_path); - app_rootpath = get_app_rootpath_from_path(bin_path); - - strncpy(app_compat_path, app_rootpath, strlen(app_rootpath)); + strncpy(app_compat_path, app_rootpath, PATH_MAX - 1); strncat(app_compat_path, app_compat_file, strlen(app_compat_file)); if (access(app_compat_path, F_OK) == 0) { osp_compat = 1; } - // XXX: temp code - //if (package_name == NULL) - { - //LOGI("The package name is empty."); - get_package_id_from_app_rootpath(app_rootpath, package_id); - } -#if 0 - else - { - get_package_id_from_package_name(package_name, package_id); - } -#endif - // XXX-end + appinfo_init(app_id, 0); + appinfo_set_compat(osp_compat); + + const char* package_id = appinfo_get_packageid(); - _SECURE_LOGI("package: %s (%s), binary: %s, OSP compat: %d", package_name, package_id, bin_path, osp_compat); + _SECURE_LOGI("do_pre_exec() is called, bin path: %s, app root: %s, app id: %s, pkg id: %s, osp-compatible: %d", + bin_path, app_rootpath, app_id, package_id, osp_compat); // FIXME: Temporary code with security risk prctl(PR_SET_KEEPCAPS, 1); if (osp_compat == 1) { - free(app_rootpath); //unshare(CLONE_NEWNS); - return do_pre_exe(package_name, bin_path, package_id); + int ret = do_pre_exe(app_rootpath, package_id); + free(app_rootpath); + return ret; } char virtual_root_file[PATH_MAX] = { 0, }; const char virtual_root_info[] = "/info/virtualroot.info"; - strncpy(virtual_root_file, app_rootpath, strlen(app_rootpath)); + strncpy(virtual_root_file, app_rootpath, PATH_MAX - 1); strncat(virtual_root_file, virtual_root_info, strlen(virtual_root_info)); if (access(virtual_root_file, F_OK) == 0) { @@ -753,7 +734,7 @@ do_pre_exec(const char* package_name, const char* bin_path) } char user_path[PATH_MAX] = { 0, }; - int read_bytes = read(fd, user_path, PATH_MAX); + int read_bytes = read(fd, user_path, PATH_MAX - 1); if (read_bytes < 0) { LOGE("failed to read %s, errno: %d (%s)", virtual_root_file, errno, strerror(errno)); @@ -770,14 +751,13 @@ do_pre_exec(const char* package_name, const char* bin_path) return res; } - // API version is equal to or greater than Tizen 2.0 - // Set current working dir to "/opt/apps/{pkgId}/data" - strncpy(osp_app_data_path, app_rootpath, strlen(app_rootpath)); - strncat(osp_app_data_path, "/data", strlen("/data")); + // Set current working dir to "/opt/usr/apps/{pkgId}/data" + strncpy(app_data_path, app_rootpath, PATH_MAX - 1); + strncat(app_data_path, "/data", strlen("/data")); - if (chdir(osp_app_data_path) != 0) + if (chdir(app_data_path) != 0) { - LOGE("chdir() failed, path: %s, errno: %d (%s)", osp_app_data_path, errno, strerror(errno)); + LOGE("chdir() failed, path: %s, errno: %d (%s)", app_data_path, errno, strerror(errno)); goto ERROR; } @@ -789,3 +769,4 @@ ERROR: free(app_rootpath); return -1; } + diff --git a/usr/etc/app-storage-exclude-dirs.list b/usr/etc/app-storage-exclude-dirs.list deleted file mode 100644 index 199a06f..0000000 --- a/usr/etc/app-storage-exclude-dirs.list +++ /dev/null @@ -1,23 +0,0 @@ -csa -dev -etc -lib -mnt -proc -sbin -smack -srv -sys -tmp -usr -var -opt -data/Share -data/Share2 -Share -Share2 -Media -HomeExt -ShareExt -Share2Ext -Storagecard/Media |