Move the symlink creation logic to installer
[platform/framework/native/env-config.git] / osp-env-config.c
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef _GNU_SOURCE
19 #define _GNU_SOURCE
20 #endif
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <sched.h>
26 #include <sys/mount.h>
27 #include <errno.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <limits.h>
31 #include <sys/prctl.h>
32 #include <sys/vfs.h>
33
34 #include <dlog.h>
35 #include <vconf.h>
36
37 #undef LOG_TAG
38 #define LOG_TAG "ENV_CONFIG"
39
40 #define _MAX_PACKAGEID_LENGTH 10
41 #define _MAX_APIVERSION_LENGTH 3
42
43 #ifdef _SECURE_LOG
44 #define _SECURE_LOGI LOGI
45 #define _SECURE_LOGE LOGE
46 #else
47 #define _SECURE_LOGI(...)
48 #define _SECURE_LOGE(...)
49 #endif
50
51 static const char* _OSP_HOME_PATH = "/opt/osp/\0"; // /opt/apps/com.samsung.osp
52 static const char* _OSP_COMPAT_SHARED_PATH = "/opt/usr/share/.osp-compat/\0";
53 static const char* _EXT_OSP_HOME_PATH = "/opt/storage/sdcard/osp/\0";
54
55 struct _path_info
56 {
57     char src_path[PATH_MAX];
58     char dest_path[PATH_MAX];
59 };
60
61 struct _dir_info
62 {
63         char path[PATH_MAX];
64         mode_t mode;
65         char app_privilege; // 0: root privilege
66 };
67
68 /*
69  * XXX: The returned app_roodir must be freed in caller.
70  */
71 static char*
72 get_app_rootpath_from_path(const char* bin_path)
73 {
74         char* app_rootpath = NULL;
75         char* delimiter = NULL;
76         size_t length = 0;
77         /* e.g., The specified bin_path is "/opt/apps/com.samsung.basicapp/bin/basicapp" */
78
79         length = strlen(bin_path);
80         app_rootpath = (char *)malloc(length + 1);
81         if(app_rootpath == NULL)
82                 return NULL;
83
84         memset(app_rootpath, '\0', length + 1);
85         strncpy(app_rootpath, bin_path, length);
86
87         _SECURE_LOGI("input bin_path: %s", app_rootpath);
88
89         delimiter = strrchr(app_rootpath, '/');
90         *delimiter = '\0';
91
92         delimiter  = strrchr(app_rootpath, '/');
93         *delimiter = '\0';
94
95         return app_rootpath;
96 }
97
98 static void
99 get_package_id_from_app_rootpath(const char* app_rootpath, char* package_id)
100 {
101         const char* p = NULL;
102         if (strncmp(app_rootpath, "/opt/apps/org.tizen.", 19) == 0)
103         {
104         p = strrchr(app_rootpath, '.') + 1;
105         }
106         else
107         {
108         p = strrchr(app_rootpath, '/') + 1;
109         }
110         strncpy(package_id, p, _MAX_PACKAGEID_LENGTH);
111     package_id[_MAX_PACKAGEID_LENGTH] = '\0';
112
113         _SECURE_LOGI("package id: %s", package_id);
114 }
115
116 static void
117 get_package_id_from_package_name(const char* package_name, char* package_id)
118 {
119     char* tmpbuf = NULL;
120
121     if (strncmp(package_name, "com", 3) == 0)
122     {   // in case of com.samsung.#osp#[package_id]#[serviceid]
123         tmpbuf = strstr(package_name, "#osp#");
124         if (tmpbuf != NULL)
125         {
126             strncpy(package_id, tmpbuf + 5, _MAX_PACKAGEID_LENGTH);
127         }
128     }
129     else if (strncmp(package_name, "osp", 3) == 0)
130     {   // in case of osp.[package_id].#osp#[serviceid]
131         tmpbuf = strstr(package_name, "osp.");
132         if (tmpbuf != NULL)
133         {
134             strncpy(package_id, tmpbuf + 4, _MAX_PACKAGEID_LENGTH);
135         }
136     }
137         else if (strncmp(package_name, "org.tizen", 9) == 0)
138         {
139                 // in case of org.tizen.[package_id]#[serviceid]
140                 tmpbuf = strstr(package_name, "org.tizen.");
141                 if (tmpbuf != NULL)
142                 {
143                         strncpy(package_id, tmpbuf + 10, _MAX_PACKAGEID_LENGTH);
144                 }
145         }
146     else if (strlen(package_name) == 10)
147     {
148                 strncpy(package_id, package_name, _MAX_PACKAGEID_LENGTH);
149     }
150     else
151     {
152         LOGE("package name is invalid (%s)", package_name);
153     }
154
155     package_id[_MAX_PACKAGEID_LENGTH] = '\0';
156
157         _SECURE_LOGI("package_id: %s", package_id);
158 }
159
160 static int
161 internal_is_mounted(const char* pkgid)
162 {
163         char mount_flag[64] = { 0, };
164         static const char dir[][64] =
165         {
166                 { "/tmp/osp-compat" },
167                 { "/tmp/osp-compat/mount" },
168                 { "/tmp/osp-compat/mount/internal" }
169         };
170
171         sprintf(mount_flag, "/tmp/osp-compat/mount/internal/%s", pkgid);
172         int res = access(mount_flag, F_OK);
173         if (res == 0)
174         {
175                 LOGI("Intenal path is already mounted.");
176                 return 1;
177         }
178         else if (res == -1 && errno == ENOENT)
179         {
180                 int i = 0;
181                 for (i = 0; i < sizeof(dir)/64; ++i)
182                 {
183                         int res = mkdir(dir[i], 0755);
184                         if (res == -1 && errno != EEXIST)
185                         {
186                                 LOGE("Failed to create directory (%s), errno: %d (%s)", dir[i], errno, strerror(errno));
187                                 return 1;
188                         }
189                 }
190
191                 int fd = creat(mount_flag, 0644);
192                 if (fd == -1)
193                 {
194                         LOGE("Failed to create mount flag (%s), errno: %d (%s)", mount_flag, errno, strerror(errno));
195                         return 1;
196                 }
197                 close(fd);
198         }
199         else
200         {
201                 LOGE("Failed to access mount flag (%s), errno: %d (%s)", mount_flag, errno, strerror(errno));
202                 return 1;
203         }
204
205         LOGI("Intenal path mount succeeded.");
206         return 0;
207 }
208
209 static int
210 external_is_mounted(const char* pkgid)
211 {
212         char mount_flag[64] = { 0, };
213         static const char dir[][64] =
214         {
215                 { "/tmp/osp-compat" },
216                 { "/tmp/osp-compat/mount" },
217                 { "/tmp/osp-compat/mount/external" }
218         };
219
220         sprintf(mount_flag, "/tmp/osp-compat/mount/external/%s", pkgid);
221         int res = access(mount_flag, F_OK);
222         if (res == 0)
223         {
224                 LOGI("Extenal path is already mounted.");
225                 return 1;
226         }
227         else if (res == -1 && errno == ENOENT)
228         {
229                 int i = 0;
230                 for (i = 0; i < sizeof(dir)/64; ++i)
231                 {
232                         int res = mkdir(dir[i], 0755);
233                         if (res == -1 && errno != EEXIST)
234                         {
235                                 LOGE("Failed to create directory (%s), errno: %d (%s)", dir[i], errno, strerror(errno));
236                                 return 1;
237                         }
238                 }
239
240                 int fd = creat(mount_flag, 0644);
241                 if (fd == -1)
242                 {
243                         LOGE("Failed to create mount flag (%s), errno: %d (%s)", mount_flag, errno, strerror(errno));
244                         return 1;
245                 }
246                 close(fd);
247         }
248         else
249         {
250                 LOGE("Failed to access mount flag (%s), errno: %d (%s)", mount_flag, errno, strerror(errno));
251                 return 1;
252         }
253
254         LOGI("Extenal path mount succeeded.");
255         return 0;
256 }
257
258 static int
259 mount_slp_paths(const char* app_rootpath)
260 {
261     int i = 0;
262     static const struct _path_info mount_info[] = {
263         //{ "/bin",             "./bin" },
264         //{ "/boot",            "./boot" },
265         //{ "/cache",           "./cache" },
266         { "/csa",               "./csa" },
267         { "/dev",               "./dev" },
268         { "/dev/pts",           "./dev/pts" },
269         { "/dev/shm",           "./dev/shm" },
270         { "/etc",               "./etc" },
271         { "/lib",               "./lib" },
272         //{ "/lost+found",      "./lost+found" },
273         { "/media",             "./media" },
274         { "/mnt",               "./mnt" },
275         { "/opt",               "./opt" },
276         { "/opt/usr",           "./opt/usr" },
277         { "/opt/var/kdb/db",    "./opt/var/kdb/db" },
278         { "/opt/storage/sdcard","./opt/storage/sdcard" },
279         //{ "/packaging",       "./packaging" },
280         { "/proc",              "./proc" },
281         { "/sbin",              "./sbin" },
282         { "/smack",             "./smack" },
283         { "/srv",               "./srv" },
284         { "/sys",               "./sys" },
285         { "/sys/kernel/debug",  "./sys/kernel/debug" },
286         { "/tmp",               "./tmp" },
287         { "/usr",               "./usr" },
288         { "/var",               "./var" },
289         { "/var/run",           "./var/run" }
290     };
291
292     if (chdir(app_rootpath) != 0)
293     {
294         LOGE("chdir() failed path: %s, errno: %d (%s)", app_rootpath, errno, strerror(errno));
295         return -1;
296     }
297
298     for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); ++i)
299     {
300         if (mount(mount_info[i].src_path, mount_info[i].dest_path, NULL, MS_BIND, NULL) != 0)
301         {
302             LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)",
303                     mount_info[i].src_path, mount_info[i].dest_path, errno, strerror(errno));
304
305             int j = 0;
306             for (j = i; j > 0; --j)
307             {
308                 umount2(mount_info[j-1].dest_path, MNT_DETACH);
309             }
310             return -1;
311         }
312     }
313
314     return 0;
315 }
316
317 static int
318 mount_osp_internal_paths(const char* app_rootpath, const char* pkgid)
319 {
320     int i = 0;
321     char osp_share_pkgid_path[PATH_MAX] = {0, };
322     char osp_share2_pkgid_path[PATH_MAX] = {0, };
323     struct _path_info mount_info[] = {
324         { "\0",                    "./data/Share" },
325         { "\0",                    "./data/Share2" },
326         { "/opt/usr/share/.osp-compat/share",  "./Share" },
327         { "/opt/usr/share/.osp-compat/share2", "./Share2" },
328       //{ "/opt/osp/clipboard",    "./Clipboard" },
329       //{ "/opt/osp/partner/npki", "./NPKI" },
330       //{ "/opt/osp/system",       "./System" },
331       //{ "/opt/osp/Tmp",          "./Tmp" },
332         { "/opt/usr/media",        "./Media" }
333     };
334
335     strncpy(osp_share_pkgid_path, _OSP_COMPAT_SHARED_PATH, strlen(_OSP_COMPAT_SHARED_PATH));
336     strncat(osp_share_pkgid_path, "share/", 6);
337     strncat(osp_share_pkgid_path, pkgid, strlen(pkgid));
338
339     strncpy(osp_share2_pkgid_path, _OSP_COMPAT_SHARED_PATH, strlen(_OSP_COMPAT_SHARED_PATH));
340     strncat(osp_share2_pkgid_path, "share2/", 7);
341     strncat(osp_share2_pkgid_path, pkgid, strlen(pkgid));
342
343     strncpy(mount_info[0].src_path, osp_share_pkgid_path, strlen(osp_share_pkgid_path));
344     strncpy(mount_info[1].src_path, osp_share2_pkgid_path, strlen(osp_share2_pkgid_path));
345
346     if (chdir(app_rootpath) != 0)
347     {
348         LOGE("chdir() failed, path: %s, errno: %d (%s)", app_rootpath, errno, strerror(errno));
349         return -1;
350     }
351
352     for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); ++i)
353     {
354         if (mount(mount_info[i].src_path, mount_info[i].dest_path, NULL, MS_BIND, NULL) != 0)
355         {
356             LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)",
357                     mount_info[i].src_path, mount_info[i].dest_path, errno, strerror(errno));
358
359             int j = 0;
360             for (j = i; j > 0; --j)
361             {
362                 umount2(mount_info[j-1].dest_path, MNT_DETACH);
363             }
364             return -1;
365         }
366     }
367
368     return 0;
369 }
370
371 static int
372 create_osp_external_paths(const char* app_rootpath, const char* pkgid)
373 {
374     char osp_ext_apps_pkgid_path[PATH_MAX] = {0, };
375     char osp_ext_apps_pkgid_share_path[PATH_MAX] = {0, };
376     char osp_ext_apps_pkgid_share2_path[PATH_MAX] = {0, };
377     char osp_ext_share_pkgid_path[PATH_MAX] = {0, };
378     char osp_ext_share2_pkgid_path[PATH_MAX] = {0, };
379         struct _dir_info external_dirs[] = {
380         { "./HomeExt",           0000, 0},
381         { "./ShareExt",          0000, 0},
382         { "./Share2Ext",         0000, 0},
383         { "/opt/storage/sdcard/osp",            0777,   0 },
384         { "/opt/storage/sdcard/osp/apps",       0777,   0 },
385         { "/opt/storage/sdcard/osp/share",      0777,   0 },
386         { "/opt/storage/sdcard/osp/share2",     0777,   0 },
387         { "\0", 0777, 0},
388         { "\0", 0777, 0},
389         { "\0", 0777, 0},
390         { "\0", 0777, 0},
391         { "\0", 0777, 0},
392         { "/opt/storage/sdcard/Images", 0777,   0 },
393         { "/opt/storage/sdcard/Sounds", 0777,   0 },
394         { "/opt/storage/sdcard/Videos", 0777,   0 },
395       //{ "/opt/storage/sdcard/Themes", 0777,   0 },
396         { "/opt/storage/sdcard/Others", 0777,   0 }
397         };
398     int i = 0;
399
400     strncpy(osp_ext_apps_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
401     strncat(osp_ext_apps_pkgid_path, "apps/", 5);
402     strncat(osp_ext_apps_pkgid_path, pkgid, strlen(pkgid));
403
404     strncpy(osp_ext_apps_pkgid_share_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path));
405     strncat(osp_ext_apps_pkgid_share_path, "/Share", 6);
406
407     strncpy(osp_ext_apps_pkgid_share2_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path));
408     strncat(osp_ext_apps_pkgid_share2_path, "/Share2", 7);
409
410     strncpy(osp_ext_share_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
411     strncat(osp_ext_share_pkgid_path, "share/", 6);
412     strncat(osp_ext_share_pkgid_path, pkgid, strlen(pkgid));
413
414     strncpy(osp_ext_share2_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
415     strncat(osp_ext_share2_pkgid_path, "share2/", 7);
416     strncat(osp_ext_share2_pkgid_path, pkgid, strlen(pkgid));
417
418     strncpy(external_dirs[7].path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path));
419     strncpy(external_dirs[8].path, osp_ext_apps_pkgid_share_path, strlen(osp_ext_apps_pkgid_share_path));
420     strncpy(external_dirs[9].path, osp_ext_apps_pkgid_share2_path, strlen(osp_ext_apps_pkgid_share2_path));
421     strncpy(external_dirs[10].path, osp_ext_share_pkgid_path, strlen(osp_ext_share_pkgid_path));
422     strncpy(external_dirs[11].path, osp_ext_share2_pkgid_path, strlen(osp_ext_share2_pkgid_path));
423
424     if (chdir(app_rootpath) != 0)
425     {
426         LOGE("chdir() failed (%s), path: %s", strerror(errno), app_rootpath);
427         return -1;
428     }
429
430     for (i = 0; i < sizeof(external_dirs)/sizeof(struct _dir_info); i++)
431     {
432         int ret = mkdir(external_dirs[i].path, external_dirs[i].mode);
433         if (ret == -1 && errno != 17) // EEXIST
434         {
435             LOGE("mkdir() failed, path: %s, errno: %d (%s)", external_dirs[i].path, errno, strerror(errno));
436             return -1;
437         }
438     }
439
440     return 0;
441 }
442
443 static int
444 mount_osp_external_paths(const char* app_rootpath, const char* pkgid)
445 {
446     char osp_ext_apps_pkgid_path[PATH_MAX] = {0, };
447     char osp_ext_share_pkgid_path[PATH_MAX] = {0, };
448     char osp_ext_share2_pkgid_path[PATH_MAX] = {0, };
449     struct _path_info mount_info[] = {
450         { "/opt/storage/sdcard",  "./Storagecard/Media" },
451         { "/opt/storage/sdcard/osp/share",  "./ShareExt" },
452         { "/opt/storage/sdcard/osp/share2", "./Share2Ext" },
453         { "\0",  "./HomeExt" },
454         { "\0",  "./HomeExt/Share" },
455         { "\0",  "./HomeExt/Share2" },
456     };
457     int i = 0;
458
459     strncpy(osp_ext_apps_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
460     strncat(osp_ext_apps_pkgid_path, "apps/", 5);
461     strncat(osp_ext_apps_pkgid_path, pkgid, strlen(pkgid));
462
463     strncpy(osp_ext_share_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
464     strncat(osp_ext_share_pkgid_path, "share/", 6);
465     strncat(osp_ext_share_pkgid_path, pkgid, strlen(pkgid));
466
467     strncpy(osp_ext_share2_pkgid_path, _EXT_OSP_HOME_PATH, strlen(_EXT_OSP_HOME_PATH));
468     strncat(osp_ext_share2_pkgid_path, "share2/", 7);
469     strncat(osp_ext_share2_pkgid_path, pkgid, strlen(pkgid));
470
471     strncpy(mount_info[3].src_path, osp_ext_apps_pkgid_path, strlen(osp_ext_apps_pkgid_path));
472     strncpy(mount_info[4].src_path, osp_ext_share_pkgid_path, strlen(osp_ext_share_pkgid_path));
473     strncpy(mount_info[5].src_path, osp_ext_share2_pkgid_path, strlen(osp_ext_share2_pkgid_path));
474
475     if (chdir(app_rootpath) != 0)
476     {
477         LOGE("chdir() failed, path: %s, errno: %d (%s)", app_rootpath, errno, strerror(errno));
478         return -1;
479     }
480     LOGI("app_rootpath: %s", app_rootpath);
481
482     for (i = 0; i < sizeof(mount_info)/sizeof(struct _path_info); i++)
483     {
484         if (mount(mount_info[i].src_path, mount_info[i].dest_path, NULL, MS_BIND, NULL) != 0)
485         {
486             LOGE("mount() failed, src path: %s, dest path: %s, errno: %d (%s)",
487                     mount_info[i].src_path, mount_info[i].dest_path, errno, strerror(errno));
488
489             int j = 0;
490             for (j = i; j > 0; --j)
491             {
492                 umount2(mount_info[j-1].dest_path, MNT_DETACH);
493             }
494             return -1;
495         }
496     }
497
498     return 0;
499 }
500
501 int
502 do_pre_exe(const char* package_name, const char* bin_path, const char* package_id)
503 {
504         char* app_rootpath = NULL;
505         char osp_app_data_path[PATH_MAX] = {0, };
506         //char internal_installed = 1; // true
507         int mmc_mounted = 0;
508     struct statfs fs;
509
510         /* e.g., app_rootdir is "/opt/apps/com.samsung.basicapp or /opt/osp/applications/[appId] */
511         app_rootpath = get_app_rootpath_from_path(bin_path);
512
513         _SECURE_LOGI("[data_caging] do_pre_exe() was called, package name: %s, package id: %s, binary: %s, app root: %s",
514                         package_name, package_id, bin_path, app_rootpath);
515
516         umask(0000);
517
518         // TODO: Check whether the application is installed in internal or external storage.
519         // Check installation position using the input path.
520     //if (internal_installed)
521     //{
522
523     if (!internal_is_mounted(package_id))
524     {
525         if (mount_slp_paths(app_rootpath) != 0)
526             goto ERROR;
527
528         if (mount_osp_internal_paths(app_rootpath, package_id) != 0)
529             goto ERROR;
530     }
531
532     int ret = 0;
533     ret = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_mounted);
534     if (ret < 0)
535     {
536         LOGE("vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
537     }
538     if (mmc_mounted == 1)
539     {
540         LOGI("MMC is mounted.");
541         if (create_osp_external_paths(app_rootpath, package_id) != 0)
542         {
543             goto ERROR;
544         }
545
546         if (!external_is_mounted(package_id))
547         {
548             if (mount_osp_external_paths(app_rootpath, package_id) != 0)
549             {
550                 goto ERROR;
551             }
552         }
553     }
554     /*}
555         else
556         {
557             // TODO mount_external_paths(app_rootpath);
558         }*/
559         LOGI("mount() succeeded.");
560
561         if (chroot(app_rootpath) != 0)
562         {
563                 LOGE("chroot() failed, path: %s, errno: %d (%s)", app_rootpath, errno, strerror(errno));
564                 goto ERROR;
565         }
566     if (chdir("/") != 0)
567         {
568                 LOGE("chdir() failed, path: /, errno: %d (%s)", errno, strerror(errno));
569                 goto ERROR;
570         }
571         LOGI("chroot() succeeded.");
572
573         // set current working dir to "/opt/apps/{packageId}/data"
574 #if 0
575         strncpy(osp_app_data_path, app_rootpath, strlen(app_rootpath));
576         strncat(osp_app_data_path, "/data", strlen("/data"));
577 #endif
578
579         if (chdir("/data") != 0)
580         {
581                 LOGE("chdir() failed, path: /data, errno: %d (%s)", errno, strerror(errno));
582                 goto ERROR;
583         }
584
585         free(app_rootpath);
586     umask(0022);
587
588         LOGI("[data_caging] do_pre_exec() succeeded.");
589         return 0;
590
591 ERROR:
592     free(app_rootpath);
593     umask(0022);
594
595         LOGI("[data_caging] do_pre_exec() failed.");
596     return -1;
597 }
598
599 int
600 do_pre_exec(const char* package_name, const char* bin_path)
601 {
602         char* app_rootpath = NULL;
603     char app_compat_path[PATH_MAX] = { 0, };
604     const char app_compat_file[] = "/info/compat.info\0";
605     int pathlen = 0;
606     char package_id[_MAX_PACKAGEID_LENGTH + 1] = { 0, };
607     char osp_app_data_path[PATH_MAX] = { 0, };
608     int osp_compat = 0;
609
610         _SECURE_LOGI("do_pre_exec() is called, package name: %s, binary path: %s", package_name, bin_path);
611
612         app_rootpath = get_app_rootpath_from_path(bin_path);
613
614         strncpy(app_compat_path, app_rootpath, strlen(app_rootpath));
615         strncat(app_compat_path, app_compat_file, strlen(app_compat_file));
616     if (access(app_compat_path, F_OK) == 0)
617     {
618         osp_compat = 1;
619     }
620
621     // XXX: temp code
622     //if (package_name == NULL)
623     {
624         //LOGI("The package name is empty.");
625         get_package_id_from_app_rootpath(app_rootpath, package_id);
626     }
627 #if 0
628     else
629     {
630         get_package_id_from_package_name(package_name, package_id);
631     }
632 #endif
633     // XXX-end
634
635         _SECURE_LOGI("package: %s (%s), binary: %s, OSP compat: %d", package_name, package_id, bin_path, osp_compat);
636
637         // FIXME: Temporary code with security risk
638         prctl(PR_SET_KEEPCAPS, 1);
639
640     if (osp_compat == 1)
641     {
642                 free(app_rootpath);
643                 //unshare(CLONE_NEWNS);
644                 return do_pre_exe(package_name, bin_path, package_id);
645     }
646
647     // API version is equal to or greater than Tizen 2.0
648         // Set current working dir to "/opt/apps/{pkgId}/data"
649         strncpy(osp_app_data_path, app_rootpath, strlen(app_rootpath));
650         strncat(osp_app_data_path, "/data", strlen("/data"));
651
652         if (chdir(osp_app_data_path) != 0)
653         {
654                 LOGE("chdir() failed, path: %s, errno: %d (%s)", osp_app_data_path, errno, strerror(errno));
655                 goto ERROR;
656         }
657
658         LOGI("[data_caging] do_pre_exec() succeeded.");
659         free(app_rootpath);
660         return 0;
661
662 ERROR:
663         free(app_rootpath);
664         return -1;
665 }