From: Hwankyu Jhun Date: Tue, 3 Nov 2015 02:00:39 +0000 (+0900) Subject: Fix prevent issues and remove compile warning messages X-Git-Tag: accepted/tizen/mobile/20151103.224955^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F50860%2F2;p=platform%2Fcore%2Fappfw%2Faul-1.git Fix prevent issues and remove compile warning messages - Fix buffer overflow - Fix thread-safety issue - Fix dereference null return value Change-Id: I6d1f11e7ce78ab28ea6b6c8b4666e88124c66f4d Signed-off-by: Hwankyu Jhun --- diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index 6524145..cbe3546 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -113,8 +113,10 @@ static int __send_message(int sock, const struct iovec *vec, int vec_size, const sndret = sendmsg(sock, &msg, 0); _D("sendmsg ret : %d", sndret); - if(sndret < 0) return -errno; - else return sndret; + if (sndret < 0) + return -errno; + else + return sndret; } static int __send_result_data(int fd, int cmd, unsigned char *kb_data, int datalen) @@ -168,9 +170,9 @@ static int __send_result_to_client(int fd, int res) static void __real_send(int clifd, int ret) { if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) { - if (errno == EPIPE) { + if (errno == EPIPE) _E("send failed due to EPIPE.\n"); - } + _E("send fail to client"); } @@ -183,7 +185,7 @@ static int __get_caller_pid(bundle *kb) int pid; pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID); - if(pid_str) + if (pid_str) goto end; pid_str = bundle_get_val(kb, AUL_K_CALLER_PID); @@ -211,9 +213,9 @@ static int __foward_cmd(int cmd, bundle *kb, int cr_pid) return AUL_R_ERROR; pgid = getpgid(cr_pid); - if(pgid > 0) { + if (pgid > 0) { snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", pgid); - bundle_del(kb,AUL_K_CALLEE_PID); + bundle_del(kb, AUL_K_CALLEE_PID); bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid); } @@ -270,9 +272,9 @@ static int __app_process_by_pid(int cmd, ret = _term_req_app(pid, clifd); break; case APP_TERM_BY_PID_ASYNC: - if ((ret = __app_send_raw_with_noreply(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) { + if ((ret = __app_send_raw_with_noreply(pid, cmd, (unsigned char *)&dummy, sizeof(int))) < 0) _D("terminate req packet send error"); - } + __real_send(clifd, ret); break; case APP_PAUSE_BY_PID: @@ -317,14 +319,13 @@ static void __handle_agent_dead_signal(struct ucred *pcr) static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct ucred *cr) { - char *caller; char *callee; char *socket_pair_key; int socket_pair_key_len; - int *handles; + int *handles = NULL; struct iovec vec[3]; - int msglen; + int msglen = 0; char buffer[1024]; struct sockaddr_un saddr; char *datacontrol_type; @@ -338,7 +339,6 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc socket_pair_key_len = strlen(caller) + strlen(callee) + 2; socket_pair_key = (char *)calloc(socket_pair_key_len, sizeof(char)); - if (socket_pair_key == NULL) { _E("calloc fail"); goto err_out; @@ -348,9 +348,7 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc _E("socket pair key : %s", socket_pair_key); handles = g_hash_table_lookup(__socket_pair_hash, socket_pair_key); - if (handles == NULL) { - handles = (int *)calloc(2, sizeof(int)); if (socketpair(AF_UNIX, SOCK_STREAM, 0, handles) != 0) { _E("error create socket pair"); @@ -358,7 +356,7 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc goto err_out; } - if(handles[0] == -1) { + if (handles[0] == -1) { _E("error socket open"); __send_result_to_client(clifd, -1); goto err_out; @@ -380,9 +378,8 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc if (datacontrol_type != NULL) { _E("datacontrol_type : %s", datacontrol_type); if (strcmp(datacontrol_type, "consumer") == 0) { - msglen = __send_message(clifd, vec, 1, &handles[0], 1); - if(msglen < 0) { + if (msglen < 0) { _E("Error[%d]: while sending message\n", -msglen); __send_result_to_client(clifd, -1); goto err_out; @@ -394,10 +391,9 @@ static int __dispatch_get_socket_pair(int clifd, const app_pkt_t *pkt, struct uc g_hash_table_remove(__socket_pair_hash, socket_pair_key); } - } - else { + } else { msglen = __send_message(clifd, vec, 1, &handles[1], 1); - if(msglen < 0) { + if (msglen < 0) { _E("Error[%d]: while sending message\n", -msglen); __send_result_to_client(clifd, -1); goto err_out; @@ -730,7 +726,7 @@ static int __dispatch_app_is_running(int clifd, const app_pkt_t *pkt, struct ucr } strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1); ret = _status_app_is_running(appid, cr->uid); - SECURE_LOGD("APP_IS_RUNNING : %s : %d",appid, ret); + SECURE_LOGD("APP_IS_RUNNING : %s : %d", appid, ret); __send_result_to_client(clifd, ret); free(appid); diff --git a/app_launcher.c b/app_launcher.c index 2d331d2..5052bda 100644 --- a/app_launcher.c +++ b/app_launcher.c @@ -279,7 +279,7 @@ int main(int argc, char **argv) print_usage(argv[0]); return -1; } else { - strcpy(args.appid, optarg); + strncpy(args.appid, optarg, sizeof(args.appid) - 1); } op = next_opt; break; diff --git a/feature/preexec.h b/feature/preexec.h index d3baa92..f5b3fc4 100644 --- a/feature/preexec.h +++ b/feature/preexec.h @@ -35,7 +35,7 @@ typedef struct _preexec_list_t { int (*dl_do_pre_exe) (char *, char *); } preexec_list_t; -static void __preexec_list_free() +static void __preexec_list_free(void) { GSList *iter = NULL; preexec_list_t *type_t; @@ -170,11 +170,6 @@ static inline void __preexec_run(const char *pkg_type, const char *appid, } #else - -static void __preexec_list_free() -{ -} - static inline void __preexec_init(int argc, char **argv) { } diff --git a/legacy/preload.h b/legacy/preload.h index 2af9468..b5b0268 100644 --- a/legacy/preload.h +++ b/legacy/preload.h @@ -20,7 +20,7 @@ */ -#ifdef PRELOAD_ACTIVATE +#ifdef PRELOAD_ACTIVATE #include #define PRELOAD_FILE SHARE_PREFIX"/preload_list.txt" @@ -46,9 +46,9 @@ static inline void __preload_init(int argc, char **argv) g_argc = argc; g_argv = argv; - for (i = 0; i < argc; i++) { + for (i = 0; i < argc; i++) max_cmdline_size += (strlen(argv[i]) + 1); - } + _D("max_cmdline_size = %d", max_cmdline_size); preload_list = fopen(PRELOAD_FILE, "rt"); @@ -119,9 +119,8 @@ static inline void __preload_exec(int argc, char **argv) return; handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL); - if (handle == NULL) { + if (handle == NULL) return; - } dl_main = dlsym(handle, "main"); if (dl_main != NULL) { @@ -139,8 +138,13 @@ static inline void __preload_exec(int argc, char **argv) #else -static inline void __preload_init(); -static inline void __preload_exec(int argc, char **argv); +static inline void __preload_init() +{ +} + +static inline void __preload_exec(int argc, char **argv) +{ +} #endif diff --git a/src/app_group.c b/src/app_group.c index 0349fef..229e43a 100644 --- a/src/app_group.c +++ b/src/app_group.c @@ -19,29 +19,24 @@ #include static struct tizen_policy *tz_policy = NULL; -static void -_reg_handle_global(void *data, struct wl_registry *reg, uint32_t id, const char *interface, uint32_t ver) +static void _reg_handle_global(void *data, struct wl_registry *reg, uint32_t id, + const char *interface, uint32_t ver) { - if (!strcmp(interface, "tizen_policy")) - { - tz_policy = wl_registry_bind(reg, - id, - &tizen_policy_interface, - 1); - } + if (!strcmp(interface, "tizen_policy")) { + tz_policy = wl_registry_bind(reg, id, + &tizen_policy_interface, 1); + } } -static void -_reg_handle_global_remove(void *data, struct wl_registry *reg, uint32_t id) +static void _reg_handle_global_remove(void *data, struct wl_registry *reg, + uint32_t id) { - // do nothing - ; + /* do nothing */ } -static const struct wl_registry_listener reg_listener = -{ - _reg_handle_global, - _reg_handle_global_remove +static const struct wl_registry_listener reg_listener = { + _reg_handle_global, + _reg_handle_global_remove }; #endif @@ -88,8 +83,7 @@ SLPAPI void aul_app_group_attach_window(int parent_wid, int child_wid) wl_registry_add_listener(reg, ®_listener, NULL); wl_display_roundtrip(dpy); - if (!tz_policy) - { + if (!tz_policy) { _E("ERR: no tizen_policy global interface"); wl_registry_destroy(reg); wl_display_disconnect(dpy); @@ -103,7 +97,7 @@ SLPAPI void aul_app_group_attach_window(int parent_wid, int child_wid) wl_registry_destroy(reg); wl_display_disconnect(dpy); #else - //ecore_x_icccm_transient_for_set(child_wid, parent_wid); + /* ecore_x_icccm_transient_for_set(child_wid, parent_wid); */ #endif } @@ -118,8 +112,7 @@ SLPAPI void aul_app_group_detach_window(int child_wid) wl_registry_add_listener(reg, ®_listener, NULL); wl_display_roundtrip(dpy); - if (!tz_policy) - { + if (!tz_policy) { _E("ERR: no tz_policy global interface"); wl_registry_destroy(reg); wl_display_disconnect(dpy); @@ -133,7 +126,7 @@ SLPAPI void aul_app_group_detach_window(int child_wid) wl_registry_destroy(reg); wl_display_disconnect(dpy); #else - //ecore_x_icccm_transient_for_unset(child_wid); + /* ecore_x_icccm_transient_for_unset(child_wid); */ #endif } @@ -197,7 +190,7 @@ SLPAPI void aul_app_group_get_group_pids(int leader_pid, int *cnt, int **pids) if (ret != NULL) { *cnt = ret->len / sizeof(int); - if (ret->len > 0 && ret->len <= INT_MAX) { + if (ret->len > 0 && ret->len <= AUL_SOCK_MAXBUFF - 8) { *pids = malloc(ret->len); if (*pids == NULL) { _E("out of memory"); diff --git a/src/app_signal.c b/src/app_signal.c index 53dddca..d8a5203 100644 --- a/src/app_signal.c +++ b/src/app_signal.c @@ -108,7 +108,6 @@ __dbus_signal_filter_session(DBusConnection *conn, DBusMessage *message, void *user_data) { const char *interface; - const char *cooldown_status; int pid = -1; DBusError error; @@ -174,9 +173,8 @@ static int __app_dbus_signal_handler_init(const char *path, if (!system_bus && session_bus_initialized) return 0; - if (system_bus && system_bus_initialized) { + if (system_bus && system_bus_initialized) return __app_dbus_signal_add_rule(system_conn, path, interface); - } dbus_error_init(&error); bus = dbus_bus_get_private(system_bus ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, &error); @@ -449,13 +447,11 @@ SLPAPI int aul_update_freezer_status(int pid, const char *type) end: dbus_error_free(&err); - if (msg) { + if (msg) dbus_message_unref(msg); - } - if (send_conn) { + if (send_conn) dbus_connection_unref(send_conn); - } return ret; @@ -500,9 +496,9 @@ SLPAPI int aul_send_app_launch_request_signal(int pid, const char *appid, const dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } + return ret; } @@ -558,9 +554,8 @@ SLPAPI int aul_send_app_resume_request_signal(int pid, const char *appid, const dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } return ret; } @@ -615,12 +610,10 @@ SLPAPI int aul_send_app_terminate_request_signal(int pid, const char *appid, con dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } return ret; - } SLPAPI int aul_send_app_status_change_signal(int pid, const char *appid, const char *pkgid, const char *status, const char *type) @@ -677,9 +670,8 @@ SLPAPI int aul_send_app_status_change_signal(int pid, const char *appid, const c dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } return ret; } @@ -718,9 +710,9 @@ SLPAPI int aul_send_app_terminated_signal(int pid) dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } + return ret; } @@ -774,9 +766,8 @@ SLPAPI int aul_send_app_group_signal(int owner_pid, int child_pid, const char *c dbus_connection_flush(send_conn); end: - if (msg) { + if (msg) dbus_message_unref(msg); - } return ret; } diff --git a/src/app_sock.c b/src/app_sock.c index 8d2d4f4..e32ce96 100644 --- a/src/app_sock.c +++ b/src/app_sock.c @@ -42,7 +42,7 @@ static int __connect_client_sock(int sockfd, const struct sockaddr *saptr, sockl static inline void __set_sock_option(int fd, int cli) { int size; - struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */ + struct timeval tv = { 5, 200 * 1000 }; /* 5.2 sec */ size = AUL_SOCK_MAXBUFF; setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)); @@ -56,7 +56,6 @@ int __create_server_sock(int pid) struct sockaddr_un saddr; struct sockaddr_un p_saddr; int fd; - mode_t orig_mask; fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); /* support above version 2.6.27*/ @@ -79,7 +78,7 @@ int __create_server_sock(int pid) unlink(saddr.sun_path); /* labeling to socket for SMACK */ - if (getuid() == 0) { // this is meaningful iff current user is ROOT + if (getuid() == 0) { /* this is meaningful iff current user is ROOT */ if (fsetxattr(fd, "security.SMACK64IPOUT", "@", 1, 0) < 0) { /* in case of unsupported filesystem on 'socket' */ /* or permission error by using 'emulator', bypass*/ @@ -469,20 +468,20 @@ static int __recv_message(int sock, struct iovec *vec, int vec_max_size, int *ve /* get the ANCILLARY data */ cmsg = CMSG_FIRSTHDR(&msg); if (cmsg == NULL) { - if(nr_fds != NULL) + if (nr_fds != NULL) *nr_fds = 0; } else { int iter = 0; int fdnum = 0; - for (; cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg), iter ++) { - switch(cmsg->cmsg_type) { - case SCM_RIGHTS: - if (fds != NULL) - fdnum = __get_descriptors(cmsg, &msg, fds, MAX_NR_OF_DESCRIPTORS); - if (nr_fds != NULL) - *nr_fds = fdnum; - break; + for (; cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg), iter++) { + switch (cmsg->cmsg_type) { + case SCM_RIGHTS: + if (fds != NULL) + fdnum = __get_descriptors(cmsg, &msg, fds, MAX_NR_OF_DESCRIPTORS); + if (nr_fds != NULL) + *nr_fds = fdnum; + break; } } } @@ -523,14 +522,14 @@ int __app_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_ if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) { _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno); - if(len > 0) { + if (len > 0) { while (len != datalen + 8) { ret = send(fd, &pkt->data[len - 8], datalen + 8 - len, 0); if (ret < 0) { _E("second send() failed - %d %d (errno: %d)", ret, datalen + 8, errno); - if (errno == EPIPE) { + if (errno == EPIPE) _E("pid:%d, fd:%d\n", pid, fd); - } + close(fd); if (pkt) { free(pkt); @@ -542,9 +541,9 @@ int __app_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_ _D("send() len - %d %d", len, datalen + 8); } } else { - if (errno == EPIPE) { + if (errno == EPIPE) _E("pid:%d, fd:%d\n", pid, fd); - } + close(fd); if (pkt) { free(pkt); @@ -562,8 +561,7 @@ int __app_send_raw_with_fd_reply(int pid, uid_t uid, int cmd, unsigned char *kb_ retry_recv: - if(cmd == APP_GET_SOCKET_PAIR) { - + if (cmd == APP_GET_SOCKET_PAIR) { char recv_buff[1024]; struct iovec vec[3]; int ret = 0; @@ -582,11 +580,10 @@ retry_recv: } else recv_buff[ret] = '\0'; - if(fds_len > 0){ + if (fds_len > 0) { _E("fds : %d", fds[0]); ret_fd[0] = fds[0]; } - } else { len = recv(fd, &res, sizeof(int), 0); if (len == -1) { @@ -870,7 +867,7 @@ app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr) 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); @@ -949,7 +946,7 @@ retry_recv: pkt->len = len; len = 0; - while( len != pkt->len ) { + while (len != pkt->len) { ret = recv(fd, pkt->data + len, pkt->len - len, 0); if (ret < 0) { if (errno == EINTR) { diff --git a/src/miregex.c b/src/miregex.c index 4d2e05f..353e298 100644 --- a/src/miregex.c +++ b/src/miregex.c @@ -56,6 +56,7 @@ static void __free_miregex_file_info(miregex_file_info *info) if (info->regex != NULL) free(info->regex); + if (info->desc != NULL) free(info->desc); @@ -74,12 +75,12 @@ static miregex_file_info *__get_miregex_file_info(const char *path) return NULL; } - info = (miregex_file_info *) malloc(sizeof(miregex_file_info)); - if(info == NULL) { + info = (miregex_file_info *)malloc(sizeof(miregex_file_info)); + if (info == NULL) { fclose(f); return NULL; } - + info->regex = NULL; info->desc = NULL; @@ -96,8 +97,6 @@ static miregex_file_info *__get_miregex_file_info(const char *path) info->desc = strdup(oneline); } - /*_D("conf file process done : info->regex = %s, - info->desc = %s",info->regex, info->desc);*/ fclose(f); return info; @@ -113,7 +112,7 @@ static int __add_miregex(const char *name, const char *regex, const char *desc) if (regex == NULL) return -1; - tbl = (regex_tbl *) malloc(sizeof(regex_tbl)); + tbl = (regex_tbl *)malloc(sizeof(regex_tbl)); if (NULL == tbl) { _E("Malloc failed!"); return -1; @@ -129,6 +128,7 @@ static int __add_miregex(const char *name, const char *regex, const char *desc) free(tbl); tbl = NULL; } + return -1; } regerror(error, &(tbl->regex_preg), msg, ret); @@ -137,10 +137,12 @@ static int __add_miregex(const char *name, const char *regex, const char *desc) free(msg); msg = NULL; } + if (tbl) { free(tbl); tbl = NULL; } + return -1; } @@ -151,8 +153,6 @@ static int __add_miregex(const char *name, const char *regex, const char *desc) tbl->next = miregex_tbl; miregex_tbl = tbl; - /*_D("added regex - %d %s %s##",getpid(),tbl->mimetype,tbl->regex);*/ - return 0; } @@ -202,7 +202,8 @@ static void __miregex_free_regex_table() regex_tbl *miregex_get_regex_table() { DIR *dp; - struct dirent *dentry; + struct dirent dentry; + struct dirent *result = NULL; char buf[MAX_LOCAL_BUFSZ]; miregex_file_info *info; @@ -218,17 +219,17 @@ regex_tbl *miregex_get_regex_table() if (dp == NULL) return NULL; - while ((dentry = readdir(dp)) != NULL) { - if (dentry->d_name[0] == '.') + while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) { + if (dentry.d_name[0] == '.') continue; snprintf(buf, sizeof(buf), "%s/%s", MIREGEX_DIR, - dentry->d_name); + dentry.d_name); info = __get_miregex_file_info(buf); if (info == NULL) continue; - if (__add_miregex(dentry->d_name, + if (__add_miregex(dentry.d_name, info->regex, info->desc) < 0) { /* TODO : invalid regular expression - will be removed*/ } @@ -240,4 +241,3 @@ regex_tbl *miregex_get_regex_table() return miregex_tbl; } - diff --git a/src/service.c b/src/service.c index 8d455c6..e3e49f1 100755 --- a/src/service.c +++ b/src/service.c @@ -68,13 +68,12 @@ pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER; GSList *tmp_list; static aul_svc_cb_info_t *__create_rescb(int request_code, - aul_svc_res_fn cbfunc, - void *data); + aul_svc_res_fn cbfunc, void *data); static void __remove_rescb(aul_svc_cb_info_t *info); static int __set_bundle(bundle *b, const char *key, const char *value); static void __aul_cb(bundle *b, int is_cancel, void *data); static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, - aul_svc_res_fn cbfunc, void *data, uid_t uid); + aul_svc_res_fn cbfunc, void *data, uid_t uid); static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info); static int __free_resolve_info_data(aul_svc_resolve_info_t *info); @@ -101,8 +100,7 @@ static bool __is_special_app(const char *appid) } static aul_svc_cb_info_t *__create_rescb(int request_code, - aul_svc_res_fn cbfunc, - void *data) + aul_svc_res_fn cbfunc, void *data) { aul_svc_cb_info_t* info; @@ -128,42 +126,38 @@ static int __set_bundle(bundle *b, const char *key, const char *value) val = bundle_get_val(b, key); if (val) { - if ( bundle_del(b, key) != 0 ) { + if (bundle_del(b, key) != 0) return AUL_SVC_RET_ERROR; - } } if (!value) return AUL_SVC_RET_EINVAL; - if ( bundle_add(b, key, value) != 0 ) { + if (bundle_add(b, key, value) != 0) return AUL_SVC_RET_ERROR; - } _D("__set_bundle"); return AUL_SVC_RET_OK; } -static int __set_bundle_array(bundle *b, const char *key, const char **value, - int len) +static int __set_bundle_array(bundle *b, const char *key, + const char **value, int len) { int type; type = aul_svc_data_is_array(b, key); if (type == 1) { - if ( bundle_del(b, key) != 0 ) { + if (bundle_del(b, key) != 0) return AUL_SVC_RET_ERROR; - } } if (!value) return AUL_SVC_RET_EINVAL; - if ( bundle_add_str_array(b, key, value, len) != 0 ) { + if (bundle_add_str_array(b, key, value, len) != 0) return AUL_SVC_RET_ERROR; - } _D("__set_bundle_array"); @@ -190,38 +184,34 @@ static void __aul_cb(bundle *b, int is_cancel, void *data) /* find corresponding callback */ cb_info = (aul_svc_cb_info_t*)data; - cb_info->cb_func(b, cb_info->request_code, (aul_svc_result_val)res, - cb_info->data); + cb_info->cb_func(b, cb_info->request_code, + (aul_svc_result_val)res, cb_info->data); __remove_rescb(cb_info); - return; } static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, - aul_svc_res_fn cbfunc, void *data, uid_t uid) + aul_svc_res_fn cbfunc, void *data, uid_t uid) { aul_svc_cb_info_t *cb_info = NULL; int ret = -1; - if ( bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST) != BUNDLE_TYPE_NONE ) { - if ( !aul_svc_get_pkgname(b) ) { + if (bundle_get_type(b, AUL_SVC_K_SELECTOR_EXTRA_LIST) != BUNDLE_TYPE_NONE) { + if (!aul_svc_get_pkgname(b)) pkgname = APP_SELECTOR; - } } - if ( bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR) ) { + if (bundle_get_val(b, AUL_K_FORCE_LAUNCH_APP_SELECTOR)) pkgname = APP_SELECTOR; - } - if ( __is_special_app(pkgname)) { + if (__is_special_app(pkgname)) { bundle_del(b, AUL_SVC_K_CAN_BE_LEADER); bundle_add_str(b, AUL_SVC_K_CAN_BE_LEADER, "true"); bundle_del(b, AUL_SVC_K_REROUTE); bundle_add_str(b, AUL_SVC_K_REROUTE, "true"); bundle_del(b, AUL_SVC_K_RECYCLE); bundle_add_str(b, AUL_SVC_K_RECYCLE, "true"); - } if (cbfunc) { @@ -235,15 +225,13 @@ static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, #ifdef _APPFW_FEATURE_MULTI_INSTANCE const char* data = bundle_get_val(b, AUL_SVC_K_MULTI_INSTANCE); - if (data) { + if (data) SECURE_LOGD("multi_instance value = %s", data); - } - if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) { + if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) ret = aul_launch_app_for_multi_instance(pkgname, b); - } else { + else ret = aul_launch_app(pkgname, b); - } #else ret = aul_launch_app_for_uid(pkgname, b, uid); #endif @@ -277,6 +265,7 @@ static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info) { char *tmp = NULL; + char *saveptr = NULL; char *strtok_buf = NULL; int ret = -1; @@ -346,14 +335,14 @@ static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info) GMatchInfo *match_info; GError *error = NULL; - regex = g_regex_new ("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error); - if (g_regex_match (regex, info->uri, 0, &match_info) == FALSE) { - g_regex_unref (regex); + regex = g_regex_new("^(([^:/?#]+):)?(//([^/?#]*))?", 0, 0, &error); + if (g_regex_match(regex, info->uri, 0, &match_info) == FALSE) { + g_regex_unref(regex); return AUL_SVC_RET_EINVAL; } - info->scheme = g_match_info_fetch (match_info, 2); - info->host = g_match_info_fetch (match_info, 4); + info->scheme = g_match_info_fetch(match_info, 2); + info->host = g_match_info_fetch(match_info, 4); if (info->scheme && info->host) { info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 2); @@ -365,11 +354,11 @@ static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info) } snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE + MAX_HOST_STR_SIZE + 1, - "%s://%s", info->scheme, info->host); + "%s://%s", info->scheme, info->host); } - g_match_info_free (match_info); - g_regex_unref (regex); + g_match_info_free(match_info); + g_regex_unref(regex); } else { info->scheme = strdup("NULL"); @@ -392,20 +381,18 @@ static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info) } tmp = strdup(info->mime); - strtok_buf = strtok(tmp, "/"); + strtok_buf = strtok_r(tmp, "/", &saveptr); if (strtok_buf) strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ - 1); - strtok_buf = strtok(NULL, "/"); + strtok_buf = strtok_r(NULL, "/", &saveptr); if (strtok_buf) strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ - 1); free(tmp); - if (strncmp(info->m_type, "*", 1) == 0) { + if (strncmp(info->m_type, "*", 1) == 0) strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ - 1); - } - if (strncmp(info->s_type, "*", 1) == 0) { + if (strncmp(info->s_type, "*", 1) == 0) strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ - 1); - } info->mime = malloc(MAX_MIME_STR_SIZE); if (info->mime == NULL) { @@ -415,8 +402,8 @@ static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info) return AUL_SVC_RET_ERROR; } - snprintf(info->mime, MAX_MIME_STR_SIZE - 1, "%s/%s", info->m_type, - info->s_type); + snprintf(info->mime, MAX_MIME_STR_SIZE - 1, + "%s/%s", info->m_type, info->s_type); } return 0; @@ -478,7 +465,8 @@ static char* __get_alias_appid(char *appid) } static int __get_list_with_condition_mime_extened(char *op, char *uri, - char *mime, char *m_type, char *s_type, GSList **pkg_list, uid_t uid) + char *mime, char *m_type, char *s_type, + GSList **pkg_list, uid_t uid) { char *tmp; @@ -504,7 +492,8 @@ static int __get_list_with_condition_mime_extened(char *op, char *uri, } static int __get_list_with_condition_mime_extened_with_collation(char *op, - char *uri, char *mime, char *m_type, char *s_type, GSList **pkg_list, uid_t uid) + char *uri, char *mime, char *m_type, + char *s_type, GSList **pkg_list, uid_t uid) { char *tmp; @@ -561,11 +550,11 @@ static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid ret = pkgmgrinfo_appinfo_filter_create(&handle); ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_CATEGORY, category); + PMINFO_APPINFO_PROP_APP_CATEGORY, category); tmp_list = *pkg_list; - ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __app_list_cb, - &app_list, uid); + ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, + __app_list_cb, &app_list, uid); if (ret != PMINFO_R_OK) { pkgmgrinfo_appinfo_filter_destroy(handle); return -1; @@ -583,20 +572,13 @@ static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid return 0; } -static int __appid_compare(gconstpointer data1, gconstpointer data2) -{ - char *a = (char *)data1; - char *b = (char *)data2; - return strcmp(a, b); -} - static int __check_mainapp_mode(char *operation) { return 0; } static int __get_list_with_submode(char *operation, char *win_id, - GSList **pkg_list, uid_t uid) + GSList **pkg_list, uid_t uid) { int ret = 0; int mainapp_mode = 0; @@ -647,9 +629,8 @@ SLPAPI int aul_svc_set_mime(bundle *b, const char *mime) SLPAPI int aul_svc_add_data(bundle *b, const char *key, const char *val) { - if (b == NULL || key == NULL) { + if (b == NULL || key == NULL) return AUL_SVC_RET_EINVAL; - } /* check key for data */ /******************/ @@ -658,11 +639,10 @@ SLPAPI int aul_svc_add_data(bundle *b, const char *key, const char *val) } SLPAPI int aul_svc_add_data_array(bundle *b, const char *key, - const char **val_array, int len) + const char **val_array, int len) { - if (b == NULL || key == NULL) { + if (b == NULL || key == NULL) return AUL_SVC_RET_EINVAL; - } /* check key for data */ /******************/ @@ -670,7 +650,6 @@ SLPAPI int aul_svc_add_data_array(bundle *b, const char *key, return __set_bundle_array(b, key, val_array, len); } - SLPAPI int aul_svc_set_pkgname(bundle *b, const char *pkg_name) { if (b == NULL) { @@ -681,7 +660,6 @@ SLPAPI int aul_svc_set_pkgname(bundle *b, const char *pkg_name) return __set_bundle(b, AUL_SVC_K_PKG_NAME, pkg_name); } - SLPAPI int aul_svc_set_appid(bundle *b, const char *appid) { char *alias_id = NULL; @@ -724,15 +702,13 @@ SLPAPI int aul_svc_set_launch_mode(bundle *b, const char *mode) } SLPAPI int aul_svc_run_service(bundle *b, int request_code, - aul_svc_res_fn cbfunc, - void *data) + aul_svc_res_fn cbfunc, void *data) { return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid()); } SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, - aul_svc_res_fn cbfunc, - void *data, uid_t uid) + aul_svc_res_fn cbfunc, void *data, uid_t uid) { aul_svc_resolve_info_t info; char *pkgname; @@ -777,8 +753,8 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, return ret; } - SECURE_LOGD("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime, - info.scheme); + SECURE_LOGD("op - %s / mime - %s / scheme - %s\n", + info.op, info.origin_mime, info.scheme); ret = _svc_db_check_perm(uid, true); if (ret < 0) { @@ -791,7 +767,7 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri, uid); if (pkgname == NULL) { __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, - info.mime, info.m_type, info.s_type, &pkg_list, uid); + info.mime, info.m_type, info.s_type, &pkg_list, uid); pkg_count = g_slist_length(pkg_list); if (pkg_count > 0) { @@ -812,9 +788,8 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, info.mime, info.m_type, info.s_type, &pkg_list, uid); } - if (info.category) { + if (info.category) __get_list_with_category(info.category, &pkg_list, uid); - } __get_list_with_submode(info.op, info.win_id, &pkg_list, uid); @@ -854,7 +829,7 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, if (pkgname == NULL) { __get_list_with_condition_mime_extened(info.op, info.uri_r_info, - info.mime, info.m_type, info.s_type, &pkg_list, uid); + info.mime, info.m_type, info.s_type, &pkg_list, uid); pkg_count = g_slist_length(pkg_list); if (pkg_count > 0) { __get_list_with_condition_mime_extened(info.op, info.scheme, @@ -869,9 +844,8 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, info.mime, info.m_type, info.s_type, &pkg_list, uid); } - if (info.category) { + if (info.category) __get_list_with_category(info.category, &pkg_list, uid); - } __get_list_with_submode(info.op, info.win_id, &pkg_list, uid); @@ -922,9 +896,8 @@ SLPAPI int aul_svc_run_service_for_uid(bundle *b, int request_code, info.mime, info.m_type, info.s_type, &pkg_list, uid); } - if (info.category) { + if (info.category) __get_list_with_category(info.category, &pkg_list, uid); - } __get_list_with_submode(info.op, info.win_id, &pkg_list, uid); @@ -1003,7 +976,7 @@ SLPAPI int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn, info.mime); __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, - info.mime, info.m_type, info.s_type, &pkg_list, uid); + info.mime, info.m_type, info.s_type, &pkg_list, uid); if (info.uri_r_info) { __get_list_with_condition_mime_extened(info.op, info.uri_r_info, @@ -1022,9 +995,8 @@ SLPAPI int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn, info.mime, info.m_type, info.s_type, &pkg_list, uid); } - if (info.category) { + if (info.category) __get_list_with_category(info.category, &pkg_list, uid); - } __get_list_with_submode(info.op, info.win_id, &pkg_list, uid); @@ -1039,7 +1011,7 @@ SLPAPI int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn, for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { pkgname = iter->data; SECURE_LOGD("PKGNAME : %s\n", pkgname); - if ( iter_fn(pkgname, data) != 0) + if (iter_fn(pkgname, data) != 0) break; g_free(pkgname); } @@ -1077,7 +1049,7 @@ SLPAPI int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn, for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { pkgname = iter->data; - if ( iter_fn(pkgname, data) != 0) + if (iter_fn(pkgname, data) != 0) break; g_free(pkgname); } @@ -1186,16 +1158,13 @@ SLPAPI int aul_svc_send_result(bundle *b, aul_svc_result_val result) } SLPAPI int aul_svc_set_defapp(const char *op, const char *mime_type, - const char *uri, - const char *defapp) + const char *uri, const char *defapp) { return aul_svc_set_defapp_for_uid(op, mime_type, uri, defapp, getuid()); } SLPAPI int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type, - const char *uri, - const char *defapp, - uid_t uid) + const char *uri, const char *defapp, uid_t uid) { int ret; @@ -1209,7 +1178,6 @@ SLPAPI int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type, } ret = _svc_db_add_app(op, mime_type, uri, defapp, uid); - if (ret < 0) return AUL_SVC_RET_ERROR; @@ -1311,7 +1279,7 @@ SLPAPI int aul_svc_allow_transient_app(bundle *b, int wid) } SLPAPI int aul_svc_request_transient_app(bundle *b, int callee_wid, - aul_svc_host_res_fn cbfunc, void *data) + aul_svc_host_res_fn cbfunc, void *data) { return 0; } diff --git a/src/service_db.c b/src/service_db.c index d777c18..a8a538e 100755 --- a/src/service_db.c +++ b/src/service_db.c @@ -38,9 +38,9 @@ #define QUERY_ATTACH "attach database '%s' as Global" #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_control as select * "\ - "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)" + "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)" #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\ - "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)" + "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)" #define QUERY_CREATE_TABLE_APPSVC "create table if not exists appsvc " \ "(operation text, " \ "mime_type text, " \ @@ -91,10 +91,10 @@ static int __mkdir(const char *dir, mode_t mode) snprintf(tmp, sizeof(tmp), "%s", dir); len = strlen(tmp); - if(tmp[len - 1] == '/') + if (tmp[len - 1] == '/') tmp[len - 1] = 0; - for(p = tmp + 1; *p; p++) { - if(*p == '/') { + for (p = tmp + 1; *p; p++) { + if (*p == '/') { *p = 0; ret = mkdir(tmp, mode); if (ret && errno != EEXIST) @@ -102,10 +102,12 @@ static int __mkdir(const char *dir, mode_t mode) *p = '/'; } } + return mkdir(tmp, mode); } -static void __mkdir_for_user(const char* dir, uid_t uid, gid_t gid) { +static void __mkdir_for_user(const char* dir, uid_t uid, gid_t gid) +{ int ret = 0; ret = __mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); @@ -113,8 +115,10 @@ static void __mkdir_for_user(const char* dir, uid_t uid, gid_t gid) { _E("Fail to create directory %s %d", dir, errno); } else if (getuid() == ROOT_UID) { ret = chown(dir, uid, gid); - if (ret == -1) - _E("Fail to chown %s %d.%d, because %s", dir, uid, gid, strerror(errno)); + if (ret == -1) { + _E("Fail to chown %s %d.%d, because %d", + dir, uid, gid, errno); + } } } @@ -137,7 +141,7 @@ static const char *__get_svc_db(uid_t uid) } if (uid_caller == ROOT_UID || uid_caller == uid) - __mkdir_for_user (db_path, uid, gid); + __mkdir_for_user(db_path, uid, gid); return appsvc_db; } @@ -167,7 +171,7 @@ static const char *__get_app_info_db(uid_t uid) } if (uid_caller == ROOT_UID || uid_caller == uid) - __mkdir_for_user (db_path, uid, gid); + __mkdir_for_user(db_path, uid, gid); return app_info_db; } @@ -175,7 +179,6 @@ static const char *__get_app_info_db(uid_t uid) /** * db initialize */ - static int __init(uid_t uid, bool readonly) { int rc; @@ -194,12 +197,12 @@ static int __init(uid_t uid, bool readonly) } rc = sqlite3_exec(svc_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL); - if (SQLITE_OK != rc) { + if (rc != SQLITE_OK) { _E("Fail to change journal mode\n"); goto err; } rc = sqlite3_exec(svc_db, QUERY_CREATE_TABLE_APPSVC, NULL, NULL, NULL); - if(SQLITE_OK!=rc){ + if (rc != SQLITE_OK) { _E("Fail to create tables\n"); goto err; } @@ -212,7 +215,7 @@ err: } static int __collate_appsvc(void *ucol, int str1_len, const void *str1, - int str2_len, const void *str2) + int str2_len, const void *str2) { char *saveptr1 = NULL; char *saveptr2 = NULL; @@ -261,7 +264,7 @@ static int __collate_appsvc(void *ucol, int str1_len, const void *str1, continue; } - if ( (strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0) ) { + if ((strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0)) { SECURE_LOGD("%s %s %s %s %s %s", op, in_op, mime, in_mime, uri, in_uri); if (g_pattern_match_simple(uri, in_uri)) { SECURE_LOGD("in_uri : %s | uri : %s", in_uri, uri); @@ -270,7 +273,7 @@ static int __collate_appsvc(void *ucol, int str1_len, const void *str1, return 0; } } - } while ( (token = strtok_r(NULL, ";", &saveptr1)) ); + } while ((token = strtok_r(NULL, ";", &saveptr1))); free(dup_str1); free(dup_str2); @@ -300,20 +303,21 @@ static int __init_app_info_db(uid_t uid) goto err; } - rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, - NULL); + rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST", + NULL, NULL, NULL); if (SQLITE_OK != rc) { _D("Fail to change journal mode\n"); goto err; } - sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8, NULL, - __collate_appsvc); + sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8, + NULL, __collate_appsvc); return 0; err: sqlite3_close(app_info_db); app_info_db = NULL; + return -1; } @@ -330,15 +334,21 @@ static int __fini(void) int _svc_db_check_perm(uid_t uid, bool readonly) { int ret = 0; + const char *db; + if (__init(uid, readonly) < 0) return -1; - ret = access(__get_svc_db(uid), readonly ? R_OK : (R_OK | W_OK)); + db = __get_svc_db(uid); + if (db == NULL) + return -1; + + ret = access(db, readonly ? R_OK : (R_OK | W_OK)); return ret; } int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, - const char *pkg_name, uid_t uid) + const char *pkg_name, uid_t uid) { char m[BUF_MAX_LEN]; char u[URI_MAX_LEN]; @@ -350,7 +360,7 @@ int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, if (__init(uid, false) < 0) return -1; - if (op == NULL ) + if (op == NULL) return -1; if (mime_type == NULL) @@ -365,7 +375,7 @@ int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, result = sqlite3_prepare_v2(svc_db, insert_query, strlen(insert_query), - &p_statement, NULL); + &p_statement, NULL); if (result != SQLITE_OK) { _E("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result, sqlite3_errmsg(svc_db), insert_query); @@ -377,7 +387,6 @@ int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, sqlite3_bind_text(p_statement, 3, u, -1, SQLITE_TRANSIENT); sqlite3_bind_text(p_statement, 4, pkg_name, -1, SQLITE_TRANSIENT); - result = sqlite3_step(p_statement); if (result != SQLITE_DONE) { _E("Sqlite3 error [%d] : <%s> executing statement\n", result, @@ -409,7 +418,7 @@ int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid) return -1; result = sqlite3_prepare_v2(svc_db, delete_query, strlen(delete_query), - &p_statement, NULL); + &p_statement, NULL); if (result != SQLITE_OK) { _E("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result, sqlite3_errmsg(svc_db), delete_query); @@ -471,7 +480,7 @@ int _svc_db_is_defapp(const char *pkg_name, uid_t uid) return 0; snprintf(query, QUERY_MAX_LEN, - "select count(*) from appsvc where pkg_name = '%s';", pkg_name); + "select count(*) from appsvc where pkg_name = '%s';", pkg_name); ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL); if (ret != SQLITE_OK) { @@ -481,9 +490,9 @@ int _svc_db_is_defapp(const char *pkg_name, uid_t uid) } ret = sqlite3_step(stmt); - if (ret == SQLITE_ROW) { + if (ret == SQLITE_ROW) cnt = sqlite3_column_int(stmt, 0); - } + sqlite3_finalize(stmt); __fini(); @@ -504,7 +513,7 @@ char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, char* pkgname; char* ret_val = NULL; - if (op == NULL ) + if (op == NULL) return NULL; if (mime_type == NULL) @@ -522,16 +531,15 @@ char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, snprintf(query, QUERY_MAX_LEN, - "select pkg_name from appsvc where operation='%s' and mime_type='%s' and uri='%s'", - \ - op, m, u); + "select pkg_name from appsvc where operation='%s' and mime_type='%s' and uri='%s'", + op, m, u); SECURE_LOGD("query : %s\n", query); ret = sqlite3_prepare(svc_db, query, strlen(query), &stmt, NULL); - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d\n", ret, - sqlite3_extended_errcode(svc_db)); + if (ret != SQLITE_OK) { + _E("prepare error, ret = %d, extended = %d\n", + ret, sqlite3_extended_errcode(svc_db)); goto db_fini; } @@ -554,13 +562,12 @@ char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, SECURE_LOGD("pkgname : %s\n", pkgname); -stmt_finialize : +stmt_finialize: ret = sqlite3_finalize(stmt); - if ( ret != SQLITE_OK) { + if (ret != SQLITE_OK) _D("finalize error(%d)", ret); - } -db_fini : +db_fini: __fini(); return ret_val; @@ -603,16 +610,16 @@ int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pk if (subapp == NULL) continue; - // find if the main app is in the pkg_list + /* find if the main app is in the pkg_list */ mainapp = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare); if (mainapp == NULL) continue; if (win_id && !mainapp_mode) - //subapp mode - remove mainapp from list + /* subapp mode - remove mainapp from list */ excluded_appid = (char *)mainapp->data; else - //mainapp mode - remove subapp from list + /* mainapp mode - remove subapp from list */ excluded_appid = (char *)subapp->data; if (excluded_appid) { @@ -628,7 +635,7 @@ int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id, GSList **pk } int _svc_db_get_list_with_condition(char *op, char *uri, char *mime, - GSList **pkg_list, uid_t uid) + GSList **pkg_list, uid_t uid) { char query[QUERY_MAX_LEN]; sqlite3_stmt* stmt; @@ -642,14 +649,14 @@ int _svc_db_get_list_with_condition(char *op, char *uri, char *mime, return 0; snprintf(query, QUERY_MAX_LEN, - "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control like '%%%s|%s|%s%%' and ai.component_type='uiapp'", - op, uri, mime); + "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control like '%%%s|%s|%s%%' and ai.component_type='uiapp'", + op, uri, mime); SECURE_LOGD("query : %s\n", query); ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL); - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d\n", ret, - sqlite3_extended_errcode(app_info_db)); + if (ret != SQLITE_OK) { + _E("prepare error, ret = %d, extended = %d\n", + ret, sqlite3_extended_errcode(app_info_db)); return -1; } @@ -676,7 +683,7 @@ int _svc_db_get_list_with_condition(char *op, char *uri, char *mime, } int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, - GSList **pkg_list, uid_t uid) + GSList **pkg_list, uid_t uid) { char query[QUERY_MAX_LEN]; sqlite3_stmt* stmt; @@ -686,19 +693,18 @@ int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, char *pkgname = NULL; int found; - if (__init_app_info_db(uid) < 0) { + if (__init_app_info_db(uid) < 0) return 0; - } snprintf(query, QUERY_MAX_LEN, - "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control='%s|%s|%s' collate appsvc_collation and ai.component_type='uiapp'", - op, uri, mime); + "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control='%s|%s|%s' collate appsvc_collation and ai.component_type='uiapp'", + op, uri, mime); SECURE_LOGD("query : %s\n", query); ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL); - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d\n", ret, - sqlite3_extended_errcode(app_info_db)); + if (ret != SQLITE_OK) { + _E("prepare error, ret = %d, extended = %d\n", + ret, sqlite3_extended_errcode(app_info_db)); return -1; } @@ -740,9 +746,9 @@ int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid) snprintf(query, QUERY_MAX_LEN, "select pkg_name from appsvc"); ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL); - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d\n", ret, - sqlite3_extended_errcode(svc_db)); + if (ret != SQLITE_OK) { + _E("prepare error, ret = %d, extended = %d\n", + ret, sqlite3_extended_errcode(svc_db)); return -1; } diff --git a/src/simple_util.c b/src/simple_util.c index 1d7b10a..5db7825 100644 --- a/src/simple_util.c +++ b/src/simple_util.c @@ -183,35 +183,32 @@ char *__proc_get_cmdline_bypid(int pid) if (ret <= 0) return NULL; - /* support app launched by shell script*/ + /* support app launched by shell script */ if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) { return strdup(&buf[BINSH_SIZE + 1]); - } - else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) { + } else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) { char* 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; }; return strdup(ptr); - } - else if (strncmp(buf, BASH_NAME, BASH_SIZE) == 0) { + } else if (strncmp(buf, BASH_NAME, BASH_SIZE) == 0) { if (strncmp(&buf[BASH_SIZE + 1], OPROFILE_NAME, OPROFILE_SIZE) == 0) { - if (strncmp(&buf[BASH_SIZE + OPROFILE_SIZE + 2], OPTION_VALGRIND_NAME, OPTION_VALGRIND_SIZE) == 0) { + if (strncmp(&buf[BASH_SIZE + OPROFILE_SIZE + 2], OPTION_VALGRIND_NAME, OPTION_VALGRIND_SIZE) == 0) return strdup(&buf[BASH_SIZE + OPROFILE_SIZE + OPTION_VALGRIND_SIZE + 3]); - } } } @@ -225,7 +222,7 @@ char *__proc_get_exe_bypid(int pid) ssize_t len; snprintf(buf, sizeof(buf), "/proc/%d/exe", pid); - len=readlink(buf, buf2, MAX_CMD_BUFSZ - 1); + len = readlink(buf, buf2, MAX_CMD_BUFSZ - 1); if (len <= 0) return NULL; buf2[len] = 0; @@ -268,18 +265,18 @@ static inline int __get_pgid_from_stat(int pid) return pid; } -int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv,uid_t uid), - void *priv) +int __proc_iter_pgid(int pgid, int (*iterfunc)(int pid, void *priv, uid_t uid), + void *priv) { DIR *dp; struct dirent *dentry; int _pgid; int ret = -1; uid_t uid; + dp = opendir("/proc"); - if (dp == NULL) { + if (dp == NULL) return -1; - } while ((dentry = readdir(dp)) != NULL) { if (!isdigit(dentry->d_name[0])) @@ -288,7 +285,7 @@ int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv,uid_t uid), _pgid = __get_pgid_from_stat(atoi(dentry->d_name)); if (pgid == _pgid) { uid = __proc_get_usr_bypid(atoi(dentry->d_name)); - ret = iterfunc(atoi(dentry->d_name), priv,uid); + ret = iterfunc(atoi(dentry->d_name), priv, uid); if (ret >= 0) break; } diff --git a/test/aul_test.c b/test/aul_test.c index e00c361..d798656 100644 --- a/test/aul_test.c +++ b/test/aul_test.c @@ -71,9 +71,9 @@ int launch_test() bundle *kb = NULL; kb = create_internal_bundle(3); - if (NULL == kb) { + if (kb == NULL) return -1; - } + printf("[aul_launch_app %d test] %s \n", num++, gargv[2]); ret = aul_launch_app(gargv[2], kb); @@ -92,9 +92,9 @@ int launch_test_for_uid() bundle *kb = NULL; kb = create_internal_bundle(3); - if (NULL == kb) { + if (kb == NULL) return -1; - } + printf("[aul_launch_app %d test] %s \n", num++, gargv[2]); ret = aul_launch_app_for_uid(gargv[2], kb, atoi(gargv[3])); @@ -113,9 +113,8 @@ int dbus_launch_test() kb = create_internal_bundle(3); - if (NULL == kb) { + if (kb == NULL) return -1; - } ret = aul_launch_app(gargv[2], kb); @@ -206,33 +205,6 @@ static test_func_t scn_func[] = { {"n", launch_test, "launch_test", ""} }; -static gboolean run_all_test(void *data) -{ - static int pos = 0; - int ret; - - if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) { - printf("all internal test done\n"); - g_main_loop_quit(mainloop); - return 0; - } - - if (strncmp(scn_func[pos].name, "n", 1) == 0) { - printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc, - gargv[2]); - apn_pid = scn_func[pos].func(); - printf("... return pid = %d\n", apn_pid); - } else { - printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc, - apn_pid); - ret = scn_func[pos].func(); - printf("... return res = %d\n", ret); - } - pos++; - - return 1; -} - int all_test() { static int pos = 0; @@ -562,30 +534,29 @@ int reload_appinfo(void) } static test_func_t test_func[] = { - {"launch",launch_test,"aul_launch_app test", + {"launch", launch_test, "aul_launch_app test", "[usage] launch ..."}, - {"launch_for_uid", launch_test_for_uid, "launch with uid test", - "[usage] launch_for_uid "}, - {"open",open_test,"aul_open_app test", + {"launch_for_uid", launch_test_for_uid, + "launch with uid test", "[usage] launch_for_uid "}, + {"open", open_test, "aul_open_app test", "[usage] open " }, - {"resume",resume_test,"aul_resume_app test", + {"resume", resume_test, "aul_resume_app test", "[usage] resume " }, - {"resume_pid",resume_pid_test,"aul_resume_pid test", + {"resume_pid", resume_pid_test, "aul_resume_pid test", "[usage] resume_pid " }, - {"term_pid", term_pid_test,"aul_terminate_pid test", + {"term_pid", term_pid_test, "aul_terminate_pid test", "[usage] term_pid " }, - {"term_req_pid", term_req_pid_test,"aul_subapp_terminate_request_pid test", + {"term_req_pid", term_req_pid_test, "aul_subapp_terminate_request_pid test", "[usage] term_req_pid " }, {"term_pid_without_restart", term_pid_without_restart_test, "aul_terminate_pid_without_restart test", "[usage] term_pid_without_restart " }, {"term_bgapp", term_bgapp_pid_test, "aul_terminate_bgapp_pid test", "[usage] term_bgapp " }, - {"dbuslaunch", dbus_launch_test,"launch by dbus auto activation", + {"dbuslaunch", dbus_launch_test, "launch by dbus auto activation", "[usage] term_pid " }, - {"all",all_test,"test based on predefine scenario", + {"all", all_test, "test based on predefine scenario", "[usage] all "}, - - {"is_run", is_run_test,"aul_is_running test", + {"is_run", is_run_test, "aul_is_running test", "[usage] is_run "}, {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test", "[usage] getallpkg all"}, @@ -593,7 +564,6 @@ static test_func_t test_func[] = { "[usage] get_app_bypid "}, {"get_pkg_bypid", get_pkg_bypid_test, "aul_app_get_pkgid_bypid test", "[usage] get_pkg_bypid "}, - {"open_file", open_file_test, "aul_open_file test", "[usage] open_file "}, {"open_content", open_content_test, "aul_open_content test", @@ -606,35 +576,26 @@ static test_func_t test_func[] = { "[usage] get_mime_file "}, {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content", "[usage] get_mime_content "}, - {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test", "[usage] get_mime_icon "}, {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test", "[usage] get_mime_desc "}, {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test", "[usage] get_mime_ext "}, - {"test_regex", test_regex, "regular expression parser test", "[usage] test_regex "}, - {"getpkg", get_pkg_func, "get package", - "[usage] getpkg "}, - {"pause", pause_test,"aul_pause_app test", + "[usage] getpkg "}, + {"pause", pause_test, "aul_pause_app test", "[usage] pause " }, - {"pause_pid", pause_pid_test,"aul_pause_pid test", + {"pause_pid", pause_pid_test, "aul_pause_pid test", "[usage] pause_pid " }, {"update_list", update_running_list, "update running list", - "[usage] update_list "}, + "[usage] update_list "}, {"reload", reload_appinfo, "reload appinfo table", "[usage] reload"}, {"get_status_pid", get_status_pid, "aul_app_get_status_bypid test", "[usage] get_status_pid "}, -/* - {"setpkg", set_pkg_func, "set package", - "[usage] setpkg "}, - {"delpkg", del_pkg_func, "del package", - "[usage] getpkg "}, -*/ }; int callfunc(char *testname) @@ -715,7 +676,7 @@ int main(int argc, char **argv) /*aul_listen_app_dead_signal(dead_tracker,NULL); */ /*aul_listen_app_dead_signal(NULL,NULL); */ - g_idle_add(run_func,NULL); + g_idle_add(run_func, NULL); mainloop = g_main_loop_new(NULL, FALSE); if (!mainloop) { diff --git a/test/launch_app.c b/test/launch_app.c index 2e083f9..57c118b 100644 --- a/test/launch_app.c +++ b/test/launch_app.c @@ -42,7 +42,7 @@ static bundle *create_internal_bundle(int start) bundle *kb; int i; char arg[1024] = {0, }; - char* val_array[128]; + char *val_array[128]; kb = bundle_create(); for (i = start; i < gargc - 1; i++) { @@ -51,17 +51,17 @@ static bundle *create_internal_bundle(int start) else { int j = 1; strncpy(arg, gargv[i + 1], 1023); - val_array[0] = strtok(arg,","); - while(1) - { - val_array[j] = strtok(NULL,","); - if(val_array[j] == NULL) + val_array[0] = strtok(arg, ","); + while (1) { + val_array[j] = strtok(NULL, ","); + if (val_array[j] == NULL) break; j++; } - if(j==1) + + if (j == 1) bundle_add(kb, gargv[i], gargv[i + 1]); - else if(j>1) + else if (j > 1) bundle_add_str_array(kb, gargv[i], (const char**)val_array, j); } @@ -79,6 +79,7 @@ int launch(void) printf("bundle creation fail\n"); return -1; } + pid = aul_launch_app(gargv[1], kb); return pid; } @@ -93,7 +94,7 @@ static int __launch_app_dead_handler(int pid, void *data) { int listen_pid = (intptr_t)data; - if(listen_pid == pid) + if (listen_pid == pid) g_main_loop_quit(mainloop); return 0; @@ -108,7 +109,7 @@ static gboolean run_func(void *data) printf("... successfully launched\n"); str = bundle_get_val(kb, "__LAUNCH_APP_MODE__"); - if (str && strcmp(str, "SYNC") == 0 ) + if (str && strcmp(str, "SYNC") == 0) aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)(intptr_t)pid); else g_main_loop_quit(mainloop); @@ -148,4 +149,3 @@ int main(int argc, char **argv) return 0; } -