From: Nikita Kalyazin Date: Fri, 28 Jun 2013 11:34:47 +0000 (+0400) Subject: [FIX] launch and kill tizen application X-Git-Tag: Tizen_SDK_2.3~329^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5233e40625037a49eb1263a26ab400576ed08de3;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [FIX] launch and kill tizen application Tested only for tizen applications. Bugs: - calculator: segfault (it is so even for vanilla version); - yandex maps; - other applications if use without reboot. Works: - setting; - browser; - contacts; - metro tizen. Works with: - probe: 5cbcd39327e3bac3596bd217c0c05b65dbe07c2b --- diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index 1943ecf..e3d93ec 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -79,7 +79,7 @@ struct app_inst_t app_inst; struct prof_session_t prof_session; */ -static struct prof_session_t prof_session; +struct prof_session_t prof_session; static void print_app_info( struct app_info_t *app_info); static void print_conf(struct conf_t * conf); @@ -1071,9 +1071,10 @@ int hostMessageHandle(struct msg_t *msg) return -1; } - // TODO: start_sampling_thread() - if (samplingStart() < 0) + if (startProfiling(prof_session.conf.use_features) < 0) { + sendACKToHost(ID, ERR_CANNOT_START_PROFILING, 0, 0); return -1; + } // TODO: exec app @@ -1083,6 +1084,7 @@ int hostMessageHandle(struct msg_t *msg) sendACKToHost(ID,ERR_NO,0,0); break; case NMSG_STOP: + terminate_all(); sendACKToHost(ID,ERR_NO,0,0); // TODO: remove_prof_session() close_buf(); diff --git a/daemon/da_protocol.h b/daemon/da_protocol.h index a9cd320..0d122a5 100644 --- a/daemon/da_protocol.h +++ b/daemon/da_protocol.h @@ -115,6 +115,11 @@ struct msg_t { char *payload; }; +enum app_type_t { + APP_TYPE_TIZEN = 1, + APP_TYPE_RUNNING = 2, + APP_TYPE_COMMON = 3, +}; struct app_info_t { uint32_t app_type; char *app_id; @@ -328,4 +333,6 @@ int open_buf(void); void close_buf(void); void free_sys_info(struct system_info_t *sys_info); +extern struct prof_session_t prof_session; + #endif /* _DA_PROTOCOL_ */ diff --git a/daemon/daemon.c b/daemon/daemon.c index 6e12833..f00d5a2 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -348,9 +348,9 @@ static int sendACKCodeToHost(enum HostMessageType resp, int msgcode) // start and terminate control functions // ======================================================================================== -static int startProfiling(long launchflag) +int startProfiling(long launchflag) { - char execPath[PATH_MAX]; + const struct app_info_t *app_info = &prof_session.app_info; // remove previous screen capture files remove_indir(SCREENSHOT_DIR); @@ -360,22 +360,34 @@ static int startProfiling(long launchflag) #endif manager.config_flag = launchflag; -#ifdef RUN_APP_LOADER - strcpy(execPath, manager.appPath); -#else - get_executable(manager.appPath, execPath, PATH_MAX); -#endif - if(samplingStart() < 0) + if (samplingStart() < 0) return -1; - if(exec_app(execPath, get_app_type(manager.appPath)) == 0) - { + switch (app_info->app_type) { + case APP_TYPE_TIZEN: + if (exec_app_tizen(app_info->app_id, app_info->exe_path)) { + LOGE("Cannot exec tizen app %s\n", app_info->app_id); + samplingStop(); + return -1; + } + break; + case APP_TYPE_RUNNING: + // TODO: nothing, it's running + break; + case APP_TYPE_COMMON: + if (exec_app_common(app_info->exe_path)) { + LOGE("Cannot exec common app %s\n", app_info->exe_path); + samplingStop(); + return -1; + } + break; + default: + LOGE("Unknown app type %d\n", app_info->app_type); samplingStop(); return -1; + break; } - LOGI("Timer Started\n"); - return 0; } @@ -423,7 +435,7 @@ static void terminate_all_target() } // terminate all target and wait for threads -static void terminate_all() +void terminate_all() { int i; terminate_all_target(); @@ -796,73 +808,8 @@ static int deviceEventHandlerNew(input_dev* dev, int input_type) // return -11 if all target process closed static int targetEventHandler(int epollfd, int index, uint64_t msg) { - msg_t log; - if(msg & EVENT_PID) { - if(index == 0) // assume index 0 is main application process - { - int base_address; - char tempBuff[DA_MSG_MAX]; - char tempBuff2[DA_MSG_MAX]; - char tempPath[PATH_MAX]; - - get_executable(manager.appPath, tempPath, PATH_MAX); - if(realpath(tempPath, tempBuff) == NULL) - { - LOGW("Failed to get realpath of app\n"); - strcpy(tempBuff, tempPath); - } - - sprintf(tempPath, "/proc/%d/maps", manager.target[index].pid); - sprintf(tempBuff2, "cat %s | grep %s | cut -d\"-\" -f1 > %s", - tempPath, tempBuff, DA_BASE_ADDRESS); - LOGI("base address command is %s\n", tempBuff2); - - do { - if(access(tempPath, F_OK) != 0) - return -1; - if(is_same_app_process(manager.appPath, manager.target[index].pid) == 0) - return -1; - - system(tempBuff2); - if(get_app_base_address(&base_address) == 1) - break; - sleep(0); - } while(1); - - tempPath[0] = '\0'; - get_app_install_path(tempPath, PATH_MAX); - -#ifndef LOCALTEST - get_device_info(tempBuff, DA_MSG_MAX); -#endif - - log.type = MSG_DEVICE; - if (strlen(tempPath) > 0) - { - get_executable(manager.appPath, tempBuff2, DA_MSG_MAX); - log.length = sprintf(log.data, "%s`,%d`,%Lu`,%d`,%u`,%d`,%s/%s", tempBuff, - manager.target[index].pid, manager.target[index].starttime, - is_app_built_pie(), base_address, get_app_type(manager.appPath), - tempPath, get_app_name(tempBuff2)); - } - else - { - log.length = sprintf(log.data, "%s`,%d`,%Lu`,%d`,%u`,%d`,", tempBuff, - manager.target[index].pid, manager.target[index].starttime, - is_app_built_pie(), base_address, get_app_type(manager.appPath)); - } - - LOGI("%s\n", log.data); - } - else - { - log.type = MSG_PID; - log.length = sprintf(log.data, "%d`,%Lu", manager.target[index].pid, manager.target[index].starttime); - } - - sendDataToHost(&log); manager.target[index].initial_log = 1; } @@ -874,14 +821,8 @@ static int targetEventHandler(int epollfd, int index, uint64_t msg) terminate_target(index); epoll_ctl(epollfd, EPOLL_CTL_DEL, manager.target[index].event_fd, NULL); setEmptyTargetSlot(index); - if (0 == __sync_sub_and_fetch(&manager.target_count, 1)) // all target client are closed - { - log.type = MSG_TERMINATE; - log.length = 0; - log.data[0] = '\0'; - sendDataToHost(&log); + if (0 == __sync_sub_and_fetch(&manager.target_count, 1)) // all target client are closed return -11; - } } return 0; diff --git a/daemon/daemon.h b/daemon/daemon.h index 8138bae..4b61c3d 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -40,7 +40,6 @@ extern "C" { #define PROTOCOL_VERSION "2.1" #define RUN_APP_LOADER -#define USE_LAUNCH_PAD #define MAX_TARGET_COUNT 8 #define DA_MSG_MAX 4096 diff --git a/daemon/threads.c b/daemon/threads.c index 83ee739..1768be1 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -172,9 +172,6 @@ static void* recvThread(void* data) } } pass = 1; - - if(manager.target[index].pid != -1) - sendDataToHost(&log); } manager.target[index].recv_thread = -1; diff --git a/daemon/utils.c b/daemon/utils.c index e7625ca..caf6a3d 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -341,126 +341,126 @@ int get_manifest_path(const char* exec_path, char* buf, int buflen) // execute applcation with executable binary path // return 0 to fail to execute // return 1 to succeed to execute -#ifdef USE_LAUNCH_PAD -int exec_app(const char* exec_path, int app_type) +int exec_app_tizen(const char *app_id, const char *exec_path) { pid_t pid; char command[PATH_MAX]; char appid[PATH_MAX]; - if (exec_path == NULL || strlen(exec_path) <= 0) - { + if (exec_path == NULL || !strlen(exec_path)) { LOGE("Executable path is not correct\n"); return 0; } - if (( pid = fork()) < 0) // fork error - return 0; - else if(pid > 0) - return 1; // exit parent process with successness - - if(get_appid(exec_path, appid, PATH_MAX) < 0) - { - LOGE("failed to get appid\n"); - return 0; - } - else - { - LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path); - execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, appid, LAUNCH_APP_SDK, DA_PRELOAD_EXEC, NULL); + pid = fork(); + if (pid == -1) return 1; - } + else if (pid > 0) + return 0; // exit parent process with success + + LOGI("launch app path is %s, executable path is %s\n", + LAUNCH_APP_PATH, exec_path); + execl(LAUNCH_APP_PATH, LAUNCH_APP_NAME, app_id, LAUNCH_APP_SDK, + DA_PRELOAD_EXEC, NULL); + + return 0; } -#else -int exec_app(const char* exec_path, int app_type) + +int exec_app_common(const char* exec_path) { - pid_t pid; - int isHwAcc = 0; + pid_t pid; + int hw_acc = 0; char manifest[PATH_MAX]; char command[PATH_MAX]; #ifndef LOCALTEST char appid[SMACK_LABEL_LEN]; #endif - if (exec_path == NULL || strlen(exec_path) <= 0) - { + if (exec_path == NULL || !strlen(exec_path)) { LOGE("Executable path is not correct\n"); - return 0; + return 1; } - if (( pid = fork()) < 0) // fork error - return 0; - - else if(pid > 0) - return 1; // exit parent process with successness + pid = fork(); + if (pid == -1) + return 1; + else if (pid > 0) + return 0; // exit parent process with success - if(get_manifest_path(exec_path, manifest, PATH_MAX) == 0) - { + if (get_manifest_path(exec_path, manifest, PATH_MAX) == 0) { FILE* fp; char buffer[BUFFER_MAX]; char* res; // grep for manifest - sprintf(command, "grep \"HwAcceleration=\\\"On\\\"\" %s", manifest); + sprintf(command, "grep \"HwAcceleration=\\\"On\\\"\" %s", + manifest); fp = popen(command, "r"); - if(fp != NULL) - { + if (fp != NULL) { buffer[0] = '\0'; res = fgets(buffer, BUFFER_MAX, fp); - if(res != NULL && strlen(buffer) != 0) - { - isHwAcc = 1; + if (res != NULL && strlen(buffer) != 0) { + hw_acc = 1; } pclose(fp); } } + // FIXME: I think the followin does not make sense +/* #ifndef LOCALTEST */ +/* if (get_smack_label(exec_path, appid, SMACK_LABEL_LEN - 1) < 0) { */ +/* LOGE("failed to get smack label\n"); */ +/* return 1; */ +/* } else */ +/* #endif */ +/* { */ +/* #ifndef LOCALTEST */ +/* LOGI("smack lable is %s\n", appid); */ +/* if(smack_set_label_for_self(appid) < 0) { */ +/* LOGE("failed to set label for self\n"); */ +/* } */ +/* #endif */ +/* set_appuser_groups(); */ +/* if (setgid(SID_APP) < 0) { */ +/* LOGE("failed to setgid\n"); */ +/* } */ +/* if (setuid(SID_APP) < 0) { */ +/* LOGE("failed to setuid\n"); */ +/* } */ + +/* pid = getpid(); */ +/* if (setpgid(pid, pid) < 0) { */ +/* LOGE("failed to setpgid\n"); */ +/* } */ + +/* if (hw_acc != 0) { */ +/* sprintf(command, "HWACC=USE %s %s", DA_PRELOAD(app_type), exec_path); */ +/* } else { */ +/* sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path); */ +/* } */ + +/* LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path); */ +/* execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); */ +/* return 0; */ +/* } */ + // TODO: + /* if (hw_acc) */ + /* sprintf(command, "HWACC=USE %s %s", */ + /* DA_PRELOAD(app_type), exec_path); */ + /* else */ + /* sprintf(command, "%s %s", */ + /* DA_PRELOAD(app_type), exec_path); */ #ifndef LOCALTEST - if(get_smack_label(exec_path, appid, SMACK_LABEL_LEN - 1) < 0) - { - LOGE("failed to get smack label\n"); - return 0; - } - else -#endif - { -#ifndef LOCALTEST - LOGI("smack lable is %s\n", appid); - if(smack_set_label_for_self(appid) < 0) - { - LOGE("failed to set label for self\n"); - } -#endif - set_appuser_groups(); - if(setgid(SID_APP) < 0) - { - LOGE("failed to setgid\n"); - } - if(setuid(SID_APP) < 0) - { - LOGE("failed to setuid\n"); - } + sprintf(command, "%s %s", + DA_PRELOAD_OSP, exec_path); +#else /* LOCALTEST */ + sprintf(command, "%s", exec_path); +#endif /* LOCALTEST */ - pid = getpid(); - if(setpgid(pid, pid) < 0) - { - LOGE("failed to setpgid\n"); - } - - if(isHwAcc != 0) - { - sprintf(command, "HWACC=USE %s %s", DA_PRELOAD(app_type), exec_path); - } - else - { - sprintf(command, "%s %s", DA_PRELOAD(app_type), exec_path); - } + LOGI("launching commmon app, command: %s\n", command); + execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); - LOGI("launch app path is %s, executable path is %s\n", LAUNCH_APP_PATH, exec_path); - execl(SHELL_CMD, SHELL_CMD, "-c", command, NULL); - return 1; - } + return 0; } -#endif // find process id from executable binary path pid_t find_pid_from_path(const char* path) @@ -511,24 +511,6 @@ void kill_app(const char* binary_path) } } -int get_app_type(char* appPath) -{ - int fd; - char buf[BUFFER_MAX]; - - sprintf(buf, "%s.exe", appPath); - fd = open(buf, O_RDONLY); - if(fd != -1) - { - close(fd); - return APP_TYPE_OSP; - } - else - { - return APP_TYPE_TIZEN; - } -} - int get_executable(char* appPath, char* buf, int buflen) { int fd; diff --git a/daemon/utils.h b/daemon/utils.h index 5032b3b..eecd031 100644 --- a/daemon/utils.h +++ b/daemon/utils.h @@ -51,12 +51,6 @@ extern "C" { #define DA_BUILD_OPTION "/home/developer/sdk_tools/da/da_build_option" #define DA_BASE_ADDRESS "/home/developer/sdk_tools/da/da_base_address" -enum ApplicationType -{ - APP_TYPE_TIZEN = 0, - APP_TYPE_OSP = 1 -}; - uint64_t str_to_uint64(char* str); int64_t str_to_int64(char* str);