4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jungmin Cho <chivalry.cho@samsung.com>, Gwangho Hwang <gwang.hwang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * simple AUL daemon - launchpad
30 #include <sys/types.h>
37 #include <sys/prctl.h>
45 #include "menu_db_util.h"
46 #include "simple_util.h"
47 #include "access_control.h"
59 #include <sys/smack.h>
60 #include "fileutils.h"
62 #define _static_ static inline
64 #define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
65 #define AUL_POLL_CNT 15
66 #define AUL_PR_NAME 16
68 #define PATH_TMP "/tmp"
69 #define PATH_DATA "/data"
71 #define SDK_CODE_COVERAGE "CODE_COVERAGE"
72 #define SDK_DEBUG "DEBUG"
73 #define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
74 #define SDK_UNIT_TEST "UNIT_TEST"
75 #define SDK_VALGRIND "VALGRIND"
77 /* DLP is short for debug-launchpad */
78 #define DLP_K_DEBUG_ARG "__DLP_DEBUG_ARG__"
79 #define DLP_K_UNIT_TEST_ARG "__DLP_UNIT_TEST_ARG__"
80 #define DLP_K_VALGRIND_ARG "__DLP_VALGRIND_ARG__"
82 #define PATH_GDBSERVER "/home/developer/sdk_tools/gdbserver/gdbserver"
83 #define PATH_VALGRIND "/home/developer/sdk_tools/valgrind/usr/bin/valgrind"
84 #define PATH_DA_SO "/usr/lib/da_probe_osp.so"
85 #define PATH_NATIVE_APP "/opt/apps/"
87 #define OPT_VALGRIND_LOGFILE "--log-file="
88 #define OPT_VALGRIND_LOGFILE_FIXED "--log-file=/tmp/valgrind_result.txt"
89 #define PATH_VALGRIND_LOGFILE "/tmp/valgrind_result.txt"
90 #define OPT_VALGRIND_XMLFILE "--xml-file="
91 #define OPT_VALGRIND_XMLFILE_FIXED "--xml-file=/tmp/valgrind_result.xml"
92 #define PATH_VALGRIND_XMLFILE "/tmp/valgrind_result.xml"
94 #define POLL_VALGRIND_LOGFILE 0x00000001
95 #define POLL_VALGRIND_XMLFILE 0x00000002
97 static char *launchpad_cmdline;
98 static int initialized = 0;
100 static int poll_outputfile = 0;
103 void __set_env(app_info_from_db * menu_info, bundle * kb);
104 int __prepare_exec(const char *pkg_name,
105 const char *app_path, app_info_from_db * menu_info,
107 int __fake_launch_app(int cmd, int pid, bundle * kb);
108 char **__create_argc_argv(bundle * kb, int *margc, const char *app_path);
109 int __normal_fork_exec(int argc, char **argv);
110 void __real_launch(const char *app_path, bundle * kb);
111 static inline int __parser(const char *arg, char *out, int out_size);
112 void __modify_bundle(bundle * kb, int caller_pid,
113 app_info_from_db * menu_info, int cmd);
114 int __send_to_sigkill(int pid);
115 int __term_app(int pid);
116 void __real_send(int clifd, int ret);
117 void __send_result_to_caller(int clifd, int ret);
118 void __launchpad_main_loop(int main_fd);
119 int __launchpad_pre_init(int argc, char **argv);
120 int __launchpad_post_init();
122 extern ail_error_e ail_db_close(void);
128 char buf[MAX_LOCAL_BUFSZ];
131 /* we should reset oomadj value as default because child
132 inherits from parent oom_adj*/
133 snprintf(buf, MAX_LOCAL_BUFSZ, "/proc/%d/oom_adj", getpid());
134 fp = fopen(buf, "w");
137 fprintf(fp, "%d", -16);
141 void __set_sdk_env(app_info_from_db* menu_info, char* str) {
142 char buf_pkgname[MAX_LOCAL_BUFSZ];
143 char buf[MAX_LOCAL_BUFSZ];
146 _D("key : %s / value : %s", AUL_K_SDK, str);
147 /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
148 /* GCOV_PREFIX contains the prefix to add to the absolute paths */
149 /* in the object file. Prefix can be absolute, or relative.*/
150 /* The default is no prefix. */
151 /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
152 /* to stripoff the hardwired absolute paths. Default value is 0. */
153 if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
154 strncpy(buf_pkgname,_get_pkgname(menu_info),MAX_LOCAL_BUFSZ-1);
155 buf_pkgname[MAX_LOCAL_BUFSZ-1]='\0';
156 snprintf(buf, MAX_LOCAL_BUFSZ, PATH_TMP"/%s"PATH_DATA
157 , strtok(buf_pkgname,"."));
158 ret = setenv("GCOV_PREFIX", buf, 1);
159 _D("GCOV_PREFIX : %d", ret);
160 ret = setenv("GCOV_PREFIX_STRIP", "0", 1);
161 _D("GCOV_PREFIX_STRIP : %d", ret);
162 } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
163 ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
164 _D("LD_PRELOAD : %d", ret);
169 void __set_env(app_info_from_db * menu_info, bundle * kb)
172 const char **str_array;
176 setenv("PKG_NAME", _get_pkgname(menu_info), 1);
180 str = bundle_get_val(kb, AUL_K_STARTTIME);
182 setenv("APP_START_TIME", str, 1);
184 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
185 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
186 if(str_array != NULL) {
187 for (i = 0; i < len; i++) {
188 _D("index : [%d]", i);
189 __set_sdk_env(menu_info, (char *)str_array[i]);
193 str = bundle_get_val(kb, AUL_K_SDK);
195 __set_sdk_env(menu_info, (char *)str);
198 if (menu_info->hwacc != NULL)
199 setenv("HWACC", menu_info->hwacc, 1);
202 int __prepare_exec(const char *pkg_name,
203 const char *app_path, app_info_from_db * menu_info,
207 char process_name[AUL_PR_NAME];
210 /* Set new session ID & new process group ID*/
211 /* In linux, child can set new session ID without check permission */
212 /* TODO : should be add to check permission in the kernel*/
215 __preexec_run(menu_info->pkg_type, pkg_name, app_path);
221 if(bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) {
222 _D("pkg_name : %s / pkg_type : %s / app_path : %s ", pkg_name
223 , menu_info->pkg_type, app_path);
224 if ((ret = __set_access(pkg_name, menu_info->pkg_type
227 _D("fail to set privileges - check your package's credential : %d\n"
232 /* SET DUMPABLE - for coredump*/
233 prctl(PR_SET_DUMPABLE, 1);
235 /* SET PROCESS NAME*/
236 if (app_path == NULL) {
237 _D("app_path should not be NULL - check menu db");
240 file_name = strrchr(app_path, '/') + 1;
241 if (file_name == NULL) {
242 _D("can't locate file name to execute");
245 memset(process_name, '\0', AUL_PR_NAME);
246 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
247 prctl(PR_SET_NAME, process_name);
250 __set_env(menu_info, kb);
255 int __fake_launch_app(int cmd, int pid, bundle * kb)
261 bundle_encode(kb, &kb_data, &datalen);
262 if ((ret = __app_send_raw(pid, cmd, kb_data, datalen)) < 0)
263 _E("error request fake launch - error code = %d", ret);
268 char** __add_arg(bundle * kb, char **argv, int *margc, const char *key)
270 const char *str = NULL;
271 const char **str_array = NULL;
274 char ** new_argv = NULL;
276 if(bundle_get_type(kb, key) & BUNDLE_TYPE_ARRAY) {
277 str_array = bundle_get_str_array(kb, key, &len);
279 str = bundle_get_val(kb, key);
285 if(str_array != NULL) {
286 if(strncmp(key, DLP_K_DEBUG_ARG, strlen(key)) == 0
287 || strncmp(key, DLP_K_VALGRIND_ARG, strlen(key)) == 0)
289 new_argv = (char **) realloc(argv
290 , sizeof(char *) * (*margc+len+2));
292 _E("realloc fail (key = %s)", key);
295 for(i=*margc+len+1; i-(len+1)>=0; i--) {
296 new_argv[i] = new_argv[i-(len+1)];
298 // need to add new_argv[0]
299 for(i=0; i<len; i++) {
300 new_argv[1+i] = strdup(str_array[i]);
302 len++; /* gdbserver or valgrind */
303 _D("uid : %d", getuid());
304 _D("euid : %d", geteuid());
305 _D("gid : %d", getgid());
306 _D("egid : %d", getegid());
308 new_argv = (char **) realloc(argv
309 , sizeof(char *) * (*margc+len+1));
311 _E("realloc fail (key = %s)", key);
314 for(i=0; i<len; i++) {
315 new_argv[*margc+i] = strdup(str_array[i]);
318 new_argv[*margc+len] = NULL;
321 if(strncmp(key, DLP_K_DEBUG_ARG, strlen(key)) == 0
322 || strncmp(key, DLP_K_VALGRIND_ARG, strlen(key)) == 0)
324 new_argv = (char **) realloc(argv
325 , sizeof(char *) * (*margc+2));
327 _E("realloc fail (key = %s)", key);
330 for(i=*margc+1; i-1>=0; i--) {
331 new_argv[i] = new_argv[i-1];
333 // need to add new_argv[0]
338 if(new_argv==NULL) return argv;
342 char **__create_argc_argv(bundle * kb, int *margc, const char *app_path)
345 char **new_argv = NULL;
348 const char *str = NULL;
349 const char **str_array = NULL;
353 argc = bundle_export_to_argv(kb, &argv);
355 argv[0] = strdup(app_path);
357 _E("bundle_export_to_argv error");
361 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
362 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
364 str = bundle_get_val(kb, AUL_K_SDK);
370 if(str_array == NULL) {
375 for (i = 0; i < len; i++) {
376 if(str_array[i] == NULL) break;
377 _D("index : [%d]", i);
379 if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0)
381 char buf[MAX_LOCAL_BUFSZ];
382 if (argv[0]) free(argv[0]);
383 sprintf(buf,"%s.exe",app_path);
384 argv[0] = strdup(buf);
385 new_argv = __add_arg(kb, argv, &argc, DLP_K_DEBUG_ARG);
386 new_argv[0] = strdup(PATH_GDBSERVER);
389 else if (strncmp(str_array[i], SDK_VALGRIND
390 , strlen(str_array[i])) == 0)
392 new_argv = __add_arg(kb, argv, &argc
393 , DLP_K_VALGRIND_ARG);
394 new_argv[0] = strdup(PATH_VALGRIND);
397 else if (strncmp(str_array[i], SDK_UNIT_TEST
398 , strlen(str_array[i])) == 0)
400 new_argv = __add_arg(kb, argv, &argc
401 , DLP_K_UNIT_TEST_ARG);
406 if(new_argv==NULL) return argv;
410 int __normal_fork_exec(int argc, char **argv)
412 _D("start real fork and exec\n");
414 if (execv(argv[0], argv) < 0) { /* Flawfinder: ignore */
415 if (errno == EACCES) {
416 _E("such a file is no executable - %s", argv[0]);
418 _E("unknown executable error - %s", argv[0]);
426 void __real_launch(const char *app_path, bundle * kb)
432 app_argv = __create_argc_argv(kb, &app_argc, app_path);
434 for (i = 0; i < app_argc; i++)
435 _D("input argument %d : %s##", i, app_argv[i]);
437 PERF("setup argument done");
438 _D("lock up test log(no error) : setup argument done");
440 /* Temporary log: launch time checking */
441 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:launchpad:done]", app_path);
443 __normal_fork_exec(app_argc, app_argv);
445 for(i=0; i<app_argc; i++) {
446 if(app_argv[i]) free(app_argv[i]);
453 * Parsing original app path to retrieve default bundle
455 * -1 : Invalid sequence
456 * -2 : Buffer overflow
459 static inline int __parser(const char *arg, char *out, int out_size)
463 char *start_out = out;
465 if (arg == NULL || out == NULL) {
466 /* Handles null buffer*/
470 for (i = 0; out_size > 1; i++) {
494 case 2: /* escape start*/
509 case 4: /* character escape*/
510 if (arg[i] == '\0') {
520 if (out != start_out) {
529 return -1; /* error*/
530 case 7: /* terminate*/
547 void __modify_bundle(bundle * kb, int caller_pid,
548 app_info_from_db * menu_info, int cmd)
550 bundle_del(kb, AUL_K_PKG_NAME);
551 bundle_del(kb, AUL_K_EXEC);
552 bundle_del(kb, AUL_K_PACKAGETYPE);
553 bundle_del(kb, AUL_K_HWACC);
555 /* Parse app_path to retrieve default bundle*/
556 if (cmd == APP_START || cmd == APP_START_RES || cmd == APP_OPEN
557 || cmd == APP_RESUME)
560 char exe[MAX_PATH_LEN];
563 ptr = _get_original_app_path(menu_info);
565 flag = __parser(ptr, exe, sizeof(exe));
571 _D("parsing app_path: EXEC - %s\n", exe);
574 flag = __parser(ptr, key, sizeof(key));
579 flag = __parser(ptr, value, sizeof(value));
584 /*bundle_del(kb, key);*/
585 bundle_add(kb, key, value);
587 } else if (flag == 0) {
588 _D("parsing app_path: No arguments\n");
590 _D("parsing app_path: Invalid argument\n");
595 int __send_to_sigkill(int pid)
603 if (killpg(pgid, SIGKILL) < 0)
609 int __term_app(int pid)
613 (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int)) < 0) {
614 _D("terminate packet send error - use SIGKILL");
615 if (__send_to_sigkill(pid) < 0) {
616 _E("fail to killing - %d\n", pid);
624 static int __get_caller_pid(bundle *kb)
629 pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
633 pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
645 int __foward_cmd(int cmd, bundle *kb, int cr_pid)
648 char tmp_pid[MAX_PID_STR_BUFSZ];
653 if ((pid = __get_caller_pid(kb)) < 0)
656 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", cr_pid);
658 bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
660 bundle_encode(kb, &kb_data, &datalen);
661 if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0)
669 void __real_send(int clifd, int ret)
671 if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
672 if (errno == EPIPE) {
673 _E("send failed due to EPIPE.\n");
675 _E("send fail to client");
681 void __send_result_to_caller(int clifd, int ret)
685 int cmdline_changed = 0;
686 int cmdline_exist = 0;
692 __real_send(clifd, ret);
695 /* check normally was launched?*/
698 cmdline = __proc_get_cmdline_bypid(ret);
699 if (cmdline == NULL) {
700 _E("error founded when being launched with %d", ret);
702 } else if (strcmp(cmdline, launchpad_cmdline)) {
711 _D("-- now wait to change cmdline --");
712 usleep(50 * 1000); /* 50ms sleep*/
714 } while (wait_count <= 20); /* max 50*20ms will be sleep*/
716 if ((!cmdline_exist) && (!cmdline_changed)) {
717 _E("abnormally launched");
718 __real_send(clifd, -1); /* abnormally launched*/
722 if (!cmdline_changed)
723 _E("process launched, but cmdline not changed");
725 __real_send(clifd, ret);
729 static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
730 const char *pkgname, bundle *kb)
732 app_info_from_db *menu_info;
734 menu_info = calloc(1, sizeof(app_info_from_db));
735 if (menu_info == NULL) {
739 menu_info->pkg_name = strdup(pkgname);
740 menu_info->app_path = strdup(bundle_get_val(kb, AUL_K_EXEC));
741 if (menu_info->app_path != NULL)
742 menu_info->original_app_path = strdup(menu_info->app_path);
743 menu_info->pkg_type = strdup(bundle_get_val(kb, AUL_K_PACKAGETYPE));
744 menu_info->hwacc = strdup(bundle_get_val(kb, AUL_K_HWACC));
746 if (!_get_app_path(menu_info)) {
747 _free_app_info_from_db(menu_info);
757 int get_native_appid(const char* app_path, char** appid) {
758 int rc = smack_lgetlabel(app_path, appid, SMACK_LABEL_ACCESS);
760 if (rc != 0 || *appid == NULL) {
761 _E("smack_lgetlabel fail");
765 if (strlen(*appid) != APPID_LEN) {
766 _E("wrong native appid : %s", *appid);
770 if (strlen(app_path) < sizeof(PATH_NATIVE_APP)+APPID_LEN-1) {
771 _E("wrong native app_path : %s", app_path);
774 else if ( strncmp(app_path, PATH_NATIVE_APP, sizeof(PATH_NATIVE_APP)-1)
775 || strncmp(&app_path[sizeof(PATH_NATIVE_APP)-1]
776 , *appid,APPID_LEN) )
778 _E("wrong native app_path : %s", app_path);
782 _D("get_appid return : %s", *appid);
786 int apply_smack_rules(const char* subject, const char* object
787 , const char* access_type)
789 struct smack_accesses *rules = NULL;
791 _D("apply_smack_rules : %s %s %s", subject, object, access_type);
793 if (smack_accesses_new(&rules)) {
794 _E("smack_accesses_new fail");
798 if (smack_accesses_add(rules, subject, object, access_type)) {
799 smack_accesses_free(rules);
800 _E("smack_accesses_add fail");
804 if (smack_accesses_apply(rules)) {
805 smack_accesses_free(rules);
806 _E("smack_accesses_apply fail");
810 smack_accesses_free(rules);
815 int __prepare_valgrind_outputfile(bundle *kb)
817 const char *str = NULL;
818 const char **str_array = NULL;
822 if(bundle_get_type(kb, DLP_K_VALGRIND_ARG) & BUNDLE_TYPE_ARRAY) {
823 str_array = bundle_get_str_array(kb, DLP_K_VALGRIND_ARG, &len);
825 str = bundle_get_val(kb, DLP_K_VALGRIND_ARG);
831 if(str_array == NULL) return 0;
833 for (i = 0; i < len; i++) {
834 if(str_array[i] == NULL) break;
835 /* valgrind log file option */
836 if (strncmp(str_array[i], OPT_VALGRIND_LOGFILE
837 , strlen(OPT_VALGRIND_LOGFILE)) == 0)
839 if(strncmp(str_array[i], OPT_VALGRIND_LOGFILE_FIXED
840 , strlen(str_array[i])))
842 _E("wrong valgrind option(%s). It should be %s"
844 , OPT_VALGRIND_LOGFILE_FIXED);
847 poll_outputfile |= POLL_VALGRIND_LOGFILE;
848 if(remove(PATH_VALGRIND_LOGFILE)){
849 _D("cannot remove %s"
850 , PATH_VALGRIND_LOGFILE);
854 /* valgrind xml file option */
855 else if (strncmp(str_array[i], OPT_VALGRIND_XMLFILE
856 , strlen(OPT_VALGRIND_XMLFILE)) == 0)
858 if(strncmp(str_array[i], OPT_VALGRIND_XMLFILE_FIXED
859 , strlen(str_array[i])))
861 _E("wrong valgrind option(%s). It should be %s"
863 , OPT_VALGRIND_XMLFILE_FIXED);
866 poll_outputfile |= POLL_VALGRIND_XMLFILE;
867 if(remove(PATH_VALGRIND_XMLFILE)){
868 _D("cannot remove %s"
869 , PATH_VALGRIND_XMLFILE);
877 int __prepare_fork(bundle *kb, char *appid)
879 const char *str = NULL;
880 const char **str_array = NULL;
885 if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
886 str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
888 str = bundle_get_val(kb, AUL_K_SDK);
894 if(str_array == NULL) return 0;
896 for (i = 0; i < len; i++) {
897 if(str_array[i] == NULL) break;
899 if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0)
901 if(apply_smack_rules("sdbd",appid,"w")) {
902 _E("unable to set sdbd rules");
906 // FIXME: set gdbfolder to 755 also
907 if(dlp_chmod(PATH_GDBSERVER
908 , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP
912 _D("unable to set 755 to %s", PATH_GDBSERVER);
916 else if (strncmp(str_array[i], SDK_VALGRIND
917 , strlen(str_array[i])) == 0)
919 if (__prepare_valgrind_outputfile(kb)) return 1;
925 /* chmod and chsmack to read file without root privilege */
926 void __chmod_chsmack_toread(const char * path)
929 if(dlp_chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 0))
931 _E("unable to set 644 to %s", path);
933 _D("set 644 to %s", path);
937 if(smack_setlabel(path, "*", SMACK_LABEL_ACCESS))
939 _E("failed chsmack -a \"*\" %s", path);
941 _D("chsmack -a \"*\" %s", path);
947 /* waiting for creating outputfile by child process */
948 void __waiting_outputfile()
951 while(poll_outputfile && wait_count<10) {
952 /* valgrind log file */
953 if( (poll_outputfile & POLL_VALGRIND_LOGFILE)
954 && (access(PATH_VALGRIND_LOGFILE,F_OK)==0) )
956 __chmod_chsmack_toread(PATH_VALGRIND_LOGFILE);
957 poll_outputfile &= ~POLL_VALGRIND_LOGFILE;
960 /* valgrind xml file */
961 if( (poll_outputfile & POLL_VALGRIND_XMLFILE)
962 && (access(PATH_VALGRIND_XMLFILE,F_OK)==0) )
964 __chmod_chsmack_toread(PATH_VALGRIND_XMLFILE);
965 poll_outputfile &= ~POLL_VALGRIND_XMLFILE;
968 if(poll_outputfile) {
969 _D("-- now wait for creating the file --");
970 usleep(50 * 1000); /* 50ms sleep*/
975 if(wait_count==10) _E("faild to waiting");
979 void __launchpad_main_loop(int main_fd)
982 app_pkt_t *pkt = NULL;
983 app_info_from_db *menu_info = NULL;
985 const char *pkg_name = NULL;
986 const char *app_path = NULL;
990 int is_real_launch = 0;
992 char sock_path[UNIX_PATH_MAX] = {0,};
995 pkt = __app_recv_raw(main_fd, &clifd, &cr);
997 _D("packet is NULL");
1001 kb = bundle_decode(pkt->data, pkt->len);
1003 _D("bundle decode error");
1008 PERF("packet processing start");
1010 pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
1011 _D("pkg name : %s\n", pkg_name);
1013 menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
1014 if (menu_info == NULL) {
1015 _D("such pkg no found");
1019 app_path = _get_app_path(menu_info);
1020 if(app_path == NULL) {
1021 _E("app_path is NULL");
1024 if (app_path[0] != '/') {
1025 _D("app_path is not absolute path");
1030 int rc = get_native_appid(app_path,&appid);
1031 if(rc!=0 || appid==NULL) {
1032 _E("unable to get native appid");
1033 if(appid) free(appid);
1038 __modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
1039 pkg_name = _get_pkgname(menu_info);
1041 PERF("get package information & modify bundle done");
1043 if(__prepare_fork(kb,appid)) goto end;
1048 _D("lock up test log(no error) : fork done");
1052 __signal_unset_sigchld();
1055 snprintf(sock_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX
1059 PERF("prepare exec - first done");
1060 _D("lock up test log(no error) : prepare exec - first done");
1062 if (__prepare_exec(pkg_name, app_path,
1063 menu_info, kb) < 0) {
1064 _E("preparing work fail to launch - "
1065 "can not launch %s\n", pkg_name);
1069 PERF("prepare exec - second done");
1070 _D("lock up test log(no error) : prepare exec - second done");
1072 __real_launch(app_path, kb);
1077 _D("==> real launch pid : %d %s\n", pid, app_path);
1081 __send_result_to_caller(clifd, pid);
1084 if (is_real_launch) {
1086 __signal_block_sigchld();
1087 __send_app_launch_signal(pid);
1088 __signal_unblock_sigchld();
1092 if (menu_info != NULL)
1093 _free_app_info_from_db(menu_info);
1102 /* Active Flusing for Daemon */
1103 if (initialized > AUL_POLL_CNT) {
1104 sqlite3_release_memory(SQLITE_FLUSH_MAX);
1109 if(poll_outputfile) __waiting_outputfile();
1112 int __launchpad_pre_init(int argc, char **argv)
1119 /* get my(launchpad) command line*/
1120 launchpad_cmdline = __proc_get_cmdline_bypid(getpid());
1121 if (launchpad_cmdline == NULL) {
1122 _E("launchpad cmdline fail to get");
1125 _D("launchpad cmdline = %s", launchpad_cmdline);
1127 /* create launchpad sock */
1128 fd = __create_server_sock(DEBUG_LAUNCHPAD_PID);
1130 _E("server sock error");
1134 __preload_init(argc, argv);
1136 __preexec_init(argc, argv);
1141 int __launchpad_post_init()
1143 /* Setting this as a global variable to keep track
1144 of launchpad poll cnt */
1145 /* static int initialized = 0;*/
1152 if (__signal_set_sigchld() < 0)
1160 int main(int argc, char **argv)
1163 struct pollfd pfds[POLLFD_MAX];
1166 /* init without concerning X & EFL*/
1167 main_fd = __launchpad_pre_init(argc, argv);
1169 _E("launchpad pre init failed");
1173 pfds[0].fd = main_fd;
1174 pfds[0].events = POLLIN;
1175 pfds[0].revents = 0;
1178 if (poll(pfds, POLLFD_MAX, -1) < 0)
1181 /* init with concerning X & EFL (because of booting
1183 if (__launchpad_post_init() < 0) {
1184 _E("launcpad post init failed");
1188 for (i = 0; i < POLLFD_MAX; i++) {
1189 if ((pfds[i].revents & POLLIN) != 0) {
1190 __launchpad_main_loop(pfds[i].fd);