From 4233579bdeafa88a6e62c3db63c86d02a019d6ae Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Mon, 4 Jan 2016 14:23:38 +0900 Subject: [PATCH] Adjust coding rules Change-Id: If50b88c2fbcbcd17aa55bda2a14730dcd564e6ff Signed-off-by: Hyunho Kang --- src/badge_service.c | 97 ++++++++++---------------- src/critical_log.c | 19 ++--- src/main.c | 48 +++++-------- src/notification_service.c | 169 +++++++++++++++++---------------------------- src/pkgmgr.c | 60 ++++++---------- src/service_common.c | 144 ++++++++++++++------------------------ src/shortcut_service.c | 20 ++---- src/util.c | 31 ++------- 8 files changed, 201 insertions(+), 387 deletions(-) diff --git a/src/badge_service.c b/src/badge_service.c index 825d264..1636a33 100644 --- a/src/badge_service.c +++ b/src/badge_service.c @@ -59,12 +59,10 @@ struct badge_service { */ static inline char *get_string(char *string) { - if (string == NULL) { + if (string == NULL) return NULL; - } - if (string[0] == '\0') { + if (string[0] == '\0') return NULL; - } return string; } @@ -86,17 +84,15 @@ static void _handler_insert_badge(struct tcb *tcb, struct packet *packet, void * writable_pkg = get_string(writable_pkg); caller = get_string(caller); - if (pkgname != NULL && writable_pkg != NULL && caller != NULL) { + if (pkgname != NULL && writable_pkg != NULL && caller != NULL) ret = badge_db_insert(pkgname, writable_pkg, caller); - } else { + else ret = BADGE_ERROR_INVALID_PARAMETER; - } packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -105,9 +101,8 @@ static void _handler_insert_badge(struct tcb *tcb, struct packet *packet, void * if (ret == BADGE_ERROR_NONE) { packet_service = packet_create("insert_badge", "is", ret, pkgname); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("Failed to send a muticast packet:%d", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("Failed to create a multicast packet"); @@ -133,20 +128,18 @@ static void _handler_delete_badge(struct tcb *tcb, struct packet *packet, void * caller = get_string(caller); if (pkgname != NULL && caller != NULL) { - if (service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification") == 1) { + if (service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification") == 1) ret = badge_db_delete(pkgname, pkgname); - } else { + else ret = badge_db_delete(pkgname, caller); - } } else { ret = BADGE_ERROR_INVALID_PARAMETER; } packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -155,9 +148,8 @@ static void _handler_delete_badge(struct tcb *tcb, struct packet *packet, void * if (ret == BADGE_ERROR_NONE) { packet_service = packet_create("delete_badge", "is", ret, pkgname); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("Failed to send a muticast packet:%d", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("Failed to create a multicast packet"); @@ -183,17 +175,15 @@ static void _handler_set_badge_count(struct tcb *tcb, struct packet *packet, voi pkgname = get_string(pkgname); caller = get_string(caller); - if (pkgname != NULL && caller != NULL) { + if (pkgname != NULL && caller != NULL) ret = badge_db_set_count(pkgname, caller, count); - } else { + else ret = BADGE_ERROR_INVALID_PARAMETER; - } packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -202,9 +192,8 @@ static void _handler_set_badge_count(struct tcb *tcb, struct packet *packet, voi if (ret == BADGE_ERROR_NONE) { packet_service = packet_create("set_badge_count", "isi", ret, pkgname, count); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("Failed to send a muticast packet:%d", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("Failed to create a multicast packet"); @@ -230,17 +219,15 @@ static void _handler_set_display_option(struct tcb *tcb, struct packet *packet, pkgname = get_string(pkgname); caller = get_string(caller); - if (pkgname != NULL && caller != NULL) { + if (pkgname != NULL && caller != NULL) ret = badge_db_set_display_option(pkgname, caller, is_display); - } else { + else ret = BADGE_ERROR_INVALID_PARAMETER; - } packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -249,9 +236,8 @@ static void _handler_set_display_option(struct tcb *tcb, struct packet *packet, if (ret == BADGE_ERROR_NONE) { packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("Failed to send a muticast packet:%d", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("Failed to create a multicast packet"); @@ -279,17 +265,15 @@ static void _handler_set_setting_property(struct tcb *tcb, struct packet *packet property = get_string(property); value = get_string(value); - if (pkgname != NULL && property != NULL && value != NULL) { + if (pkgname != NULL && property != NULL && value != NULL) ret = badge_setting_db_set(pkgname, property, value); - } else { + else ret = BADGE_ERROR_INVALID_PARAMETER; - } packet_reply = packet_create_reply(packet, "ii", ret, ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -297,17 +281,15 @@ static void _handler_set_setting_property(struct tcb *tcb, struct packet *packet if (ret == BADGE_ERROR_NONE) { if (strcmp(property, "OPT_BADGE") == 0) { - if (strcmp(value, "ON") == 0) { + if (strcmp(value, "ON") == 0) is_display = 1; - } else { + else is_display = 0; - } packet_service = packet_create("set_disp_option", "isi", ret, pkgname, is_display); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("Failed to send a muticast packet:%d", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("Failed to create a multicast packet"); @@ -333,25 +315,22 @@ static void _handler_get_setting_property(struct tcb *tcb, struct packet *packet pkgname = get_string(pkgname); property = get_string(property); - if (pkgname != NULL && property != NULL) { + if (pkgname != NULL && property != NULL) ret = badge_setting_db_get(pkgname, property, &value); - } else { + else ret = BADGE_ERROR_INVALID_PARAMETER; - } packet_reply = packet_create_reply(packet, "is", ret, value); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if (value != NULL) { + if (value != NULL) DbgFree(value); - } } } @@ -361,15 +340,13 @@ static void _handler_service_register(struct tcb *tcb, struct packet *packet, vo struct packet *packet_reply; ret = tcb_client_type_set(tcb, TCB_CLIENT_TYPE_SERVICE); - if (ret < 0) { + if (ret < 0) ErrPrint("Failed to set the type of client:%d", ret); - } packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -383,9 +360,8 @@ static void _handler_access_control_error(struct tcb *tcb, struct packet *packet packet_reply = packet_create_reply(packet, "i", BADGE_ERROR_PERMISSION_DENIED); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -466,16 +442,14 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat case PACKET_REQ: /* Need to send reply packet */ for (i = 0; service_req_table[i].cmd; i++) { - if (strcmp(service_req_table[i].cmd, command)) { + if (strcmp(service_req_table[i].cmd, command)) continue; - } #if ENABLE_BS_ACCESS_CONTROL - if (service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification") == 1) { + if (service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification") == 1) service_req_table[i].handler(tcb, packet, data); - } else { + else _handler_access_control_error(tcb, packet); - } #else service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification"); service_req_table[i].handler(tcb, packet, data); @@ -524,9 +498,8 @@ HAPI int badge_service_init(void) HAPI int badge_service_fini(void) { - if (!s_info.svc_ctx) { + if (!s_info.svc_ctx) return SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } service_common_destroy(s_info.svc_ctx); s_info.svc_ctx = NULL; diff --git a/src/critical_log.c b/src/critical_log.c index a671a1b..2bcd507 100644 --- a/src/critical_log.c +++ b/src/critical_log.c @@ -55,9 +55,8 @@ static inline void rotate_log(void) char *filename; int namelen; - if (s_info.nr_of_lines < CONF_MAX_LOG_LINE) { + if (s_info.nr_of_lines < CONF_MAX_LOG_LINE) return; - } s_info.file_id = (s_info.file_id + 1) % CONF_MAX_LOG_FILE; @@ -65,17 +64,14 @@ static inline void rotate_log(void) filename = malloc(namelen); if (filename) { snprintf(filename, namelen, "%s/%d_%s.%d", CONF_LOG_PATH, s_info.file_id, s_info.filename, getpid()); - if (s_info.fp) { - if (fclose(s_info.fp) != 0) { + if (fclose(s_info.fp) != 0) ErrPrint("fclose: %d\n", errno); - } } s_info.fp = fopen(filename, "w+"); - if (!s_info.fp) { + if (!s_info.fp) ErrPrint("Failed to open a file: %s\n", filename); - } DbgFree(filename); } @@ -90,9 +86,8 @@ HAPI int critical_log(const char *func, int line, const char *fmt, ...) va_list ap; int ret; - if (!s_info.fp) { + if (!s_info.fp) return SERVICE_COMMON_ERROR_IO_ERROR; - } CRITICAL_SECTION_BEGIN(&s_info.cri_lock); @@ -118,9 +113,8 @@ HAPI int critical_log_init(const char *name) int namelen; char *filename; - if (s_info.fp) { + if (s_info.fp) return SERVICE_COMMON_ERROR_NONE; - } s_info.filename = strdup(name); if (!s_info.filename) { @@ -163,9 +157,8 @@ HAPI void critical_log_fini(void) } if (s_info.fp) { - if (fclose(s_info.fp) != 0) { + if (fclose(s_info.fp) != 0) ErrPrint("fclose: %d\n", errno); - } s_info.fp = NULL; } } diff --git a/src/main.c b/src/main.c index f6fbf8c..602a5d9 100644 --- a/src/main.c +++ b/src/main.c @@ -47,20 +47,16 @@ static inline int app_create(void) int ret; ret = shortcut_service_init(); - if (ret < 0) { + if (ret < 0) DbgPrint("shortcut: %d\n", ret); - } ret = notification_service_init(); - if (ret < 0) { + if (ret < 0) DbgPrint("noti: %d\n", ret); - } - ret = badge_service_init(); - if (ret < 0) { + if (ret < 0) DbgPrint("badge: %d\n", ret); - } return 0; } @@ -70,19 +66,16 @@ static inline int app_terminate(void) int ret; ret = badge_service_fini(); - if (ret < 0) { + if (ret < 0) DbgPrint("badge: %d\n", ret); - } ret = notification_service_fini(); - if (ret < 0) { + if (ret < 0) DbgPrint("noti: %d\n", ret); - } ret = shortcut_service_fini(); - if (ret < 0) { + if (ret < 0) DbgPrint("shortcut: %d\n", ret); - } DbgPrint("Terminated\n"); return 0; @@ -92,6 +85,7 @@ static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler) { struct signalfd_siginfo fdsi; ssize_t size; + int cfd; int fd; fd = ecore_main_fd_handler_fd_get(handler); @@ -109,17 +103,12 @@ static Eina_Bool signal_cb(void *data, Ecore_Fd_Handler *handler) } if (fdsi.ssi_signo == SIGTERM) { - int cfd; - CRITICAL_LOG("Terminated(SIGTERM)\n"); - cfd = creat("/tmp/.stop.provider", 0644); - if (cfd < 0 || close(cfd) < 0) { + if (cfd < 0 || close(cfd) < 0) ErrPrint("stop.provider: %d\n", errno); - } vconf_set_bool(VCONFKEY_MASTER_STARTED, 0); - //exit(0); ecore_main_loop_quit(); } else { CRITICAL_LOG("Unknown SIG[%d] received\n", fdsi.ssi_signo); @@ -136,9 +125,8 @@ int main(int argc, char *argv[]) Ecore_Fd_Handler *signal_handler = NULL; /* appcore_agent_terminate */ - if (ecore_init() <= 0) { + if (ecore_init() <= 0) return -EFAULT; - } ecore_app_args_set(argc, (const char **)argv); @@ -147,7 +135,6 @@ int main(int argc, char *argv[]) #endif vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); - util_setup_log_disk(); /*! @@ -155,27 +142,25 @@ int main(int argc, char *argv[]) * Is there any way to print something on the screen? */ ret = critical_log_init(util_basename(argv[0])); - if (ret < 0) { + if (ret < 0) ErrPrint("Failed to init the critical log\n"); - } sigemptyset(&mask); - ret = sigaddset(&mask, SIGTERM); - if (ret < 0) { + if (ret < 0) CRITICAL_LOG("sigaddset: %d\n", errno); - } ret = sigprocmask(SIG_BLOCK, &mask, NULL); - if (ret < 0) { + if (ret < 0) CRITICAL_LOG("sigprocmask: %d\n", errno); - } ret = signalfd(-1, &mask, 0); if (ret < 0) { CRITICAL_LOG("signalfd: %d\n", errno); } else { - signal_handler = ecore_main_fd_handler_add(ret, ECORE_FD_READ, signal_cb, NULL, NULL, NULL); + signal_handler = ecore_main_fd_handler_add( + ret, ECORE_FD_READ, signal_cb, + NULL, NULL, NULL); CRITICAL_LOG("Signal handler initiated: %d\n", ret); } @@ -191,9 +176,8 @@ int main(int argc, char *argv[]) app_terminate(); - if (signal_handler) { + if (signal_handler) ecore_main_fd_handler_del(signal_handler); - } ecore_shutdown(); critical_log_fini(); diff --git a/src/notification_service.c b/src/notification_service.c index 368e220..769ca9e 100644 --- a/src/notification_service.c +++ b/src/notification_service.c @@ -66,12 +66,10 @@ struct noti_service { static inline char *_string_get(char *string) { - if (string == NULL) { + if (string == NULL) return NULL; - } - if (string[0] == '\0') { + if (string[0] == '\0') return NULL; - } return string; } @@ -79,15 +77,16 @@ static inline char *_string_get(char *string) /*! * FUNCTIONS to create packets */ -static inline int _priv_id_get_from_list(int num_data, int *list, int index) { - if (index < num_data) { +static inline int _priv_id_get_from_list(int num_data, int *list, int index) +{ + if (index < num_data) return *(list + index); - } else { + else return -1; - } } -static inline struct packet *_packet_create_with_list(int op_num, int *list, int start_index) { +static inline struct packet *_packet_create_with_list(int op_num, int *list, int start_index) +{ return packet_create( "del_noti_multiple", "iiiiiiiiiii", @@ -120,9 +119,8 @@ static void _handler_insert_noti(struct tcb *tcb, struct packet *packet, notific DbgPrint("priv_id: [%d]\n", priv_id); packet_reply = packet_create_reply(packet, "ii", ret, priv_id); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet: %d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -130,14 +128,13 @@ static void _handler_insert_noti(struct tcb *tcb, struct packet *packet, notific if (ret != NOTIFICATION_ERROR_NONE) { ErrPrint("failed to insert a notification: %d\n", ret); - return ; + return; } packet_service = notification_ipc_make_packet_from_noti(noti, "add_noti", 2); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("failed to create a multicats packet\n"); @@ -172,9 +169,8 @@ static void _handler_update_noti(struct tcb *tcb, struct packet *packet, notific DbgPrint("priv_id: [%d]\n", priv_id); packet_reply = packet_create_reply(packet, "ii", ret, priv_id); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -182,14 +178,13 @@ static void _handler_update_noti(struct tcb *tcb, struct packet *packet, notific if (ret != NOTIFICATION_ERROR_NONE) { ErrPrint("failed to update a notification:%d\n", ret); - return ; + return; } packet_service = notification_ipc_make_packet_from_noti(noti, "update_noti", 2); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } packet_destroy(packet_service); } } @@ -200,11 +195,10 @@ static void _handler_update(struct tcb *tcb, struct packet *packet, void *data) noti = notification_create(NOTIFICATION_TYPE_NOTI); if (noti != NULL) { - if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { + if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) _handler_update_noti(tcb, packet, noti, data); - } else { + else ErrPrint("Failed to create the packet"); - } notification_free(noti); } } @@ -218,11 +212,10 @@ static void _handler_check_noti_by_tag(struct tcb *tcb, struct packet *packet, v if (noti != NULL) { if (notification_ipc_make_noti_from_packet(noti, packet) == NOTIFICATION_ERROR_NONE) { ret = notification_noti_check_tag(noti); - if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) { + if (ret == NOTIFICATION_ERROR_NOT_EXIST_ID) _handler_insert_noti(tcb, packet, noti, data); - } else if (ret == NOTIFICATION_ERROR_ALREADY_EXIST_ID) { + else if (ret == NOTIFICATION_ERROR_ALREADY_EXIST_ID) _handler_update_noti(tcb, packet, noti, data); - } } notification_free(noti); } @@ -231,8 +224,8 @@ static void _handler_check_noti_by_tag(struct tcb *tcb, struct packet *packet, v static void _handler_load_noti_by_tag(struct tcb *tcb, struct packet *packet, void *data) { int ret = 0, ret_p = 0; - char* tag; - char* pkgname; + char *tag; + char *pkgname; struct packet *packet_reply = NULL; notification_h noti = NULL; @@ -242,9 +235,8 @@ static void _handler_load_noti_by_tag(struct tcb *tcb, struct packet *packet, vo ret = notification_noti_get_by_tag(noti, pkgname, tag); packet_reply = notification_ipc_make_reply_packet_from_noti(noti, packet); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet: %d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -253,7 +245,7 @@ static void _handler_load_noti_by_tag(struct tcb *tcb, struct packet *packet, vo if (ret != NOTIFICATION_ERROR_NONE) { ErrPrint("failed to load_noti_by_tag : %d\n", ret); notification_free(noti); - return ; + return; } } else { ErrPrint("Failed to create the packet"); @@ -270,17 +262,15 @@ static void _handler_refresh(struct tcb *tcb, struct packet *packet, void *data) packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet:%d\n", ret); - } } static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void *data) @@ -300,9 +290,8 @@ static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void DbgPrint("priv_id: [%d] num_delete:%d\n", priv_id, num_changes); packet_reply = packet_create_reply(packet, "ii", ret, priv_id); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -310,14 +299,13 @@ static void _handler_delete_single(struct tcb *tcb, struct packet *packet, void if (ret != NOTIFICATION_ERROR_NONE || num_changes <= 0) { ErrPrint("failed to delete a notification:%d %d\n", ret, num_changes); - return ; + return; } packet_service = packet_create("del_noti_single", "ii", 1, priv_id); if (packet_service != NULL) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } packet_destroy(packet_service); } } else { @@ -344,9 +332,8 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi packet_reply = packet_create_reply(packet, "ii", ret, num_deleted); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -354,10 +341,9 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi if (ret != NOTIFICATION_ERROR_NONE) { ErrPrint("failed to delete notifications:%d\n", ret); - if (list_deleted != NULL) { + if (list_deleted != NULL) DbgFree(list_deleted); - } - return ; + return; } if (num_deleted > 0) { @@ -365,9 +351,8 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi packet_service = _packet_create_with_list(num_deleted, list_deleted, 0); if (packet_service) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet: %d\n", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("failed to create a multicast packet\n"); @@ -381,9 +366,8 @@ static void _handler_delete_multiple(struct tcb *tcb, struct packet *packet, voi list_deleted, set * NOTIFICATION_DEL_PACKET_UNIT); if (packet_service) { - if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret_p = service_common_multicast_packet(tcb, packet_service, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet:%d\n", ret_p); - } packet_destroy(packet_service); } else { ErrPrint("failed to create a multicast packet\n"); @@ -418,17 +402,15 @@ static void _handler_noti_property_set(struct tcb *tcb, struct packet *packet, v packet_reply = packet_create_reply(packet, "ii", ret, ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if (ret != NOTIFICATION_ERROR_NONE) { + if (ret != NOTIFICATION_ERROR_NONE) ErrPrint("failed to set noti property:%d\n", ret); - } } else { ErrPrint("Failed to get data from the packet"); } @@ -450,17 +432,15 @@ static void _handler_noti_property_get(struct tcb *tcb, struct packet *packet, v packet_reply = packet_create_reply(packet, "is", ret, value); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if (value != NULL) { + if (value != NULL) DbgFree(value); - } } } @@ -481,17 +461,15 @@ static void _handler_noti_update_setting(struct tcb *tcb, struct packet *packet, packet_reply = packet_create_reply(packet, "ii", ret, ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if (ret != NOTIFICATION_ERROR_NONE) { + if (ret != NOTIFICATION_ERROR_NONE) ErrPrint("failed to update setting[%d]\n", ret); - } } else { ErrPrint("Failed to get data from the packet"); } @@ -511,17 +489,15 @@ static void _handler_noti_update_system_setting(struct tcb *tcb, struct packet * packet_reply = packet_create_reply(packet, "ii", ret, ret); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if (ret != NOTIFICATION_ERROR_NONE) { + if (ret != NOTIFICATION_ERROR_NONE) ErrPrint("failed to update system setting[%d]\n", ret); - } } else { ErrPrint("Failed to get data from the packet"); } @@ -536,9 +512,8 @@ static void _handler_service_register(struct tcb *tcb, struct packet *packet, vo packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); @@ -552,18 +527,15 @@ static void _handler_post_toast_message(struct tcb *tcb, struct packet *packet, packet_reply = packet_create_reply(packet, "i", ret); if (packet_reply) { - if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("failed to send reply packet:%d\n", ret); - } packet_destroy(packet_reply); } else { ErrPrint("failed to create a reply packet\n"); } - if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) { + if ((ret = service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE)) < 0) ErrPrint("failed to send a multicast packet:%d\n", ret); - } - } static void _handler_package_install(struct tcb *tcb, struct packet *packet, void *data) @@ -576,10 +548,8 @@ static void _handler_package_install(struct tcb *tcb, struct packet *packet, voi DbgPrint("package_name [%s]\n", package_name); /* TODO : add codes to add a record to setting table */ - - if (ret != NOTIFICATION_ERROR_NONE) { + if (ret != NOTIFICATION_ERROR_NONE) ErrPrint("failed to update setting[%d]\n", ret); - } } else { ErrPrint("Failed to get data from the packet"); } @@ -595,9 +565,8 @@ static void _permission_check_common(struct tcb *tcb, struct packet *packet) packet_reply = packet_create_reply(packet, "ii", NOTIFICATION_ERROR_PERMISSION_DENIED, 0); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -611,9 +580,8 @@ static void _permission_check_refresh(struct tcb *tcb, struct packet *packet) packet_reply = packet_create_reply(packet, "i", NOTIFICATION_ERROR_PERMISSION_DENIED); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -627,9 +595,8 @@ static void _permission_check_property_get(struct tcb *tcb, struct packet *packe packet_reply = packet_create_reply(packet, "is", NOTIFICATION_ERROR_PERMISSION_DENIED, NULL); if (packet_reply) { - if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) { + if ((ret_p = service_common_unicast_packet(tcb, packet_reply)) < 0) ErrPrint("Failed to send a reply packet:%d", ret_p); - } packet_destroy(packet_reply); } else { ErrPrint("Failed to create a reply packet"); @@ -668,20 +635,18 @@ static void _notification_data_init(void) noti_list = notification_list_get_next(noti_list); } - if (noti_list_head != NULL) { + if (noti_list_head != NULL) notification_free_list(noti_list_head); - } } -static void _notification_init(void) { +static void _notification_init(void) +{ int ret = -1; int restart_count = 0; ret = vconf_get_int(VCONFKEY_MASTER_RESTART_COUNT, &restart_count); - if (ret == 0 && restart_count <= 1) { + if (ret == 0 && restart_count <= 1) _notification_data_init(); - } - } /*! @@ -820,16 +785,14 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat DbgPrint("%p REQ: Command: [%s]\n", tcb, command); for (i = 0; service_req_table[i].cmd; i++) { - if (strcmp(service_req_table[i].cmd, command)) { + if (strcmp(service_req_table[i].cmd, command)) continue; - } if (service_check_privilege_by_socket_fd(tcb_svc_ctx(tcb), tcb_fd(tcb), "http://tizen.org/privilege/notification") == 1) { service_req_table[i].handler(tcb, packet, data); } else { - if (service_req_table[i].handler_access_error != NULL) { + if (service_req_table[i].handler_access_error != NULL) service_req_table[i].handler_access_error(tcb, packet); - } } break; } @@ -838,9 +801,8 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat case PACKET_REQ_NOACK: DbgPrint("%p PACKET_REQ_NOACK: Command: [%s]\n", tcb, command); for (i = 0; service_req_no_ack_table[i].cmd; i++) { - if (strcmp(service_req_no_ack_table[i].cmd, command)) { + if (strcmp(service_req_no_ack_table[i].cmd, command)) continue; - } service_req_no_ack_table[i].handler(tcb, packet, data); break; } @@ -873,17 +835,15 @@ static int _invoke_package_change_event(struct info *notification_service_info, if (event_type == PKGMGR_EVENT_INSTALL) { packet = packet_create_noack("package_install", "s", pkgname); - } - else if (event_type == PKGMGR_EVENT_UNINSTALL){ + } else if (event_type == PKGMGR_EVENT_UNINSTALL) { packet = packet_create_noack("package_uninstall", "s", pkgname); - } - else { + } else { /* Ignore other events */ goto out; } if (packet == NULL) { - ErrPrint("packet_create_noack failed\n");\ + ErrPrint("packet_create_noack failed\n"); ret = -1; goto out; } @@ -906,9 +866,8 @@ static int _package_install_cb(const char *pkgname, enum pkgmgr_status status, d { struct info *notification_service_info = (struct info *)data; - if (status != PKGMGR_STATUS_END) { + if (status != PKGMGR_STATUS_END) return 0; - } _invoke_package_change_event(notification_service_info, PKGMGR_EVENT_INSTALL, pkgname); @@ -919,9 +878,8 @@ static int _package_uninstall_cb(const char *pkgname, enum pkgmgr_status status, { struct info *notification_service_info = (struct info *)data; - if (status != PKGMGR_STATUS_END) { + if (status != PKGMGR_STATUS_END) return 0; - } _invoke_package_change_event(notification_service_info, PKGMGR_EVENT_UNINSTALL, pkgname); @@ -950,18 +908,17 @@ HAPI int notification_service_init(void) notification_setting_refresh_setting_table(); pkgmgr_init(); - pkgmgr_add_event_callback(PKGMGR_EVENT_INSTALL, _package_install_cb, (void*)&s_info); - pkgmgr_add_event_callback(PKGMGR_EVENT_UPDATE, _package_install_cb, (void*)&s_info); - pkgmgr_add_event_callback(PKGMGR_EVENT_UNINSTALL, _package_uninstall_cb, (void*)&s_info); + pkgmgr_add_event_callback(PKGMGR_EVENT_INSTALL, _package_install_cb, (void *)&s_info); + pkgmgr_add_event_callback(PKGMGR_EVENT_UPDATE, _package_install_cb, (void *)&s_info); + pkgmgr_add_event_callback(PKGMGR_EVENT_UNINSTALL, _package_uninstall_cb, (void *)&s_info); DbgPrint("Successfully initiated\n"); return SERVICE_COMMON_ERROR_NONE; } HAPI int notification_service_fini(void) { - if (!s_info.svc_ctx) { + if (!s_info.svc_ctx) return SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } pkgmgr_fini(); diff --git a/src/pkgmgr.c b/src/pkgmgr.c index 18fd5e8..545a167 100644 --- a/src/pkgmgr.c +++ b/src/pkgmgr.c @@ -67,9 +67,8 @@ static inline void invoke_install_event_handler(const char *pkgname, enum pkgmgr struct event_item *item; EINA_LIST_FOREACH(s_info.install_event, l, item) { - if (item->cb) { + if (item->cb) item->cb(pkgname, status, value, item->data); - } } } @@ -79,9 +78,8 @@ static inline void invoke_uninstall_event_handler(const char *pkgname, enum pkgm struct event_item *item; EINA_LIST_FOREACH(s_info.uninstall_event, l, item) { - if (item->cb) { + if (item->cb) item->cb(pkgname, status, value, item->data); - } } } @@ -91,9 +89,8 @@ static inline void invoke_update_event_handler(const char *pkgname, enum pkgmgr_ struct event_item *item; EINA_LIST_FOREACH(s_info.update_event, l, item) { - if (item->cb) { + if (item->cb) item->cb(pkgname, status, value, item->data); - } } } @@ -103,9 +100,8 @@ static inline void invoke_download_event_handler(const char *pkgname, enum pkgmg struct event_item *item; EINA_LIST_FOREACH(s_info.download_event, l, item) { - if (item->cb) { + if (item->cb) item->cb(pkgname, status, value, item->data); - } } } @@ -115,9 +111,8 @@ static inline void invoke_recover_event_handler(const char *pkgname, enum pkgmgr struct event_item *item; EINA_LIST_FOREACH(s_info.recover_event, l, item) { - if (item->cb) { + if (item->cb) item->cb(pkgname, status, value, item->data); - } } } @@ -183,9 +178,8 @@ static struct item *find_item(const char *pkgname) } EINA_LIST_FOREACH(s_info.item_list, l, item) { - if (strcmp(item->pkgname, pkgname)) { + if (strcmp(item->pkgname, pkgname)) continue; - } return item; } @@ -245,13 +239,11 @@ static int icon_path_cb(const char *pkgname, const char *val, void *data) DbgPrint("[%s] %s\n", pkgname, val); item = find_item(pkgname); - if (!item) { + if (!item) return SERVICE_COMMON_ERROR_NOT_EXIST; - } - if (item->icon) { + if (item->icon) DbgFree(item->icon); - } item->icon = strdup(val); if (!item->icon) { @@ -269,9 +261,8 @@ static int command_cb(const char *pkgname, const char *val, void *data) DbgPrint("[%s] %s\n", pkgname, val); item = find_item(pkgname); - if (!item) { + if (!item) return SERVICE_COMMON_ERROR_NOT_EXIST; - } if (!is_valid_status(item, val)) { DbgPrint("Invalid status: %d, %s\n", item->type, val); @@ -291,9 +282,8 @@ static int error_cb(const char *pkgname, const char *val, void *data) DbgPrint("[%s] %s\n", pkgname, val); item = find_item(pkgname); - if (!item) { + if (!item) return SERVICE_COMMON_ERROR_NOT_EXIST; - } item->status = PKGMGR_STATUS_ERROR; invoke_callback(pkgname, item, 0.0f); @@ -308,9 +298,8 @@ static int change_pkgname_cb(const char *pkgname, const char *val, void *data) DbgPrint("[%s] %s\n", pkgname, val); item = find_item(pkgname); - if (!item) { + if (!item) return SERVICE_COMMON_ERROR_NOT_EXIST; - } new_pkgname = strdup(val); if (!new_pkgname) { @@ -354,9 +343,8 @@ static int download_cb(const char *pkgname, const char *val, void *data) } if (val) { - if (sscanf(val, "%lf", &value) != 1) { + if (sscanf(val, "%lf", &value) != 1) value = (double)SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } } else { value = (double)SERVICE_COMMON_ERROR_INVALID_PARAMETER; } @@ -391,9 +379,8 @@ static int progress_cb(const char *pkgname, const char *val, void *data) } if (val) { - if (sscanf(val, "%lf", &value) != 1) { + if (sscanf(val, "%lf", &value) != 1) value = (double)SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } } else { value = (double)SERVICE_COMMON_ERROR_INVALID_PARAMETER; } @@ -409,9 +396,8 @@ static int end_cb(const char *pkgname, const char *val, void *data) DbgPrint("[%s] %s\n", pkgname, val); item = find_item(pkgname); - if (!item) { + if (!item) return SERVICE_COMMON_ERROR_NOT_EXIST; - } item->status = !strcasecmp(val, "ok") ? PKGMGR_STATUS_END : PKGMGR_STATUS_ERROR; @@ -449,9 +435,8 @@ static int pkgmgr_cb(uid_t target_uid, int req_id, const char *type, const char int ret; for (i = 0; handler[i].key; i++) { - if (strcasecmp(key, handler[i].key)) { + if (strcasecmp(key, handler[i].key)) continue; - } ret = handler[i].func(pkgname, val, data); if (ret < 0) { @@ -465,18 +450,15 @@ static int pkgmgr_cb(uid_t target_uid, int req_id, const char *type, const char HAPI int pkgmgr_init(void) { - if (s_info.listen_pc) { + if (s_info.listen_pc) return SERVICE_COMMON_ERROR_ALREADY_EXIST; - } s_info.listen_pc = pkgmgr_client_new(PC_LISTENING); - if (!s_info.listen_pc) { + if (!s_info.listen_pc) return SERVICE_COMMON_ERROR_FAULT; - } - if (pkgmgr_client_listen_status(s_info.listen_pc, pkgmgr_cb, NULL) != PKGMGR_R_OK) { + if (pkgmgr_client_listen_status(s_info.listen_pc, pkgmgr_cb, NULL) != PKGMGR_R_OK) return SERVICE_COMMON_ERROR_FAULT; - } return SERVICE_COMMON_ERROR_NONE; } @@ -486,13 +468,11 @@ HAPI int pkgmgr_fini(void) struct event_item *item; struct item *ctx; - if (!s_info.listen_pc) { + if (!s_info.listen_pc) return SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } - if (pkgmgr_client_free(s_info.listen_pc) != PKGMGR_R_OK) { + if (pkgmgr_client_free(s_info.listen_pc) != PKGMGR_R_OK) return SERVICE_COMMON_ERROR_FAULT; - } s_info.listen_pc = NULL; diff --git a/src/service_common.c b/src/service_common.c index f149e40..1b436f7 100644 --- a/src/service_common.c +++ b/src/service_common.c @@ -120,9 +120,8 @@ static void _initialize_privilege_checker(struct service_context *svc_ctx) /* Cynara structure init */ ret = cynara_initialize(&(svc_ctx->cynara_handle), NULL); - if (ret != CYNARA_API_SUCCESS) { + if (ret != CYNARA_API_SUCCESS) ErrPrint("cynara_initialize failed[%d]\n", ret); - } } static void _finish_privilege_checker(struct service_context *svc_ctx) @@ -130,9 +129,8 @@ static void _finish_privilege_checker(struct service_context *svc_ctx) int ret; ret = cynara_finish(svc_ctx->cynara_handle); - if (ret != CYNARA_API_SUCCESS) { + if (ret != CYNARA_API_SUCCESS) ErrPrint("cynara_initialize failed[%d]\n", ret); - } } HAPI int service_common_send_packet_to_service(struct service_context *svc_ctx, struct tcb *tcb, struct packet *packet) @@ -167,7 +165,6 @@ HAPI int service_common_send_packet_to_service(struct service_context *svc_ctx, } out: - return ret; } @@ -266,9 +263,8 @@ static void *client_packet_pump_main(void *data) case RECV_HEADER: ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); if (ret <= 0) { - if (ret == 0) { + if (ret == 0) ret = -ECANCELED; - } DbgFree(ptr); ptr = NULL; break; @@ -308,9 +304,8 @@ static void *client_packet_pump_main(void *data) case RECV_PAYLOAD: ret = secure_socket_recv(tcb->fd, ptr, size - recv_offset, &tcb->pid); if (ret <= 0) { - if (ret == 0) { + if (ret == 0) ret = -ECANCELED; - } DbgFree(ptr); ptr = NULL; break; @@ -394,9 +389,8 @@ static void *client_packet_pump_main(void *data) * \note * Emit a signal to collect this TCB from the SERVER THREAD. */ - if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) { + if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) ErrPrint("write: %d\n", errno); - } if (ptr) free(ptr); @@ -424,9 +418,8 @@ HAPI int service_register_tcb_callback(struct service_context *svc_ctx, struct t switch (event) { case TCB_EVENT_CREATE: - if (tcb) { + if (tcb) DbgPrint("To catch the create event of TCB does not requires \"tcb\" handle\n"); - } svc_ctx->tcb_create_cb_list = eina_list_append(svc_ctx->tcb_create_cb_list, cbdata); break; case TCB_EVENT_DESTROY: @@ -552,16 +545,14 @@ static inline void tcb_teminate_all(struct service_context *svc_ctx) /*! * ASSERT(tcb->fd >= 0); */ - if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) { + if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) ErrPrint("write: %d\n", errno); - } status = pthread_join(tcb->thid, &ret); - if (status != 0) { + if (status != 0) ErrPrint("Unable to join a thread: %d\n", status); - } else { + else DbgPrint("Thread returns: %p\n", ret); - } secure_socket_destroy_handle(tcb->fd); @@ -572,16 +563,14 @@ static inline void tcb_teminate_all(struct service_context *svc_ctx) HAPI int service_common_destroy_tcb(struct service_context *svc_ctx, struct tcb *tcb) { - if (!svc_ctx || !tcb) { + if (!svc_ctx || !tcb) return SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } /** * @note * In this case, we just need to push terminate event to pipe. */ - if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) { + if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) ErrPrint("write: %d\n", errno); - } return SERVICE_COMMON_ERROR_NONE; } @@ -608,9 +597,8 @@ static inline void tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb) continue; } - if (cbdata->tcb != tcb) { + if (cbdata->tcb != tcb) continue; - } cbdata->cb(svc_ctx, tcb, cbdata->data); @@ -627,16 +615,14 @@ static inline void tcb_destroy(struct service_context *svc_ctx, struct tcb *tcb) * ASSERT(tcb->fd >= 0); * Close the connection, and then collecting the return value of thread */ - if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) { + if (write(tcb->ctrl_pipe[PIPE_WRITE], &ch, sizeof(ch)) != sizeof(ch)) ErrPrint("write: %d\n", errno); - } status = pthread_join(tcb->thid, &ret); - if (status != 0) { + if (status != 0) ErrPrint("Unable to join a thread: %d\n", status); - } else { + else DbgPrint("Thread returns: %p\n", ret); - } secure_socket_destroy_handle(tcb->fd); @@ -660,21 +646,18 @@ static inline int update_fdset(struct service_context *svc_ctx, fd_set *set) fd = svc_ctx->fd; FD_SET(svc_ctx->tcb_pipe[PIPE_READ], set); - if (svc_ctx->tcb_pipe[PIPE_READ] > fd) { + if (svc_ctx->tcb_pipe[PIPE_READ] > fd) fd = svc_ctx->tcb_pipe[PIPE_READ]; - } FD_SET(svc_ctx->evt_pipe[PIPE_READ], set); - if (svc_ctx->evt_pipe[PIPE_READ] > fd) { + if (svc_ctx->evt_pipe[PIPE_READ] > fd) fd = svc_ctx->evt_pipe[PIPE_READ]; - } EINA_LIST_FOREACH(svc_ctx->event_list, l, item) { if (item->type == SERVICE_EVENT_TIMER) { FD_SET(item->info.timer.fd, set); - if (fd < item->info.timer.fd) { + if (fd < item->info.timer.fd) fd = item->info.timer.fd; - } } } @@ -695,27 +678,23 @@ static inline void processing_timer_event(struct service_context *svc_ctx, fd_se EINA_LIST_FOREACH_SAFE(svc_ctx->event_list, l, n, item) { switch (item->type) { case SERVICE_EVENT_TIMER: - if (!FD_ISSET(item->info.timer.fd, set)) { + if (!FD_ISSET(item->info.timer.fd, set)) break; - } if (read(item->info.timer.fd, &expired_count, sizeof(expired_count)) == sizeof(expired_count)) { DbgPrint("Expired %d times\n", expired_count); - if (item->event_cb(svc_ctx, item->cbdata) >= 0) { + if (item->event_cb(svc_ctx, item->cbdata) >= 0) break; - } } else { ErrPrint("read: %d\n", errno); } - if (!eina_list_data_find(svc_ctx->event_list, item)) { + if (!eina_list_data_find(svc_ctx->event_list, item)) break; - } svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); - if (close(item->info.timer.fd) < 0) { + if (close(item->info.timer.fd) < 0) ErrPrint("close: %d\n", errno); - } DbgFree(item); break; default: @@ -800,9 +779,8 @@ static void *server_main(void *data) svc_ctx->processing_service_handler = 1; ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); svc_ctx->processing_service_handler = 0; - if (ret < 0) { + if (ret < 0) ErrPrint("Service thread returns: %d\n", ret); - } packet_destroy(packet_info->packet); DbgFree(packet_info); @@ -838,9 +816,8 @@ static void *server_main(void *data) lockfree_packet_list = NULL; CRITICAL_SECTION_BEGIN(&svc_ctx->packet_list_lock); EINA_LIST_FOREACH_SAFE(svc_ctx->packet_list, l, n, packet_info) { - if (packet_info->tcb != tcb) { + if (packet_info->tcb != tcb) continue; - } svc_ctx->packet_list = eina_list_remove(svc_ctx->packet_list, packet_info); lockfree_packet_list = eina_list_append(lockfree_packet_list, packet_info); @@ -853,9 +830,9 @@ static void *server_main(void *data) svc_ctx->processing_service_handler = 1; ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); svc_ctx->processing_service_handler = 0; - if (ret < 0) { + if (ret < 0) ErrPrint("Service thread returns: %d\n", ret); - } + packet_destroy(packet_info->packet); DbgFree(packet_info); } @@ -895,9 +872,8 @@ static void *server_main(void *data) svc_ctx->processing_service_handler = 1; ret = svc_ctx->service_thread_main(packet_info->tcb, packet_info->packet, svc_ctx->service_thread_data); svc_ctx->processing_service_handler = 0; - if (ret < 0) { + if (ret < 0) ErrPrint("Service thread returns: %d\n", ret); - } packet_destroy(packet_info->packet); DbgFree(packet_info); } @@ -934,13 +910,11 @@ HAPI struct service_context *service_common_create(const char *addr, const char * So, find the scheme length first and then "unlink" it. */ offset = strlen(COM_CORE_LOCAL_SCHEME); - if (strncmp(addr, COM_CORE_LOCAL_SCHEME, offset)) { + if (strncmp(addr, COM_CORE_LOCAL_SCHEME, offset)) offset = 0; - } - if (unlink(addr + offset) < 0) { + if (unlink(addr + offset) < 0) ErrPrint("unlink [%s] - %d\n", addr, errno); - } } svc_ctx = calloc(1, sizeof(*svc_ctx)); @@ -958,13 +932,11 @@ HAPI struct service_context *service_common_create(const char *addr, const char svc_ctx->service_thread_main = service_thread_main; svc_ctx->service_thread_data = data; - if (fcntl(svc_ctx->fd, F_SETFD, FD_CLOEXEC) < 0) { + if (fcntl(svc_ctx->fd, F_SETFD, FD_CLOEXEC) < 0) ErrPrint("fcntl: %d\n", errno); - } - if (fcntl(svc_ctx->fd, F_SETFL, O_NONBLOCK) < 0) { + if (fcntl(svc_ctx->fd, F_SETFL, O_NONBLOCK) < 0) ErrPrint("fcntl: %d\n", errno); - } if (pipe2(svc_ctx->evt_pipe, O_CLOEXEC) < 0) { ErrPrint("pipe2: %d\n", errno); @@ -998,9 +970,9 @@ HAPI struct service_context *service_common_create(const char *addr, const char if (status != 0) { ErrPrint("Unable to create a thread for shortcut service: %d\n", status); status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); - if (status != 0) { + if (status != 0) ErrPrint("mutex_destroy: %d\n", status); - } + CLOSE_PIPE(svc_ctx->evt_pipe); CLOSE_PIPE(svc_ctx->tcb_pipe); secure_socket_destroy_handle(svc_ctx->fd); @@ -1026,33 +998,29 @@ HAPI int service_common_destroy(struct service_context *svc_ctx) int status = 0; void *ret; - if (!svc_ctx) { + if (!svc_ctx) return -EINVAL; - } /*! * \note * Terminate server thread */ - if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &status, sizeof(status)) != sizeof(status)) { + if (write(svc_ctx->tcb_pipe[PIPE_WRITE], &status, sizeof(status)) != sizeof(status)) ErrPrint("write: %d\n", errno); - } status = pthread_join(svc_ctx->server_thid, &ret); - if (status != 0) { + if (status != 0) ErrPrint("Join: %d\n", status); - } else { + else DbgPrint("Thread returns: %p\n", ret); - } _finish_privilege_checker(svc_ctx); secure_socket_destroy_handle(svc_ctx->fd); status = pthread_mutex_destroy(&svc_ctx->packet_list_lock); - if (status != 0) { + if (status != 0) ErrPrint("destroy_mutex: %d\n", status); - } CLOSE_PIPE(svc_ctx->evt_pipe); CLOSE_PIPE(svc_ctx->tcb_pipe); @@ -1088,9 +1056,8 @@ HAPI int tcb_is_valid(struct service_context *svc_ctx, struct tcb *tcb) */ HAPI int tcb_pid(struct tcb *tcb) { - if (!tcb) { + if (!tcb) return -1; - } return tcb->pid; } @@ -1101,9 +1068,8 @@ HAPI int tcb_pid(struct tcb *tcb) */ HAPI int tcb_fd(struct tcb *tcb) { - if (!tcb) { + if (!tcb) return -EINVAL; - } return tcb->fd; } @@ -1114,9 +1080,8 @@ HAPI int tcb_fd(struct tcb *tcb) */ HAPI int tcb_client_type(struct tcb *tcb) { - if (!tcb) { + if (!tcb) return -EINVAL; - } return tcb->type; } @@ -1127,9 +1092,8 @@ HAPI int tcb_client_type(struct tcb *tcb) */ HAPI int tcb_client_type_set(struct tcb *tcb, enum tcb_type type) { - if (!tcb) { + if (!tcb) return -EINVAL; - } DbgPrint("TCB[%p] Client type is changed to %d from %d\n", tcb, type, tcb->type); tcb->type = type; @@ -1142,9 +1106,8 @@ HAPI int tcb_client_type_set(struct tcb *tcb, enum tcb_type type) */ HAPI struct service_context *tcb_svc_ctx(struct tcb *tcb) { - if (!tcb) { + if (!tcb) return NULL; - } return tcb->svc_ctx; } @@ -1195,9 +1158,8 @@ HAPI int service_common_multicast_packet(struct tcb *tcb, struct packet *packet, } ret = com_core_send(target->fd, (void *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT); - if (ret < 0) { + if (ret < 0) ErrPrint("Failed to send packet: %d\n", ret); - } } DbgPrint("Finish to multicast packet\n"); return 0; @@ -1226,9 +1188,8 @@ HAPI struct service_event_item *service_common_add_timer(struct service_context } if (service_common_update_timer(item, timer) < 0) { - if (close(item->info.timer.fd) < 0) { + if (close(item->info.timer.fd) < 0) ErrPrint("close: %d\n", errno); - } DbgFree(item); return NULL; } @@ -1277,9 +1238,8 @@ HAPI int service_common_del_timer(struct service_context *svc_ctx, struct servic svc_ctx->event_list = eina_list_remove(svc_ctx->event_list, item); - if (close(item->info.timer.fd) < 0) { + if (close(item->info.timer.fd) < 0) ErrPrint("close: %d\n", errno); - } DbgFree(item); return 0; } @@ -1334,8 +1294,7 @@ HAPI int service_check_privilege_by_socket_fd(struct service_context *svc_ctx, i if (ret == CYNARA_API_ACCESS_ALLOWED) { DbgPrint("[%s] Access allowed.", privilege); result = 1; - } - else { + } else { DbgPrint("[%s] Access denied.[%d]", privilege, ret); result = 0; } @@ -1343,17 +1302,14 @@ HAPI int service_check_privilege_by_socket_fd(struct service_context *svc_ctx, i } out: - if (client_smack) { + if (client_smack) free(client_smack); - } - if (session) { + if (session) free(session); - } - if (uid) { + if (uid) free(uid); - } return result; } diff --git a/src/shortcut_service.c b/src/shortcut_service.c index 9dd0e65..ddc5d9f 100644 --- a/src/shortcut_service.c +++ b/src/shortcut_service.c @@ -78,9 +78,8 @@ static inline struct tcb *get_reply_context(double seq) tcb = NULL; EINA_LIST_FOREACH_SAFE(s_info.context_list, l, n, ctx) { - if (ctx->seq != seq) { + if (ctx->seq != seq) continue; - } s_info.context_list = eina_list_remove(s_info.context_list, ctx); tcb = ctx->tcb; @@ -101,9 +100,8 @@ static void send_reply_packet(struct tcb *tcb, struct packet *packet, int ret) return; } - if (service_common_unicast_packet(tcb, reply_packet) < 0) { + if (service_common_unicast_packet(tcb, reply_packet) < 0) ErrPrint("Unable to send reply packet\n"); - } packet_destroy(reply_packet); } @@ -150,11 +148,10 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat } } - if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { + if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) ErrPrint("Unable to send service request packet\n"); - } else { + else (void)put_reply_context(tcb, packet_seq(packet)); - } break; case PACKET_REQ_NOACK: /* Doesn't need to send reply packet */ @@ -164,9 +161,8 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat break; } - if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) { + if (service_common_multicast_packet(tcb, packet, TCB_CLIENT_TYPE_SERVICE) < 0) ErrPrint("Unable to send service reuqest packet\n"); - } break; case PACKET_ACK: /* Okay, client(or app) send a reply packet to us. */ @@ -182,9 +178,8 @@ static int service_thread_main(struct tcb *tcb, struct packet *packet, void *dat break; } - if (service_common_unicast_packet(tcb, packet) < 0) { + if (service_common_unicast_packet(tcb, packet) < 0) ErrPrint("Unable to send reply packet\n"); - } break; default: ErrPrint("Packet type is not valid[%s]\n", command); @@ -223,9 +218,8 @@ HAPI int shortcut_service_init(void) HAPI int shortcut_service_fini(void) { - if (!s_info.svc_ctx) { + if (!s_info.svc_ctx) return SERVICE_COMMON_ERROR_INVALID_PARAMETER; - } service_common_destroy(s_info.svc_ctx); s_info.svc_ctx = NULL; diff --git a/src/util.c b/src/util.c index d150b6d..c950508 100644 --- a/src/util.c +++ b/src/util.c @@ -60,48 +60,25 @@ HAPI double util_timestamp(void) HAPI void util_setup_log_disk(void) { -#if 0 - int ret; -#endif - if (access(CONF_LOG_PATH, R_OK | W_OK | X_OK) == 0) { DbgPrint("[%s] is already accessible\n", CONF_LOG_PATH); return; } DbgPrint("Initiate the critical log folder [%s]\n", CONF_LOG_PATH); - if (mkdir(CONF_LOG_PATH, 0755) < 0) { + if (mkdir(CONF_LOG_PATH, 0755) < 0) ErrPrint("mkdir: %d\n", errno); - } else { -#if 0 - if (chmod(CONF_LOG_PATH, 0750) < 0) { - ErrPrint("chmod: %d\n", errno); - } - - if (chown(CONF_LOG_PATH, 5000, 5000) < 0) { - ErrPrint("chown: %d\n", errno); - } - - ret = smack_setlabel(CONF_LOG_PATH, DATA_SHARE_LABEL, SMACK_LABEL_ACCESS); - if (ret != 0) { - ErrPrint("Failed to set SMACK for %s (%d)\n", CONF_LOG_PATH, ret); - } else { - ret = smack_setlabel(CONF_LOG_PATH, "1", SMACK_LABEL_TRANSMUTE); - DbgPrint("[%s] is successfully created (t: %d)\n", CONF_LOG_PATH, ret); - } -#endif - } } HAPI const char *util_basename(const char *name) { int length; length = name ? strlen(name) : 0; - if (!length) { + if (!length) return "."; - } - while (--length > 0 && name[length] != '/'); + while (--length > 0 && name[length] != '/') + ; return length <= 0 ? name : (name + length + (name[length] == '/')); } -- 2.7.4