2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sys/types.h>
28 #include <sys/prctl.h>
36 #include "menu_db_util.h"
37 #include "simple_util.h"
38 #include "access_control.h"
52 #include <sys/resource.h>
55 #include "process_pool.h"
56 #include <Elementary.h>
59 #define _static_ static inline
60 #define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
61 #define AUL_POLL_CNT 15
62 #define AUL_PR_NAME 16
64 #define EXEC_DUMMY_EXPIRED 5
65 #define DIFF(a,b) (((a)>(b))?(a)-(b):(b)-(a))
66 #define LOWEST_PRIO 20
69 static char *launchpad_cmdline;
70 static char *__appid = NULL;
71 static int initialized = 0;
72 static int candidate_pid = DUMMY_NONE;
73 static int candidate_fd = -1;
74 static int last_dummy_exec_time = 0;
75 const char* const HOME = "HOME";
76 const char* const APP_HOME_PATH = "/opt/home/app";
77 const char* const ROOT_HOME_PATH = "/opt/home/root";
79 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb);
80 _static_ int __prepare_exec(const char *pkg_name,
81 const char *app_path, app_info_from_db * menu_info,
83 _static_ int __fake_launch_app(int cmd, int pid, bundle * kb);
84 _static_ char **__create_argc_argv(bundle * kb, int *margc);
85 _static_ int __normal_fork_exec(int argc, char **argv);
86 _static_ void __real_launch(const char *app_path, bundle * kb);
87 _static_ int __candidate_process_real_launch(int dummy_client_fd, app_pkt_t* pkt);
88 static inline int __parser(const char *arg, char *out, int out_size);
89 _static_ void __modify_bundle(bundle * kb, int caller_pid,
90 app_info_from_db * menu_info, int cmd);
91 _static_ int __child_raise_win_by_x(int pid, void *priv);
92 _static_ int __raise_win_by_x(int pid);
93 _static_ int __send_to_sigkill(int pid);
94 _static_ int __term_app(int pid);
95 _static_ int __resume_app(int pid);
96 _static_ int __real_send(int clifd, int ret);
97 _static_ void __send_result_to_caller(int clifd, int ret);
98 _static_ void __prepare_candidate_process(int main_fd, int pool_fd, int client_fd);
99 _static_ void __launchpad_main_loop(int main_fd, int pool_fd);
100 _static_ int __launchpad_pre_init(int argc, char **argv);
101 _static_ int __launchpad_post_init();
103 extern ail_error_e ail_db_close(void);
106 static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
107 const char *pkgname, bundle *kb);
110 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
114 setenv("PKG_NAME", _get_pkgname(menu_info), 1);
118 str = bundle_get_val(kb, AUL_K_STARTTIME);
120 setenv("APP_START_TIME", str, 1);
122 if (menu_info->hwacc != NULL)
123 setenv("HWACC", menu_info->hwacc, 1);
124 if (menu_info->taskmanage != NULL)
125 setenv("TASKMANAGE", menu_info->taskmanage, 1);
128 _static_ int __prepare_exec(const char *pkg_name,
129 const char *app_path, app_info_from_db * menu_info,
133 char process_name[AUL_PR_NAME];
136 /* Set new session ID & new process group ID*/
137 /* In linux, child can set new session ID without check permission */
138 /* TODO : should be add to check permission in the kernel*/
141 __preexec_run(menu_info->pkg_type, pkg_name, app_path);
144 SECURE_LOGD("pkg_name : %s / pkg_type : %s / app_path : %s ", pkg_name, menu_info->pkg_type, app_path);
145 if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) {
146 _D("fail to set privileges - check your package's credential : %d\n", ret);
149 /* SET DUMPABLE - for coredump*/
150 prctl(PR_SET_DUMPABLE, 1);
152 /* SET PROCESS NAME*/
153 if (app_path == NULL) {
154 _D("app_path should not be NULL - check menu db");
157 file_name = strrchr(app_path, '/') + 1;
158 if (file_name == NULL) {
159 _D("can't locate file name to execute");
162 memset(process_name, '\0', AUL_PR_NAME);
163 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
164 prctl(PR_SET_NAME, process_name);
167 __set_env(menu_info, kb);
172 _static_ int __fake_launch_app(int cmd, int pid, bundle * kb)
178 bundle_encode(kb, &kb_data, &datalen);
179 if ((ret = __app_send_raw(pid, cmd, kb_data, datalen)) < 0)
180 _E("error request fake launch - error code = %d", ret);
185 _static_ char **__create_argc_argv(bundle * kb, int *margc)
190 argc = bundle_export_to_argv(kb, &argv);
196 _static_ int __normal_fork_exec(int argc, char **argv)
198 _D("start real fork and exec\n");
200 if (execv(argv[0], argv) < 0) { /* Flawfinder: ignore */
202 _E("such a file is no executable - %s", argv[0]);
204 _E("unknown executable error - %s", argv[0]);
211 _static_ void __real_launch(const char *app_path, bundle * kb)
217 app_argv = __create_argc_argv(kb, &app_argc);
218 app_argv[0] = strdup(app_path);
220 for (i = 0; i < app_argc; i++) {
223 SECURE_LOGD("input argument %d : %s##", i, app_argv[i]);
226 PERF("setup argument done");
228 /* Temporary log: launch time checking */
229 LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:launchpad:done]", app_path);
231 __preload_exec(app_argc, app_argv);
233 __normal_fork_exec(app_argc, app_argv);
236 _static_ int __candidate_process_real_launch(int dummy_client_fd, app_pkt_t* pkt)
238 return __send_pkt_raw_data(dummy_client_fd, pkt);
242 * Parsing original app path to retrieve default bundle
244 * -1 : Invalid sequence
245 * -2 : Buffer overflow
248 static inline int __parser(const char *arg, char *out, int out_size)
252 char *start_out = out;
254 if (arg == NULL || out == NULL) {
255 /* Handles null buffer*/
259 for (i = 0; out_size > 1; i++) {
283 case 2: /* escape start*/
298 case 4: /* character escape*/
299 if (arg[i] == '\0') {
309 if (out != start_out) {
318 return -1; /* error*/
319 case 7: /* terminate*/
336 _static_ void __modify_bundle(bundle * kb, int caller_pid,
337 app_info_from_db * menu_info, int cmd)
339 bundle_del(kb, AUL_K_PKG_NAME);
340 bundle_del(kb, AUL_K_EXEC);
341 bundle_del(kb, AUL_K_PACKAGETYPE);
342 bundle_del(kb, AUL_K_HWACC);
343 bundle_del(kb, AUL_K_TASKMANAGE);
345 /* Parse app_path to retrieve default bundle*/
346 if (cmd == APP_START || cmd == APP_START_RES || cmd == APP_START_ASYNC || cmd == APP_OPEN || cmd == APP_RESUME) {
348 char exe[MAX_PATH_LEN];
351 ptr = _get_original_app_path(menu_info);
353 flag = __parser(ptr, exe, sizeof(exe));
359 SECURE_LOGD("parsing app_path: EXEC - %s\n", exe);
362 flag = __parser(ptr, key, sizeof(key));
367 flag = __parser(ptr, value, sizeof(value));
372 /*bundle_del(kb, key);*/
373 bundle_add(kb, key, value);
375 } else if (flag == 0) {
376 _D("parsing app_path: No arguments\n");
378 _D("parsing app_path: Invalid argument\n");
383 _static_ int __child_raise_win_by_x(int pid, void *priv)
385 return x_util_raise_win(pid);
388 _static_ int __raise_win_by_x(int pid)
391 if (x_util_raise_win(pid) == 0)
394 /* support app launched by shell script*/
396 _D("X raise failed. try to find first child & raise it - c:%d p:%d\n",
401 if (__proc_iter_pgid(pgid, __child_raise_win_by_x, NULL) < 0)
407 _static_ int __send_to_sigkill(int pid)
415 if (killpg(pgid, SIGKILL) < 0)
421 _static_ int __term_app(int pid)
425 (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int)) < 0) {
426 _D("terminate packet send error - use SIGKILL");
427 if (__send_to_sigkill(pid) < 0) {
428 _E("fail to killing - %d\n", pid);
436 _static_ int __resume_app(int pid)
441 __app_send_raw(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
444 _E("resume packet timeout error");
446 _D("resume packet send error - use raise win");
447 if (__raise_win_by_x(pid) < 0) {
448 _E("raise failed - %d resume fail\n", pid);
449 _E("we will term the app - %d\n", pid);
450 __send_to_sigkill(pid);
460 static int __get_caller_pid(bundle *kb)
465 pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
469 pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
481 _static_ int __foward_cmd(int cmd, bundle *kb, int cr_pid)
484 char tmp_pid[MAX_PID_STR_BUFSZ];
489 if ((pid = __get_caller_pid(kb)) < 0)
492 snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", cr_pid);
494 bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
496 bundle_encode(kb, &kb_data, &datalen);
497 if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0)
505 _static_ int __real_send(int clifd, int ret)
507 if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
508 if (errno == EPIPE) {
509 _E("send failed due to EPIPE.\n");
513 _E("send fail to client");
520 _static_ void __send_result_to_caller(int clifd, int ret)
524 int cmdline_changed = 0;
525 int cmdline_exist = 0;
532 __real_send(clifd, ret);
535 /* check normally was launched?*/
538 cmdline = __proc_get_cmdline_bypid(ret);
539 if (cmdline == NULL) {
540 _E("error founded when being launched with %d", ret);
542 } else if (strcmp(cmdline, launchpad_cmdline)) {
551 _D("-- now wait to change cmdline --");
552 usleep(50 * 1000); /* 50ms sleep*/
554 } while (wait_count <= 20); /* max 50*20ms will be sleep*/
556 if ((!cmdline_exist) && (!cmdline_changed)) {
557 __real_send(clifd, -1); /* abnormally launched*/
561 if (!cmdline_changed)
562 _E("process launched, but cmdline not changed");
564 if(__real_send(clifd, ret) < 0) {
565 r = kill(ret, SIGKILL);
567 _E("send SIGKILL: %s", strerror(errno));
573 _static_ int __candidate_process_prepare_exec(const char *pkg_name,
574 const char *app_path, app_info_from_db *menu_info,
577 const char *file_name = NULL;
578 char process_name[AUL_PR_NAME] = { 0, };
582 SECURE_LOGD("[candidata] pkg_name : %s / pkg_type : %s / app_path : %s ", pkg_name, menu_info->pkg_type, app_path);
583 if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) {
584 _D("fail to set privileges - check your package's credential : %d\n", ret);
588 //XXX: Check CAP_MAC_ADMIN
590 /* SET INHERIT BIT FOR CAP_MAC_ADMIN TO WHOLE THREAD */
591 EXECUTE_ON_WHOLE_THREAD(__set_inherit_bit_for_CAP_MAC_ADMIN, SIGUSR1);
594 /* SET PROCESS NAME*/
595 if (app_path == NULL) {
596 _D("app_path should not be NULL - check menu db");
600 file_name = strrchr(app_path, '/') + 1;
601 if (file_name == NULL) {
602 _D("can't locate file name to execute");
605 memset(process_name, '\0', AUL_PR_NAME);
606 snprintf(process_name, AUL_PR_NAME, "%s", file_name);
607 prctl(PR_SET_NAME, process_name);
610 __set_env(menu_info, kb);
615 static bundle *_s_bundle = NULL;
616 static void __at_exit_to_release_bundle()
619 bundle_free(_s_bundle);
624 static void __release_appid_at_exit(void)
626 if (__appid != NULL) {
631 _static_ void __candidate_process_launchpad_main_loop(app_pkt_t* pkt, char* out_app_path, int* out_argc, char ***out_argv)
634 app_info_from_db *menu_info = NULL;
636 const char *pkg_name = NULL;
637 const char *app_path = NULL;
639 kb = bundle_decode(pkt->data, pkt->len);
641 _E("bundle decode error");
645 if (_s_bundle != NULL) {
646 bundle_free(_s_bundle);
649 atexit(__at_exit_to_release_bundle);
651 pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
652 SECURE_LOGD("pkg name : %s", pkg_name);
654 menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
655 if (menu_info == NULL) {
656 _D("such pkg no found");
660 app_path = _get_app_path(menu_info);
661 if (app_path == NULL) {
662 _E("app_path is NULL");
666 if (app_path[0] != '/') {
667 _E("app_path is not absolute path");
671 __modify_bundle(kb, /*cr.pid - unused parameter*/ 0, menu_info, pkt->cmd);
672 pkg_name = _get_pkgname(menu_info);
673 SECURE_LOGD("pkg name : %s", pkg_name);
675 __appid = strdup(pkg_name);
676 aul_set_preinit_appid(__appid);
677 atexit(__release_appid_at_exit);
679 __candidate_process_prepare_exec(pkg_name, app_path, menu_info, kb);
681 if (out_app_path != NULL && out_argc != NULL && out_argv != NULL)
685 sprintf(out_app_path, "%s", app_path);
687 *out_argv = __create_argc_argv(kb, out_argc);
688 (*out_argv)[0] = out_app_path;
690 for (i = 0; i < *out_argc; i++)
692 SECURE_LOGD("input argument %d : %s##", i, (*out_argv)[i]);
700 if (menu_info != NULL) {
701 _free_app_info_from_db(menu_info);
705 static Eina_Bool __candidate_proces_fd_handler(void* data, Ecore_Fd_Handler *handler)
707 int fd = ecore_main_fd_handler_fd_get(handler);
711 _D("[candidate] ECORE_FD_GET");
715 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
717 _D("[candidate] ECORE_FD_ERROR");
722 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ))
724 _D("[candidate] ECORE_FD_READ");
726 app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
727 memset(pkt, 0, AUL_SOCK_MAXBUFF);
729 int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0);
733 _D("[condidate] recv error!");
737 _D("[candidate] recv_ret: %d, pkt->len: %d", recv_ret, pkt->len);
739 ecore_main_fd_handler_del(handler);
740 __candidate_process_launchpad_main_loop(pkt, g_argv[0], &g_argc, &g_argv);
741 SECURE_LOGD("[candidate] real app argv[0]: %s, real app argc: %d", g_argv[0], g_argc);
744 ecore_main_loop_quit();
745 _D("[candidate] ecore main loop quit");
748 return ECORE_CALLBACK_CANCEL;
751 _static_ void __prepare_candidate_process(int main_fd, int pool_fd, int client_fd)
755 last_dummy_exec_time = time(NULL);
759 if (pid == 0) // child
761 setpriority(PRIO_PROCESS, 0, LOWEST_PRIO);
762 _D("[candidate] Another candidate process was forked.");
764 //temp - this requires some optimization.
766 _D("sleeping 1 sec...");
768 /* Set new session ID & new process group ID*/
769 /* In linux, child can set new session ID without check permission */
770 /* TODO : should be add to check permission in the kernel*/
788 __signal_unset_sigchld();
791 /* SET PR_SET_KEEPCAPS */
792 if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
793 _E("prctl(PR_SET_KEEPCAPS) failed.");
796 /* SET DUMPABLE - for coredump*/
797 prctl(PR_SET_DUMPABLE, 1);
799 int client_fd = __connect_candidate_process();
802 _D("Connecting to candidate process was failed.");
806 // Temporarily change HOME path to app
807 // This change is needed for getting elementary profile
808 // /opt/home/app/.elementary/config/mobile/base.cfg
809 setenv(HOME, APP_HOME_PATH, 1);
810 _D("[candidate] elm_init()");
811 elm_init(g_argc, g_argv);
812 setenv(HOME, ROOT_HOME_PATH, 1);
814 Evas_Object *eo = elm_win_add(NULL, "package_name", ELM_WIN_BASIC);
815 aul_set_preinit_window(eo);
817 Ecore_Fd_Handler* fd_handler = ecore_main_fd_handler_add(client_fd,
818 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ|ECORE_FD_ERROR),
819 __candidate_proces_fd_handler, NULL, NULL, NULL);
820 if (fd_handler == NULL)
822 _D("fd_handler is NULL");
826 setpriority(PRIO_PROCESS, 0, 0);
828 _D("[candidate] ecore main loop begin");
829 ecore_main_loop_begin();
832 int (*dl_main) (int, char **);
834 SECURE_LOGD("[candidate] Launch real application (%s)", g_argv[0]);
835 handle = dlopen(g_argv[0], RTLD_LAZY | RTLD_GLOBAL);
838 _E("dlopen failed (%s).", dlerror());
843 dl_main = dlsym(handle, "main");
846 dl_main(g_argc, g_argv);
850 _E("dlsym not founded. bad preloaded app - check fpie pie");
858 static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
859 const char *pkgname, bundle *kb)
861 app_info_from_db *menu_info;
863 menu_info = calloc(1, sizeof(app_info_from_db));
864 if (menu_info == NULL) {
868 menu_info->pkg_name = strdup(pkgname);
869 menu_info->app_path = strdup(bundle_get_val(kb, AUL_K_EXEC));
870 if (menu_info->app_path != NULL)
871 menu_info->original_app_path = strdup(menu_info->app_path);
872 menu_info->pkg_type = strdup(bundle_get_val(kb, AUL_K_PACKAGETYPE));
873 menu_info->hwacc = strdup(bundle_get_val(kb, AUL_K_HWACC));
874 menu_info->taskmanage = strdup(bundle_get_val(kb, AUL_K_TASKMANAGE));
876 if (!_get_app_path(menu_info)) {
877 _free_app_info_from_db(menu_info);
884 _static_ void __launchpad_main_loop(int main_fd, int pool_fd)
887 app_pkt_t *pkt = NULL;
888 app_info_from_db *menu_info = NULL;
890 const char *pkg_name = NULL;
891 const char *app_path = NULL;
895 int is_real_launch = 0;
897 char sock_path[UNIX_PATH_MAX] = {0,};
899 pkt = __app_recv_raw(main_fd, &clifd, &cr);
901 _D("packet is NULL");
905 kb = bundle_decode(pkt->data, pkt->len);
907 _D("bundle decode error");
912 PERF("packet processing start");
914 pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
915 SECURE_LOGD("pkg name : %s\n", pkg_name);
917 menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
918 if (menu_info == NULL) {
919 _D("such pkg no found");
923 app_path = _get_app_path(menu_info);
924 if(app_path == NULL) {
925 _E("app_path is NULL");
928 if (app_path[0] != '/') {
929 _D("app_path is not absolute path");
933 __modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
934 pkg_name = _get_pkgname(menu_info);
936 PERF("get package information & modify bundle done");
938 if (candidate_pid != DUMMY_NONE)
940 snprintf(sock_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, candidate_pid);
943 __candidate_process_real_launch(candidate_fd, pkt);
944 _D("Request real launch to candidate_process.");
950 candidate_pid = DUMMY_NONE;
953 /* Temporary log: launch time checking */
954 //LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:launchpad:done]", app_path);
956 __prepare_candidate_process(main_fd, pool_fd, clifd);
958 SECURE_LOGD("Prepare candidate process, pid: %d, bin path: %s\n", pid, app_path);
967 _E("lock up test log(no error) : fork done");
971 __signal_unset_sigchld();
974 snprintf(sock_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, getpid());
977 PERF("prepare exec - first done");
978 _E("lock up test log(no error) : prepare exec - first done");
980 if (__prepare_exec(pkg_name, app_path,
983 SECURE_LOGE("preparing work fail to launch - "
984 "can not launch %s\n", pkg_name);
988 PERF("prepare exec - second done");
989 _E("lock up test log(no error) : prepare exec - second done");
991 __real_launch(app_path, kb);
995 _D("==> real launch pid : %d %s\n", pid, app_path);
1000 __send_result_to_caller(clifd, pid);
1003 if (is_real_launch) {
1005 __signal_block_sigchld();
1006 __send_app_launch_signal(pid);
1007 __signal_unblock_sigchld();
1011 if (menu_info != NULL)
1012 _free_app_info_from_db(menu_info);
1019 /* Active Flusing for Daemon */
1020 if (initialized > AUL_POLL_CNT) {
1021 sqlite3_release_memory(SQLITE_FLUSH_MAX);
1028 _static_ int __launchpad_pre_init(int argc, char **argv)
1035 /* get my(launchpad) command line*/
1036 launchpad_cmdline = __proc_get_cmdline_bypid(getpid());
1037 if (launchpad_cmdline == NULL) {
1038 _E("launchpad cmdline fail to get");
1041 _D("launchpad cmdline = %s", launchpad_cmdline);
1043 /* create launchpad sock */
1044 fd = __create_server_sock(PROCESS_POOL_LAUNCHPAD_PID);
1046 _E("server sock error");
1050 __preload_init(argc, argv);
1052 __preload_init_for_process_pool();
1054 __preexec_init(argc, argv);
1059 _static_ int __launchpad_post_init()
1061 /* Setting this as a global variable to keep track
1062 of launchpad poll cnt */
1063 /* static int initialized = 0;*/
1070 if (__signal_set_sigchld() < 0)
1078 int main(int argc, char **argv)
1088 struct pollfd pfds[POLLFD_MAX];
1091 memset(pfds, 0x00, sizeof(pfds));
1093 /* init without concerning X & EFL*/
1094 main_fd = __launchpad_pre_init(argc, argv);
1096 _E("launchpad pre init failed");
1100 pfds[LAUNCH_PAD].fd = main_fd;
1101 pfds[LAUNCH_PAD].events = POLLIN;
1102 pfds[LAUNCH_PAD].revents = 0;
1104 pool_fd = __create_candidate_process();
1107 _E("Error creationg pool server!");
1111 pfds[POOL_SERVER].fd = pool_fd;
1112 pfds[POOL_SERVER].events = POLLIN;
1113 pfds[POOL_SERVER].revents = 0;
1116 if (candidate_pid == DUMMY_NONE)
1118 pfds[DUMMY_PROCESS].fd = -1;
1119 pfds[DUMMY_PROCESS].events = 0;
1120 pfds[DUMMY_PROCESS].revents = 0;
1122 if (DIFF(last_dummy_exec_time, time(NULL)) > EXEC_DUMMY_EXPIRED)
1124 __prepare_candidate_process(main_fd, pool_fd, -1);
1128 if (poll(pfds, POLLFD_MAX, -1) < 0)
1131 _D("pfds[LAUNCH_PAD].revents : 0x%x", pfds[LAUNCH_PAD].revents) ;
1132 _D("pfds[POOL_SERVER].revents : 0x%x", pfds[POOL_SERVER].revents) ;
1133 _D("pfds[DUMMY_PROCESS].revents : 0x%x", pfds[DUMMY_PROCESS].revents) ;
1135 /* init with concerning X & EFL (because of booting
1136 * sequence problem)*/
1137 if (__launchpad_post_init() < 0)
1139 _E("launcpad post init failed");
1143 if ((pfds[LAUNCH_PAD].revents & POLLIN) != 0)
1145 _D("pfds[LAUNCH_PAD].revents & POLLIN");
1146 __launchpad_main_loop(pfds[LAUNCH_PAD].fd, pfds[POOL_SERVER].fd);
1149 if ((pfds[POOL_SERVER].revents & POLLIN) != 0)
1151 int server_fd, client_fd, client_pid;
1153 server_fd = pfds[POOL_SERVER].fd;
1155 _D("pfds[POOL_SERVER].revents & POLLIN");
1157 if (candidate_pid == DUMMY_NONE)
1159 __accept_candidate_process(server_fd, &client_fd, &client_pid);
1161 candidate_pid = client_pid;
1162 candidate_fd = client_fd;
1164 pfds[DUMMY_PROCESS].fd = candidate_fd;
1165 pfds[DUMMY_PROCESS].events = POLLIN|POLLHUP;
1166 pfds[DUMMY_PROCESS].revents = 0;
1168 _D("Dummy process was connected! (pid:%d)", candidate_pid);
1172 __refuse_candidate_process(server_fd);
1174 _E("Refused dummy process connection!");
1178 if ((pfds[DUMMY_PROCESS].revents & (POLLHUP|POLLNVAL)) != 0)
1180 _D("pfds[DUMMY_PROCESS].revents & (POLLHUP|POLLNVAL) (pid:%d)", candidate_pid);
1182 if (pfds[DUMMY_PROCESS].fd > -1)
1184 close(pfds[DUMMY_PROCESS].fd);
1187 candidate_pid = DUMMY_NONE;
1190 pfds[DUMMY_PROCESS].fd = -1;
1191 pfds[DUMMY_PROCESS].events = 0;
1192 pfds[DUMMY_PROCESS].revents = 0;