From: Hwankyu Jhun Date: Tue, 15 Dec 2015 00:30:09 +0000 (+0900) Subject: Apply coding rule X-Git-Tag: accepted/tizen/mobile/20151215.083047^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F54300%2F6;p=platform%2Fcore%2Fappfw%2Flaunchpad.git Apply coding rule Change-Id: I08a0324648a099ec3137770a9aec21307f40fcda Signed-off-by: Hwankyu Jhun --- diff --git a/src/launchpad.c b/src/launchpad.c index 59b50fd..a5a1dfa 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -42,7 +42,7 @@ #define AUL_PR_NAME 16 #define EXEC_CANDIDATE_EXPIRED 5 #define EXEC_CANDIDATE_WAIT 1 -#define DIFF(a,b) (((a)>(b))?(a)-(b):(b)-(a)) +#define DIFF(a, b) (((a) > (b)) ? (a) - (b) : (b) - (a)) #define CANDIDATE_NONE 0 #define PROCESS_POOL_LAUNCHPAD_SOCK ".launchpad-process-pool-sock" #define LOADER_PATH_DEFAULT "/usr/bin/launchpad-loader" @@ -150,13 +150,10 @@ static candidate_process_context_t* __find_slot(int type, int loader_id) static void __kill_process(int pid) { - int r = kill(pid, SIGKILL); - - if (r == -1) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; + char err_str[MAX_LOCAL_BUFSZ] = { 0, }; + if (kill(pid, SIGKILL) == -1) _E("send SIGKILL: %s", strerror_r(errno, err_str, sizeof(err_str))); - } } static void __refuse_candidate_process(int server_fd) @@ -181,10 +178,12 @@ error: return; } -static int __accept_candidate_process(int server_fd, int* out_client_fd, - int* out_client_pid) +static int __accept_candidate_process(int server_fd, int *out_client_fd, + int *out_client_pid) { - int client_fd = -1, client_pid = 0, recv_ret = 0; + int client_fd = -1; + int client_pid = 0; + int recv_ret = 0; if (server_fd == -1 || out_client_fd == NULL || out_client_pid == NULL) { _E("arguments error!"); @@ -273,6 +272,9 @@ static int __set_access(const char* appId, const char* pkg_type, static int __get_launchpad_type(const char* internal_pool, const char* hwacc) { + int r; + int sys_hwacc = -1; + if (internal_pool && strncmp(internal_pool, "true", 4) == 0 && hwacc) { if (strncmp(hwacc, "NOT_USE", 7) == 0) { _D("[launchpad] launchpad type: S/W(%d)", LAUNCHPAD_TYPE_SW); @@ -283,23 +285,19 @@ static int __get_launchpad_type(const char* internal_pool, const char* hwacc) return LAUNCHPAD_TYPE_HW; } if (strncmp(hwacc, "SYS", 3) == 0) { - int r; - int sys_hwacc = -1; - - r = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &sys_hwacc); - if (r != VCONF_OK) - _E("failed to get vconf int: %s", VCONFKEY_SETAPPL_APP_HW_ACCELERATION); - - SECURE_LOGD("sys hwacc: %d", sys_hwacc); - - if (sys_hwacc == SETTING_HW_ACCELERATION_ON) { - _D("[launchpad] launchpad type: H/W(%d)", LAUNCHPAD_TYPE_HW); - return LAUNCHPAD_TYPE_HW; - } - if (sys_hwacc == SETTING_HW_ACCELERATION_OFF) { - _D("[launchpad] launchpad type: S/W(%d)", LAUNCHPAD_TYPE_SW); - return LAUNCHPAD_TYPE_SW; - } + r = vconf_get_int(VCONFKEY_SETAPPL_APP_HW_ACCELERATION, &sys_hwacc); + if (r != VCONF_OK) + _E("failed to get vconf int: %s", VCONFKEY_SETAPPL_APP_HW_ACCELERATION); + + SECURE_LOGD("sys hwacc: %d", sys_hwacc); + + if (sys_hwacc == SETTING_HW_ACCELERATION_ON) { + _D("[launchpad] launchpad type: H/W(%d)", LAUNCHPAD_TYPE_HW); + return LAUNCHPAD_TYPE_HW; + } else if (sys_hwacc == SETTING_HW_ACCELERATION_OFF) { + _D("[launchpad] launchpad type: S/W(%d)", LAUNCHPAD_TYPE_SW); + return LAUNCHPAD_TYPE_SW; + } } } @@ -343,9 +341,6 @@ static int __real_send(int clifd, int ret) static void __send_result_to_caller(int clifd, int ret, const char* app_path) { char *cmdline; - int cmdline_changed = 0; - int cmdline_exist = 0; - char sock_path[PATH_MAX]; _W("Check app launching"); @@ -384,7 +379,6 @@ static int __prepare_candidate_process(int type, int loader_id) cpt->last_exec_time = time(NULL); pid = fork(); - if (pid == 0) { /* child */ __signal_unblock_sigchld(); @@ -446,7 +440,7 @@ static int __send_launchpad_loader(candidate_process_context_t *cpc, app_pkt_t * cpc->timer = 0; } - __send_result_to_caller(clifd, pid, app_path); //to AMD + __send_result_to_caller(clifd, pid, app_path); /* to AMD */ if (strcmp("uiapp", comp_type) == 0) cpc->timer = g_timeout_add(5000, __handle_preparing_candidate_process, cpc); @@ -804,9 +798,9 @@ static gboolean __handle_sigchild(gpointer data) static int __dispatch_cmd_visibility(bundle *kb) { - _W("cmd visibility"); GList *iter = candidate_slot_list; + _W("cmd visibility"); while (iter) { candidate_process_context_t *cpc = (candidate_process_context_t*)iter->data; @@ -826,17 +820,17 @@ static int __dispatch_cmd_visibility(bundle *kb) static int __dispatch_cmd_add_loader(bundle *kb) { - _W("cmd add loader"); const char *add_slot_str = NULL; const char *caller_pid = NULL; + int lid; + _W("cmd add loader"); add_slot_str = bundle_get_val(kb, AUL_K_LOADER_PATH); caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID); if (add_slot_str && caller_pid) { - int lid = __make_loader_id(); + lid = __make_loader_id(); candidate_process_context_t *cpc = __add_slot(LAUNCHPAD_TYPE_DYNAMIC, lid, atoi(caller_pid), add_slot_str); - if (cpc) cpc->timer = g_timeout_add(2000, __handle_preparing_candidate_process, cpc); @@ -848,12 +842,12 @@ static int __dispatch_cmd_add_loader(bundle *kb) static int __dispatch_cmd_remove_loader(bundle *kb) { - _W("cmd remove loader"); const char *id = bundle_get_val(kb, AUL_K_LOADER_ID); + int lid; + _W("cmd remove loader"); if (id) { - int lid = atoi(id); - + lid = atoi(id); if (__remove_slot(LAUNCHPAD_TYPE_DYNAMIC, lid) == 0) return 0; } @@ -891,23 +885,21 @@ static gboolean __handle_launch_event(gpointer data) } switch (pkt->cmd) { - case PAD_CMD_VISIBILITY: - ret = __dispatch_cmd_visibility(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; - - case PAD_CMD_ADD_LOADER: - ret = __dispatch_cmd_add_loader(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; - - case PAD_CMD_REMOVE_LOADER: - ret = __dispatch_cmd_remove_loader(kb); - __real_send(clifd, ret); - clifd = -1; - goto end; + case PAD_CMD_VISIBILITY: + ret = __dispatch_cmd_visibility(kb); + __real_send(clifd, ret); + clifd = -1; + goto end; + case PAD_CMD_ADD_LOADER: + ret = __dispatch_cmd_add_loader(kb); + __real_send(clifd, ret); + clifd = -1; + goto end; + case PAD_CMD_REMOVE_LOADER: + ret = __dispatch_cmd_remove_loader(kb); + __real_send(clifd, ret); + clifd = -1; + goto end; } INIT_PERF(kb); @@ -1144,18 +1136,17 @@ static int __before_loop(int argc, char **argv) return 0; } +#ifdef _APPFW_FEATURE_PRIORITY_CHANGE static void __set_priority(void) { -#ifdef _APPFW_FEATURE_PRIORITY_CHANGE + char err_str[MAX_LOCAL_BUFSZ] = { 0, }; int res = setpriority(PRIO_PROCESS, 0, -12); - if (res == -1) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; + if (res == -1) SECURE_LOGE("Setting process (%d) priority to -12 failed, errno: %d (%s)", getpid(), errno, strerror_r(errno, err_str, sizeof(err_str))); - } -#endif } +#endif int main(int argc, char **argv) { @@ -1172,7 +1163,9 @@ int main(int argc, char **argv) return -1; } +#ifdef _APPFW_FEATURE_PRIORITY_CHANGE __set_priority(); +#endif g_main_loop_run(mainloop); return -1; diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 31222d8..7ab406f 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -277,7 +277,7 @@ retry_recv: pkt->len = datalen; len = 0; - while ( len != pkt->len ) { + while (len != pkt->len) { ret = recv(*clifd, pkt->data + len, pkt->len - len, 0); if (ret < 0) { _E("recv error %d %d", len, pkt->len); @@ -325,6 +325,7 @@ char *_proc_get_cmdline_bypid(int pid) { char buf[MAX_CMD_BUFSZ]; int ret; + char *ptr; snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); ret = __read_proc(buf, buf, sizeof(buf)); @@ -332,22 +333,21 @@ char *_proc_get_cmdline_bypid(int pid) return NULL; /* support app launched by shell script*/ - if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) { + if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) return strdup(&buf[BINSH_SIZE + 1]); - } else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) { - char* ptr = buf; + else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) { + ptr = buf; - // buf comes with double null-terminated string + /* buf comes with double null-terminated string */ while (1) { - while (*ptr) { + while (*ptr) ptr++; - } ptr++; if (!(*ptr)) break; - // ignore trailing "--" + /* ignore trailing "--" */ if (strncmp(ptr, "-", 1) != 0) break; } @@ -413,6 +413,7 @@ char *_appinfo_get_app_path(appinfo_t *menu_info) { int i = 0; int path_len = -1; + char *tmp_app_path; if (!menu_info || menu_info->app_path == NULL) return NULL; @@ -430,8 +431,8 @@ char *_appinfo_get_app_path(appinfo_t *menu_info) free(menu_info->app_path); menu_info->app_path = NULL; } else if (path_len > 0) { - char *tmp_app_path = malloc(sizeof(char) * (path_len + 1)); - if(tmp_app_path == NULL) + tmp_app_path = malloc(sizeof(char) * (path_len + 1)); + if (tmp_app_path == NULL) return NULL; snprintf(tmp_app_path, path_len + 1, "%s", menu_info->app_path); free(menu_info->app_path); @@ -443,32 +444,39 @@ char *_appinfo_get_app_path(appinfo_t *menu_info) void _appinfo_free(appinfo_t *menu_info) { - if (menu_info != NULL) { - if (menu_info->appid != NULL) - free(menu_info->appid); - if (menu_info->app_path != NULL) - free(menu_info->app_path); - if (menu_info->original_app_path != NULL) - free(menu_info->original_app_path); - if (menu_info->pkg_type != NULL) - free(menu_info->pkg_type); - if (menu_info->hwacc != NULL) - free(menu_info->hwacc); - if (menu_info->taskmanage != NULL) - free(menu_info->taskmanage); - if (menu_info->pkgid != NULL) - free(menu_info->pkgid); - if (menu_info->comp_type != NULL) - free(menu_info->comp_type); - if (menu_info->internal_pool != NULL) - free(menu_info->internal_pool); - - free(menu_info); - } + if (menu_info == NULL) + return; + + if (menu_info->appid != NULL) + free(menu_info->appid); + if (menu_info->app_path != NULL) + free(menu_info->app_path); + if (menu_info->original_app_path != NULL) + free(menu_info->original_app_path); + if (menu_info->pkg_type != NULL) + free(menu_info->pkg_type); + if (menu_info->hwacc != NULL) + free(menu_info->hwacc); + if (menu_info->taskmanage != NULL) + free(menu_info->taskmanage); + if (menu_info->pkgid != NULL) + free(menu_info->pkgid); + if (menu_info->comp_type != NULL) + free(menu_info->comp_type); + if (menu_info->internal_pool != NULL) + free(menu_info->internal_pool); + + free(menu_info); } void _modify_bundle(bundle * kb, int caller_pid, appinfo_t *menu_info, int cmd) { + char *ptr; + char exe[MAX_PATH_LEN]; + int flag; + char key[256]; + char value[256]; + bundle_del(kb, AUL_K_APPID); bundle_del(kb, AUL_K_EXEC); bundle_del(kb, AUL_K_PACKAGETYPE); @@ -480,17 +488,9 @@ void _modify_bundle(bundle * kb, int caller_pid, appinfo_t *menu_info, int cmd) /* Parse app_path to retrieve default bundle*/ if (cmd == PAD_CMD_LAUNCH) { - char *ptr; - char exe[MAX_PATH_LEN]; - int flag; - ptr = menu_info->original_app_path; - flag = __parse_app_path(ptr, exe, sizeof(exe)); if (flag > 0) { - char key[256]; - char value[256]; - ptr += flag; SECURE_LOGD("parsing app_path: EXEC - %s\n", exe); diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index d72292f..8cd52c5 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -45,12 +45,11 @@ static void __at_exit_to_release_bundle() static void __release_appid_at_exit(void) { - if (__appid != NULL) { + if (__appid != NULL) free(__appid); - } - if (__pkgid != NULL) { + + if (__pkgid != NULL) free(__pkgid); - } } static int __set_access(const char* appId, const char* pkg_type, @@ -103,30 +102,27 @@ static int __prepare_exec(const char *appid, const char *app_path, static int __default_launch_cb(bundle *kb, const char *appid, const char *app_path, const char *pkg_type, int loader_type) { + char err_str[MAX_LOCAL_BUFSZ] = { 0, }; #ifdef _APPFW_FEATURE_PRIORITY_CHANGE + int res; const char *high_priority = bundle_get_val(kb, AUL_K_HIGHPRIORITY); - _D("high_priority: %s", high_priority); + _D("high_priority: %s", high_priority); if (strncmp(high_priority, "true", 4) == 0) { - int res = setpriority(PRIO_PROCESS, 0, -10); - if (res == -1) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + res = setpriority(PRIO_PROCESS, 0, -10); + if (res == -1) SECURE_LOGE("Setting process (%d) priority to -10 failed, errno: %d (%s)", - getpid(), errno, strerror_r(errno, err_str, sizeof(err_str))); - } + getpid(), errno, strerror_r(errno, err_str, sizeof(err_str))); } bundle_del(kb, AUL_K_HIGHPRIORITY); #endif if (__prepare_exec(appid, app_path, pkg_type, loader_type) < 0) { _E("__candidate_process_prepare_exec() failed"); - if (access(app_path, F_OK | R_OK)) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + if (access(app_path, F_OK | R_OK)) SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", - app_path, errno, strerror_r(errno, err_str, sizeof(err_str))); - } + app_path, errno, strerror_r(errno, err_str, sizeof(err_str))); + exit(-1); } @@ -142,6 +138,7 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t* pkt, int tmp_argc = 0; char **tmp_argv = NULL; int ret = -1; + int i; kb = bundle_decode(pkt->data, pkt->len); if (!kb) { @@ -220,8 +217,6 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t* pkt, _set_env(menu_info, kb); if (out_app_path != NULL && out_argc != NULL && out_argv != NULL) { - int i = 0; - memset(out_app_path, '\0', strlen(out_app_path)); sprintf(out_app_path, "%s", app_path); @@ -242,17 +237,19 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t* pkt, static void __receiver_cb(int fd) { + int ret = -1; + int recv_ret; + app_pkt_t *pkt; + _D("[candidate] ECORE_FD_READ"); - app_pkt_t* pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF); + pkt = (app_pkt_t*) malloc(sizeof(char) * AUL_SOCK_MAXBUFF); if (!pkt) { _D("[candidate] out of memory1"); exit(-1); } memset(pkt, 0, AUL_SOCK_MAXBUFF); - int ret = -1; - int recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0); - + recv_ret = recv(fd, pkt, AUL_SOCK_MAXBUFF, 0); if (recv_ret == -1) { _D("[condidate] recv error!"); close(fd); @@ -263,10 +260,10 @@ static void __receiver_cb(int fd) __loader_adapter->remove_fd(__loader_user_data, fd); close(fd); - ret = __candidate_process_launchpad_main_loop(pkt, __argv[0], &__argc, &__argv, - __loader_type); - SECURE_LOGD("[candidate] real app argv[0]: %s, real app argc: %d", __argv[0], - __argc); + ret = __candidate_process_launchpad_main_loop(pkt, __argv[0], + &__argc, &__argv, __loader_type); + SECURE_LOGD("[candidate] real app argv[0]: %s, real app argc: %d", + __argv[0], __argc); free(pkt); if (ret >= 0) { @@ -279,16 +276,13 @@ static int __before_loop(int argc, char **argv) { int client_fd; int ret = -1; - #ifdef _APPFW_FEATURE_LOADER_PRIORITY + char err_str[MAX_LOCAL_BUFSZ] = { 0, }; int res = setpriority(PRIO_PROCESS, 0, LOWEST_PRIO); - if (res == -1) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + if (res == -1) SECURE_LOGE("Setting process (%d) priority to %d failed, errno: %d (%s)", getpid(), LOWEST_PRIO, errno, strerror_r(errno, err_str, sizeof(err_str))); - } #endif __preexec_init(argc, argv); @@ -304,12 +298,9 @@ static int __before_loop(int argc, char **argv) #ifdef _APPFW_FEATURE_LOADER_PRIORITY res = setpriority(PRIO_PGRP, 0, 0); - if (res == -1) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + if (res == -1) SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)", getpid(), errno, strerror_r(errno, err_str, sizeof(err_str))); - } #endif client_fd = _connect_to_launchpad(__loader_type, __loader_id); if (client_fd == -1) { @@ -324,13 +315,12 @@ static int __before_loop(int argc, char **argv) static int __after_loop(void) { - if (__loader_callbacks->terminate) { + if (__loader_callbacks->terminate) return __loader_callbacks->terminate(__argc, __argv, __loader_user_data); - } + return -1; } - API int launchpad_loader_main(int argc, char **argv, loader_lifecycle_callback_s *callbacks, loader_adapter_s *adapter, void *user_data) @@ -378,5 +368,3 @@ API int launchpad_loader_main(int argc, char **argv, return __after_loop(); } - - diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index 0afc78b..1dd13c1 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -83,19 +83,17 @@ static void __loader_create_cb(int argc, char **argv, int type, void *user_data) _D("[candidate] elm init, returned: %d", elm_init_cnt); switch (type) { - case LAUNCHPAD_TYPE_SW: - elm_config_accel_preference_set("none"); - __init_window(); - break; - - case LAUNCHPAD_TYPE_HW: - elm_config_accel_preference_set("hw"); - __init_window(); - break; - - case LAUNCHPAD_TYPE_COMMON: - __init_theme(); - break; + case LAUNCHPAD_TYPE_SW: + elm_config_accel_preference_set("none"); + __init_window(); + break; + case LAUNCHPAD_TYPE_HW: + elm_config_accel_preference_set("hw"); + __init_window(); + break; + case LAUNCHPAD_TYPE_COMMON: + __init_theme(); + break; } } @@ -110,6 +108,7 @@ static int __loader_terminate_cb(int argc, char **argv, void *user_data) void *handle = NULL; int res; int (*dl_main)(int, char **); + char err_str[MAX_LOCAL_BUFSZ] = { 0, }; SECURE_LOGD("[candidate] Launch real application (%s)", argv[0]); handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL); @@ -134,19 +133,14 @@ static int __loader_terminate_cb(int argc, char **argv, void *user_data) return res; do_exec: - if (access(argv[0], F_OK | R_OK)) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + if (access(argv[0], F_OK | R_OK)) SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", argv[0], errno, strerror_r(errno, err_str, sizeof(err_str))); - } else { + else { SECURE_LOGD("[candidate] Exec application (%s)", g_argv[0]); - if (execv(argv[0], argv) < 0) { - char err_str[MAX_LOCAL_BUFSZ] = { 0, }; - + if (execv(argv[0], argv) < 0) SECURE_LOGE("execv() failed for file: \"%s\", error: %d (%s)", argv[0], errno, strerror_r(errno, err_str, sizeof(err_str))); - } } return -1; @@ -185,7 +179,7 @@ static void __adapter_loop_quit(void *user_data) } static void __adapter_add_fd(void *user_data, int fd, - loader_receiver_cb receiver) + loader_receiver_cb receiver) { __fd_handler = ecore_main_fd_handler_add(fd, (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_ERROR),