summaryrefslogtreecommitdiff
path: root/src/osp-env-config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osp-env-config.c')
-rw-r--r--src/osp-env-config.c135
1 files changed, 86 insertions, 49 deletions
diff --git a/src/osp-env-config.c b/src/osp-env-config.c
index 3030303..ded97d7 100644
--- a/src/osp-env-config.c
+++ b/src/osp-env-config.c
@@ -108,7 +108,6 @@ get_app_rootpath_from_path(const char* bin_path)
return app_rootpath;
}
-
static int
internal_is_mounted(const char* pkgid)
{
@@ -267,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" }
+ };
+ static const struct _path_info mount_info2[] =
+ {
{ "/opt/usr/share/.osp-compat/share", "./Share" },
{ "/opt/usr/share/.osp-compat/share2", "./Share2" },
{ "/opt/usr/media", "./Media" }
@@ -284,8 +286,8 @@ mount_osp_internal_paths(const char* app_rootpath, const char* pkgid)
strncat(osp_share2_pkgid_path, "share2/", 7);
strncat(osp_share2_pkgid_path, pkgid, MAX_PACKAGE_ID);
- strncpy(mount_info[0].src_path, osp_share_pkgid_path, PATH_MAX - 1);
- strncpy(mount_info[1].src_path, osp_share2_pkgid_path, PATH_MAX - 1);
+ 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)
{
@@ -293,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;
}
@@ -393,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[] =
+ static const struct _dir_info external_dirs1[] =
{
{ "./HomeExt", 0000, 0 },
{ "./ShareExt", 0000, 0 },
@@ -402,16 +419,19 @@ 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));
@@ -432,11 +452,11 @@ create_osp_external_paths(const char* app_rootpath, const char* pkgid)
strncat(osp_ext_share2_pkgid_path, "share2/", 7);
strncat(osp_ext_share2_pkgid_path, pkgid, MAX_PACKAGE_ID);
- strncpy(external_dirs[7].path, osp_ext_apps_pkgid_path, PATH_MAX - 1);
- strncpy(external_dirs[8].path, osp_ext_apps_pkgid_share_path, PATH_MAX - 1);
- strncpy(external_dirs[9].path, osp_ext_apps_pkgid_share2_path, PATH_MAX - 1);
- strncpy(external_dirs[10].path, osp_ext_share_pkgid_path, PATH_MAX - 1);
- strncpy(external_dirs[11].path, osp_ext_share2_pkgid_path, PATH_MAX - 1);
+ 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)
{
@@ -444,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;
}
}
@@ -463,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" }
@@ -486,9 +518,9 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid)
strncat(osp_ext_share2_pkgid_path, "share2/", 7);
strncat(osp_ext_share2_pkgid_path, pkgid, MAX_PACKAGE_ID);
- strncpy(mount_info[3].src_path, osp_ext_apps_pkgid_path, PATH_MAX - 1);
- strncpy(mount_info[4].src_path, osp_ext_share_pkgid_path, PATH_MAX - 1);
- strncpy(mount_info[5].src_path, osp_ext_share2_pkgid_path, PATH_MAX - 1);
+ 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)
{
@@ -497,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;
}
@@ -517,9 +564,8 @@ mount_osp_external_paths(const char* app_rootpath, const char* pkgid)
}
int
-do_pre_exe(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;
// preload libosp-compat.so.1 for compatibility
@@ -529,12 +575,6 @@ do_pre_exe(const char* bin_path, const char* package_id)
LOGI("%s is preloaded.", OSP_COMPAT_LIB);
}
- /* 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 id: %s, binary path: %s, app root: %s",
- package_id, bin_path, app_rootpath);
-
umask(0000);
if (!internal_is_mounted(package_id))
@@ -590,14 +630,12 @@ do_pre_exe(const char* bin_path, const char* package_id)
goto ERROR;
}
- free(app_rootpath);
umask(0022);
LOGI("[data_caging] do_pre_exe() succeeded.");
return 0;
ERROR:
- free(app_rootpath);
umask(0022);
LOGI("[data_caging] do_pre_exe() failed.");
@@ -648,13 +686,12 @@ ERROR:
int
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";
char app_data_path[PATH_MAX] = { 0, };
int osp_compat = 0;
- app_rootpath = get_app_rootpath_from_path(bin_path);
+ const char* app_rootpath = get_app_rootpath_from_path(bin_path);
strncpy(app_compat_path, app_rootpath, PATH_MAX - 1);
strncat(app_compat_path, app_compat_file, strlen(app_compat_file));
@@ -676,9 +713,10 @@ do_pre_exec(const char* app_id, const char* bin_path)
if (osp_compat == 1)
{
- free(app_rootpath);
//unshare(CLONE_NEWNS);
- return do_pre_exe(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, };
@@ -696,7 +734,7 @@ do_pre_exec(const char* app_id, 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));
@@ -713,8 +751,7 @@ do_pre_exec(const char* app_id, 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"
+ // 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"));