Update coding convention
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 9 Aug 2013 05:16:15 +0000 (14:16 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 9 Aug 2013 05:16:15 +0000 (14:16 +0900)
Use the '{' '}' for local block(if, for, while, ...) even if it has A line.

Change-Id: I29a8d8ab2c6023db66312b2d2ca93b8c4440248a

packaging/libcom-core.spec
src/com-core.c
src/com-core_packet-router.c
src/com-core_packet.c
src/com-core_thread.c
src/dlist.c
src/packet.c
src/secure_socket.c

index facc9d8..4bacf0a 100644 (file)
@@ -1,6 +1,6 @@
 Name: libcom-core
 Summary: Library for the light-weight IPC 
-Version: 0.5.0
+Version: 0.5.1
 Release: 1
 Group: HomeTF/Framework
 License: Apache License
index 1fb3c48..4cbb44b 100644 (file)
@@ -147,11 +147,13 @@ static gboolean accept_cb(GIOChannel *src, GIOCondition cond, gpointer cbdata)
        }
        DbgPrint("New connectino arrived: server(%d), client(%d)\n", socket_fd, client_fd);
 
-       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
-       if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+       if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        gio = g_io_channel_unix_new(client_fd);
        if (!gio) {
@@ -206,11 +208,13 @@ EAPI int com_core_server_create(const char *addr, int is_sync, int (*service_cb)
                return fd;
        }
 
-       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("fcntl: %s\n", strerror(errno));
+       }
 
-       if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("fcntl: %s\n", strerror(errno));
+       }
 
        DbgPrint("Create new IO channel for server FD: %d\n", fd);
        gio = g_io_channel_unix_new(fd);
@@ -264,11 +268,13 @@ EAPI int com_core_client_create(const char *addr, int is_sync, int (*service_cb)
                return client_fd;
        }
 
-       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
-       if (!is_sync && fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+       if (!is_sync && fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        gio = g_io_channel_unix_new(client_fd);
        if (!gio) {
@@ -312,10 +318,11 @@ EAPI int com_core_add_event_callback(enum com_core_event_type type, int (*evt_cb
        cbdata->evt_cb = evt_cb;
        cbdata->data = data;
 
-       if (type == CONNECTOR_CONNECTED)
+       if (type == CONNECTOR_CONNECTED) {
                s_info.conn_cb_list = dlist_append(s_info.conn_cb_list, cbdata);
-       else
+       } else {
                s_info.disconn_cb_list = dlist_append(s_info.disconn_cb_list, cbdata);
+       }
        return 0;
 }
 
index f716751..1f2adb7 100644 (file)
@@ -276,11 +276,13 @@ static inline void clear_request_ctx(int handle)
        struct dlist *n;
 
        dlist_foreach_safe(s_info.request_list, l, n, ctx) {
-               if (ctx->handle != handle)
+               if (ctx->handle != handle) {
                        continue;
+               }
 
-               if (ctx->recv_cb)
+               if (ctx->recv_cb) {
                        ctx->recv_cb(-1, handle, NULL, ctx->data);
+               }
 
                destroy_request_ctx(ctx);
        }
@@ -327,8 +329,9 @@ static struct router *find_router_by_handle(int handle)
                         * Find the client list
                         */
                        dlist_foreach(router->info.server.client_list, cl, client) {
-                               if (client->handle == handle)
+                               if (client->handle == handle) {
                                        return router;
+                               }
                        }
                } else if (router->handle == handle) {
                        return router;
@@ -385,8 +388,9 @@ static gboolean packet_cb(GIOChannel *src, GIOCondition cond, gpointer data)
                                break;
                        }
 
-                       if (request->recv_cb)
+                       if (request->recv_cb) {
                                request->recv_cb(pid, handle, packet, request->data);
+                       }
 
                        destroy_request_ctx(request);
                        break;
@@ -415,8 +419,9 @@ static gboolean packet_cb(GIOChannel *src, GIOCondition cond, gpointer data)
                        }
 
                        ret = put_send_packet(router, handle, packet);
-                       if (ret < 0)
+                       if (ret < 0) {
                                ErrPrint("Failed to send a packet\n");
+                       }
                        break;
                case PACKET_ERROR:
                default:
@@ -455,8 +460,9 @@ static struct packet *service_handler(int handle, pid_t pid, const struct packet
 
        result = NULL;
        for (i = 0; table[i].cmd; i++) {
-               if (strcmp(table[i].cmd, packet_command(packet)))
+               if (strcmp(table[i].cmd, packet_command(packet))) {
                        continue;
+               }
 
                result = table[i].handler(pid, handle, packet);
                break;
@@ -479,8 +485,9 @@ static inline int select_event(int handle, double timeout)
        FD_SET(handle, &set);
 
        status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+       }
        if (timeout > 0.0f) {
                struct timeval tv;
 
@@ -493,8 +500,9 @@ static inline int select_event(int handle, double timeout)
        } else {
                ErrPrint("Invalid timeout: %lf (it must be greater than 0.0)\n", timeout);
                status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+               }
                return -EINVAL;
        }
 
@@ -508,19 +516,22 @@ static inline int select_event(int handle, double timeout)
 
                ErrPrint("Error: %s\n", strerror(errno));
                status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+               }
                return ret;
        } else if (ret == 0) {
                ErrPrint("Timeout expired\n");
                status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+               }
                return -ETIMEDOUT;
        }
        status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+       }
 
        if (!FD_ISSET(handle, &set)) {
                ErrPrint("Unexpected handle is toggled\n");
@@ -547,11 +558,13 @@ static void *send_main(void *data)
                 * select event has cancel point
                 */
                ret = select_event(router->send_pipe[PIPE_READ], 0.0f);
-               if (ret == -EAGAIN)
+               if (ret == -EAGAIN) {
                        continue;
+               }
 
-               if (ret < 0)
+               if (ret < 0) {
                        break;
+               }
 
                packet = get_send_packet(router, &handle);
                if (!packet) {
@@ -602,8 +615,9 @@ static struct router *create_router(const char *sock, int handle, struct method
        if (ret != 0) {
                ErrPrint("Mutex craetion failed: %s\n", strerror(ret));
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -614,12 +628,14 @@ static struct router *create_router(const char *sock, int handle, struct method
                ErrPrint("Mutex creation failed: %s\n", strerror(ret));
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -629,16 +645,19 @@ static struct router *create_router(const char *sock, int handle, struct method
        if (!router->sock) {
                ErrPrint("Heap: %s\n", strerror(errno));
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -650,16 +669,19 @@ static struct router *create_router(const char *sock, int handle, struct method
                free(router->sock);
 
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -673,16 +695,19 @@ static struct router *create_router(const char *sock, int handle, struct method
                CLOSE_PIPE(router->recv_pipe);
 
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -700,16 +725,19 @@ static struct router *create_router(const char *sock, int handle, struct method
                free(router->sock);
 
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -732,16 +760,19 @@ static struct router *create_router(const char *sock, int handle, struct method
                free(router->sock);
 
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -764,16 +795,19 @@ static struct router *create_router(const char *sock, int handle, struct method
                free(router->sock);
 
                ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                ret = pthread_mutex_destroy(&router->route_list_lock);
-               if (ret != 0)
+               if (ret != 0) {
                        ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+               }
 
                free(router);
                return NULL;
@@ -797,13 +831,15 @@ static inline __attribute__((always_inline)) int destroy_router(struct router *r
        DbgPrint("Put NULL Packet to terminate send thread (%d)\n", ret);
 
        ret = pthread_join(router->send_thid, NULL);
-       if (ret != 0)
+       if (ret != 0) {
                ErrPrint("Join: %s\n", strerror(ret));
+       }
 
        dlist_remove_data(s_info.router_list, router);
 
-       if (router->id > 0)
+       if (router->id > 0) {
                g_source_remove(router->id);
+       }
 
        CLOSE_PIPE(router->recv_pipe);
        CLOSE_PIPE(router->send_pipe);
@@ -811,16 +847,19 @@ static inline __attribute__((always_inline)) int destroy_router(struct router *r
        free(router->sock);
 
        ret = pthread_mutex_destroy(&router->send_packet_list_lock);
-       if (ret != 0)
+       if (ret != 0) {
                ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+       }
 
        ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
-       if (ret != 0)
+       if (ret != 0) {
                ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+       }
 
        ret = pthread_mutex_destroy(&router->route_list_lock);
-       if (ret != 0)
+       if (ret != 0) {
                ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+       }
 
        handle = router->handle;
        free(router);
@@ -865,8 +904,9 @@ static inline int route_packet(struct router *router, int handle, struct packet
                                 *
                                 * We have to optimize the processing time in the CRITICAL SECTION
                                 */
-                               if (put_send_packet(router, route->handle, packet) < 0)
+                               if (put_send_packet(router, route->handle, packet) < 0) {
                                        ErrPrint("Failed to send whole packet\n");
+                               }
 
                                processed++;
                        }
@@ -913,8 +953,9 @@ static int put_send_packet(struct router *router, int handle, struct packet *pac
         * \note
         * Producing an event on event pipe
         */
-       if (write(router->send_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle))
+       if (write(router->send_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle)) {
                ErrPrint("Failed to put an event: %s\n", strerror(errno));
+       }
 
        return 0;
 }
@@ -951,8 +992,9 @@ static inline int put_recv_packet(struct router *router, int handle, struct pack
         * \note
         * Producing an event on event pipe
         */
-       if (write(router->recv_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle))
+       if (write(router->recv_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle)) {
                ErrPrint("Failed to put an event: %s\n", strerror(errno));
+       }
 
        return 0;
 }
@@ -979,8 +1021,9 @@ static inline struct packet *get_send_packet(struct router *router, int *handle)
 
        CRITICAL_SECTION_END(&router->send_packet_list_lock);
 
-       if (read(router->send_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle))
+       if (read(router->send_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle)) {
                ErrPrint("Failed to get an event: %s\n", strerror(errno));
+       }
 
        return packet;
 }
@@ -1003,8 +1046,9 @@ static inline struct packet *get_recv_packet(struct router *router, int *handle,
                router->recv_packet_list = dlist_remove(router->recv_packet_list, l);
 
                packet = item->packet;
-               if (pid)
+               if (pid) {
                        *pid = item->pid;
+               }
 
                free(item);
        }
@@ -1017,8 +1061,9 @@ static inline struct packet *get_recv_packet(struct router *router, int *handle,
         * Even if we cannot get the packet(NULL), we should consuming event
         * Because the NULL packet means disconnected
         */
-       if (read(router->recv_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle))
+       if (read(router->recv_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle)) {
                ErrPrint("Failed to get an event: %s\n", strerror(errno));
+       }
 
        return packet;
 }
@@ -1054,16 +1099,18 @@ static inline int build_packet(int handle, struct recv_ctx *ctx)
                ctx->packet = packet_build(ctx->packet, ctx->offset, ptr, ret);
                free(ptr);
 
-               if (!ctx->packet)
+               if (!ctx->packet) {
                        return -EFAULT;
+               }
 
                ctx->offset += ret;
 
                if (ctx->offset == packet_header_size()) {
-                       if (packet_size(ctx->packet) == ctx->offset)
+                       if (packet_size(ctx->packet) == ctx->offset) {
                                ctx->state = RECV_STATE_READY;
-                       else
+                       } else {
                                ctx->state = RECV_STATE_BODY;
+                       }
                }
                break;
        case RECV_STATE_BODY:
@@ -1090,12 +1137,14 @@ static inline int build_packet(int handle, struct recv_ctx *ctx)
 
                ctx->packet = packet_build(ctx->packet, ctx->offset, ptr, ret);
                free(ptr);
-               if (!ctx->packet)
+               if (!ctx->packet) {
                        return -EFAULT;
+               }
 
                ctx->offset += ret;
-               if (ctx->offset == packet_size(ctx->packet))
+               if (ctx->offset == packet_size(ctx->packet)) {
                        ctx->state = RECV_STATE_READY;
+               }
 
                break;
        case RECV_STATE_READY:
@@ -1115,8 +1164,9 @@ static int router_common_main(struct router *router, int handle, struct recv_ctx
                 * select event has cancel point
                 */
                ret = select_event(handle, ctx->timeout);
-               if (ret == -EAGAIN)
+               if (ret == -EAGAIN) {
                        continue;
+               }
 
                if (ret < 0) {
                        packet_destroy(ctx->packet);
@@ -1139,10 +1189,11 @@ static int router_common_main(struct router *router, int handle, struct recv_ctx
                         * If the destination address is ZERO,
                         * Pull up the packet to this server.
                         */
-                       if (packet_destination(ctx->packet))
+                       if (packet_destination(ctx->packet)) {
                                route_packet(router, handle, ctx->packet);
-                       else
+                       } else {
                                put_recv_packet(router, handle, ctx->packet, ctx->pid);
+                       }
 
                        ctx->state = RECV_STATE_INIT;
                }
@@ -1226,11 +1277,13 @@ static gboolean accept_cb(GIOChannel *src, GIOCondition cond, gpointer data)
                return FALSE;
        }
 
-       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
-       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        client = calloc(1, sizeof(*client));
        if (!client) {
@@ -1275,8 +1328,9 @@ EAPI int com_core_packet_router_server_init(const char *sock, double timeout, st
        GIOChannel *gio;
 
        handle = secure_socket_create_server(sock);
-       if (handle < 0)
+       if (handle < 0) {
                return handle;
+       }
 
        router = create_router(sock, handle, table);
        if (!router) {
@@ -1326,8 +1380,9 @@ EAPI int com_core_packet_router_client_init(const char *sock, double timeout, st
        int status;
 
        handle = secure_socket_create_client(sock);
-       if (handle < 0)
+       if (handle < 0) {
                return handle;
+       }
 
        router = create_router(sock, handle, table);
        if (!router) {
@@ -1398,13 +1453,15 @@ EAPI void *com_core_packet_router_server_fini(int handle)
                router->info.server.client_list = dlist_remove(router->info.server.client_list, l);
 
                status = pthread_cancel(client->thid);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Failed to cacnel a thread: %s\n", strerror(errno));
+               }
 
                ret = NULL;
                status = pthread_join(client->thid, &ret);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Failed to join a thread: %s\n", strerror(errno));
+               }
 
                if (ret == PTHREAD_CANCELED) {
                        DbgPrint("Thread is canceled\n");
@@ -1456,12 +1513,14 @@ EAPI void *com_core_packet_router_client_fini(int handle)
        }
 
        status = pthread_cancel(router->info.client.thid);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Failed to cancel a thread: %s\n", strerror(errno));
+       }
 
        status = pthread_join(router->info.client.thid, &ret);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Failed to join a thread: %s\n", strerror(errno));
+       }
 
        if (ret == PTHREAD_CANCELED) {
                DbgPrint("Thread is canceled\n");
@@ -1491,8 +1550,9 @@ EAPI int com_core_packet_router_async_send(int handle, struct packet *packet, do
        struct router *router;
        int ret;
 
-       if (handle < 0 || !packet)
+       if (handle < 0 || !packet) {
                return -EINVAL;
+       }
 
        if (packet_type(packet) != PACKET_REQ) {
                ErrPrint("Invalid packet - should be PACKET_REQ\n");
@@ -1506,16 +1566,18 @@ EAPI int com_core_packet_router_async_send(int handle, struct packet *packet, do
        }
 
        ctx = create_request_ctx(handle);
-       if (!ctx)
+       if (!ctx) {
                return -ENOMEM;
+       }
 
        ctx->recv_cb = recv_cb;
        ctx->data = data;
        ctx->packet = packet_ref(packet);
 
        ret = put_send_packet(router, handle, packet);
-       if (ret < 0)
+       if (ret < 0) {
                destroy_request_ctx(ctx);
+       }
 
        return ret;
 }
@@ -1528,8 +1590,9 @@ EAPI int com_core_packet_router_send_only(int handle, struct packet *packet)
 {
        struct router *router;
 
-       if (handle < 0 || !packet || packet_type(packet) != PACKET_REQ_NOACK)
+       if (handle < 0 || !packet || packet_type(packet) != PACKET_REQ_NOACK) {
                return -EINVAL;
+       }
 
        router = find_router_by_handle(handle);
        if (!router) {
@@ -1561,8 +1624,9 @@ EAPI int com_core_packet_router_add_route(int handle, unsigned long address, int
        struct dlist *l;
        int found = 0;
 
-       if (handle < 0 || !address || h < 0)
+       if (handle < 0 || !address || h < 0) {
                return -EINVAL;
+       }
 
        router = find_router_by_handle(handle);
        if (!router) {
@@ -1589,8 +1653,9 @@ EAPI int com_core_packet_router_add_route(int handle, unsigned long address, int
                }
        }
 
-       if (!found)
+       if (!found) {
                router->route_list = dlist_append(router->route_list, route);
+       }
 
        CRITICAL_SECTION_END(&router->route_list_lock);
 
@@ -1614,8 +1679,9 @@ EAPI int com_core_packet_router_del_route(int handle, unsigned long address)
        struct dlist *n;
        int found = 0;
 
-       if (handle < 0 || !address)
+       if (handle < 0 || !address) {
                return -EINVAL;
+       }
 
        router = find_router_by_handle(handle);
        if (!router) {
@@ -1626,8 +1692,9 @@ EAPI int com_core_packet_router_del_route(int handle, unsigned long address)
        CRITICAL_SECTION_BEGIN(&router->route_list_lock);
 
        dlist_foreach_safe(router->route_list, l, n, route) {
-               if (route->address != address)
+               if (route->address != address) {
                        continue;
+               }
 
                router->route_list = dlist_remove(router->route_list, l);
 
@@ -1654,8 +1721,9 @@ EAPI int com_core_packet_router_update_route(int handle, unsigned long address,
        struct dlist *l;
        int found = 0;
 
-       if (handle < 0 || !address || h < 0)
+       if (handle < 0 || !address || h < 0) {
                return -EINVAL;
+       }
 
        router = find_router_by_handle(handle);
        if (!router) {
@@ -1666,8 +1734,9 @@ EAPI int com_core_packet_router_update_route(int handle, unsigned long address,
        CRITICAL_SECTION_BEGIN(&router->route_list_lock);
 
        dlist_foreach(router->route_list, l, route) {
-               if (route->address != address)
+               if (route->address != address) {
                        continue;
+               }
 
                route->handle = h;
                route->invalid = 0;
index a50955a..16844bb 100644 (file)
@@ -142,8 +142,9 @@ static inline struct recv_ctx *find_recv_ctx(int handle)
        struct dlist *l;
 
        dlist_foreach(s_info.recv_list, l, ctx) {
-               if (ctx->handle == handle)
+               if (ctx->handle == handle) {
                        return ctx;
+               }
        }
 
        return NULL;
@@ -206,8 +207,9 @@ static inline int packet_ready(int handle, const struct recv_ctx *receive, struc
                break;
        case PACKET_REQ:
                for (i = 0; table[i].cmd; i++) {
-                       if (strcmp(table[i].cmd, packet_command(receive->packet)))
+                       if (strcmp(table[i].cmd, packet_command(receive->packet))) {
                                continue;
+                       }
 
                        result = table[i].handler(receive->pid, handle, receive->packet);
                        if (result) {
@@ -225,12 +227,14 @@ static inline int packet_ready(int handle, const struct recv_ctx *receive, struc
                break;
        case PACKET_REQ_NOACK:
                for (i = 0; table[i].cmd; i++) {
-                       if (strcmp(table[i].cmd, packet_command(receive->packet)))
+                       if (strcmp(table[i].cmd, packet_command(receive->packet))) {
                                continue;
+                       }
 
                        result = table[i].handler(receive->pid, handle, receive->packet);
-                       if (result)
+                       if (result) {
                                packet_destroy(result);
+                       }
                }
                break;
        default:
@@ -253,28 +257,32 @@ static int client_disconnected_cb(int handle, void *data)
        int referred = 0;
 
        receive = find_recv_ctx(handle);
-       if (receive)
+       if (receive) {
                pid = receive->pid;
+       }
 
        DbgPrint("Clean up all requests and a receive context for handle(%d) for pid(%d)\n", handle, pid);
 
        dlist_foreach_safe(s_info.request_list, l, n, request) {
-               if (request->handle != handle)
+               if (request->handle != handle) {
                        continue;
+               }
 
                if (request->in_recv) {
                        referred = 1;
                        continue;
                }
 
-               if (request->recv_cb)
+               if (request->recv_cb) {
                        request->recv_cb(pid, handle, NULL, request->data);
+               }
 
                destroy_request_ctx(request);
        }
 
-       if (receive && !referred)
+       if (receive && !referred) {
                destroy_recv_ctx(receive);
+       }
 
        return 0;
 }
@@ -336,10 +344,11 @@ static int service_cb(int handle, void *data)
                        receive->offset += ret;
 
                        if (receive->offset == packet_header_size()) {
-                               if (packet_size(receive->packet) == receive->offset)
+                               if (packet_size(receive->packet) == receive->offset) {
                                        receive->state = RECV_STATE_READY;
-                               else
+                               } else {
                                        receive->state = RECV_STATE_BODY;
+                               }
                        }
                } else {
                        DbgPrint("ZERO bytes receives(%d)\n", pid);
@@ -402,8 +411,9 @@ static int service_cb(int handle, void *data)
 
        if (receive->state == RECV_STATE_READY) {
                ret = packet_ready(handle, receive, data);
-               if (ret == 0)
+               if (ret == 0) {
                        destroy_recv_ctx(receive);
+               }
                /*!
                 * if ret is negative value, disconnected_cb will be called after this function
                 */
@@ -430,8 +440,9 @@ EAPI int com_core_packet_async_send(int handle, struct packet *packet, double ti
        }
 
        ctx = create_request_ctx(handle);
-       if (!ctx)
+       if (!ctx) {
                return -ENOMEM;
+       }
 
        ctx->recv_cb = recv_cb;
        ctx->data = data;
@@ -481,18 +492,22 @@ EAPI struct packet *com_core_packet_oneshot_send(const char *addr, struct packet
        }
 
        fd = secure_socket_create_client(addr);
-       if (fd < 0)
+       if (fd < 0) {
                return NULL;
+       }
 
-       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("fcntl: %s\n", strerror(errno));
+       }
 
-       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        ret = com_core_send(fd, (char *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT);
-       if (ret < 0)
+       if (ret < 0) {
                goto out;
+       }
 
        ptr = malloc(packet_header_size());
        if (!ptr) {
@@ -559,8 +574,9 @@ out:
 static inline int com_core_packet_init(void)
 {
        int ret;
-       if (s_info.initialized)
+       if (s_info.initialized) {
                return 0;
+       }
 
        ret = com_core_add_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
        s_info.initialized = (ret == 0);
@@ -569,8 +585,9 @@ static inline int com_core_packet_init(void)
 
 static inline int com_core_packet_fini(void)
 {
-       if (!s_info.initialized)
+       if (!s_info.initialized) {
                return 0;
+       }
 
        s_info.initialized = 0;
        com_core_del_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
@@ -582,12 +599,14 @@ EAPI int com_core_packet_client_init(const char *addr, int is_sync, struct metho
        int ret;
 
        ret = com_core_packet_init();
-       if (ret < 0)
+       if (ret < 0) {
                return ret;
+       }
 
        ret = s_info.vtable.client_create(addr, is_sync, service_cb, table);
-       if (ret < 0)
+       if (ret < 0) {
                com_core_packet_fini();
+       }
 
        return ret;
 }
@@ -604,12 +623,14 @@ EAPI int com_core_packet_server_init(const char *addr, struct method *table)
        int ret;
 
        ret = com_core_packet_init();
-       if (ret < 0)
+       if (ret < 0) {
                return ret;
+       }
 
        ret = s_info.vtable.server_create(addr, 0, service_cb, table);
-       if (ret < 0)
+       if (ret < 0) {
                com_core_packet_fini();
+       }
 
        return ret;
 }
index 86e7553..b6d65bc 100644 (file)
@@ -95,11 +95,13 @@ static inline void server_destroy(struct server *server)
 {
        dlist_remove_data(s_info.server_list, server);
 
-       if (server->id > 0)
+       if (server->id > 0) {
                g_source_remove(server->id);
+       }
 
-       if (server->handle > 0)
+       if (server->handle > 0) {
                secure_socket_destroy_handle(server->handle);
+       }
 
        free(server);
 }
@@ -148,14 +150,16 @@ static inline void terminate_thread(struct tcb *tcb)
        void *res = NULL;
        struct chunk *chunk;
 
-       if (write(tcb->ctrl_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb))
+       if (write(tcb->ctrl_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) {
                ErrPrint("Unable to write CTRL pipe\n");
+       }
 
        secure_socket_destroy_handle(tcb->handle);
 
        status = pthread_join(tcb->thid, &res);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Join: %s\n", strerror(status));
+       }
        else
                ErrPrint("Thread returns: %d\n", (int)res);
 
@@ -213,8 +217,9 @@ static inline void chunk_append(struct tcb *tcb, struct chunk *chunk)
                return;
        }
 
-       if (ret != sizeof(event_ch))
+       if (ret != sizeof(event_ch)) {
                ErrPrint("Failed to trigger reader\n");
+       }
 
        /* Take a breathe */
        pthread_yield();
@@ -393,8 +398,9 @@ static void *client_cb(void *data)
        DbgPrint("Client CB is terminated (%d)\n", tcb->handle);
        /* Wake up main thread to get disconnected event */
        event_ch = EVENT_TERM;
-       if (write(tcb->evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch))
+       if (write(tcb->evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) {
                ErrPrint("write: %s\n", strerror(errno));
+       }
 
        return (void *)ret;
 }
@@ -409,15 +415,17 @@ static inline void tcb_destroy(struct tcb *tcb)
 
        dlist_remove_data(s_info.tcb_list, tcb);
 
-       if (tcb->id > 0)
+       if (tcb->id > 0) {
                g_source_remove(tcb->id);
+       }
 
        CLOSE_PIPE(tcb->evt_pipe);
        CLOSE_PIPE(tcb->ctrl_pipe);
 
        status = pthread_mutex_destroy(&tcb->chunk_lock);
-       if (status != 0)
+       if (status != 0) {
                ErrPrint("Failed to destroy mutex: %s\n", strerror(status));
+       }
 
        free(tcb);
 }
@@ -496,8 +504,9 @@ static inline struct tcb *tcb_create(int client_fd, int is_sync, int (*service_c
        if (pipe2(tcb->evt_pipe, (is_sync ? 0 : O_NONBLOCK) | O_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
                status = pthread_mutex_destroy(&tcb->chunk_lock);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Error: %s\n", strerror(status));
+               }
                free(tcb);
                return NULL;
        }
@@ -508,8 +517,9 @@ static inline struct tcb *tcb_create(int client_fd, int is_sync, int (*service_c
                CLOSE_PIPE(tcb->evt_pipe);
 
                status = pthread_mutex_destroy(&tcb->chunk_lock);
-               if (status != 0)
+               if (status != 0) {
                        ErrPrint("Error: %s\n", strerror(status));
+               }
 
                free(tcb);
                return NULL;
@@ -552,11 +562,13 @@ static gboolean accept_cb(GIOChannel *src, GIOCondition cond, gpointer data)
                return FALSE;
        }
 
-       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
-       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        tcb = tcb_create(fd, 0, server->service_cb, server->data);
        if (!tcb) {
@@ -627,11 +639,13 @@ EAPI int com_core_thread_client_create(const char *addr, int is_sync, int (*serv
        if (client_fd < 0)
                return client_fd;
 
-       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
-       if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+       if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("Error: %s\n", strerror(errno));
+       }
 
        tcb = tcb_create(client_fd, is_sync, service_cb, data);
        if (!tcb) {
@@ -696,14 +710,17 @@ EAPI int com_core_thread_server_create(const char *addr, int is_sync, int (*serv
        struct server *server;
 
        fd = secure_socket_create_server(addr);
-       if (fd < 0)
+       if (fd < 0) {
                return fd;
+       }
 
-       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+       if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
                ErrPrint("fcntl: %s\n", strerror(errno));
+       }
 
-       if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+       if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
                ErrPrint("fcntl: %s\n", strerror(errno));
+       }
 
        server = server_create(fd, service_cb, data);
        if (!server) {
@@ -749,8 +766,9 @@ static inline struct tcb *find_tcb_by_handle(int handle)
        struct tcb *tcb;
 
        dlist_foreach(s_info.tcb_list, l, tcb) {
-               if (tcb->handle == handle)
+               if (tcb->handle == handle) {
                        return tcb;
+               }
        }
 
        return NULL;
@@ -898,8 +916,9 @@ EAPI int com_core_thread_recv(int handle, char *buffer, int size, int *sender_pi
 
                *sender_pid = chunk->pid;
 
-               if (chunk->offset == chunk->size)
+               if (chunk->offset == chunk->size) {
                        chunk_remove(tcb, chunk);
+               }
        }
 
        return readsize;
@@ -917,8 +936,9 @@ EAPI int com_core_thread_server_destroy(int handle)
        struct server *server;
 
        dlist_foreach_safe(s_info.tcb_list, l, n, tcb) {
-               if (tcb->server_handle != handle)
+               if (tcb->server_handle != handle) {
                        continue;
+               }
 
                invoke_disconn_cb_list(handle);
                terminate_thread(tcb);
@@ -927,8 +947,9 @@ EAPI int com_core_thread_server_destroy(int handle)
        }
 
        dlist_foreach_safe(s_info.server_list, l, n, server) {
-               if (server->handle != handle)
+               if (server->handle != handle) {
                        continue;
+               }
 
                invoke_disconn_cb_list(handle);
                server_destroy(server);
@@ -947,8 +968,9 @@ EAPI int com_core_thread_client_destroy(int handle)
        struct tcb *tcb;
 
        tcb = find_tcb_by_handle(handle);
-       if (!tcb)
+       if (!tcb) {
                return -ENOENT;
+       }
 
        invoke_disconn_cb_list(handle);
        terminate_thread(tcb);
index 2b40ff4..695d22a 100644 (file)
@@ -46,8 +46,9 @@ struct dlist *dlist_append(struct dlist *list, void *data)
        struct dlist *item;
 
        item = malloc(sizeof(*item));
-       if (!item)
+       if (!item) {
                return NULL;
+       }
 
        item->next = NULL;
        item->data = data;
@@ -72,8 +73,9 @@ struct dlist *dlist_prepend(struct dlist *list, void *data)
        struct dlist *item;
 
        item = malloc(sizeof(*item));
-       if (!item)
+       if (!item) {
                return NULL;
+       }
 
        item->data = data;
 
@@ -96,16 +98,19 @@ struct dlist *dlist_prepend(struct dlist *list, void *data)
 
 struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
 {
-       if (!list || !l)
+       if (!list || !l) {
                return NULL;
+       }
 
-       if (l == list)
+       if (l == list) {
                list = l->next;
-       else
+       } else {
                l->prev->next = l->next;
+       }
 
-       if (l->next)
+       if (l->next) {
                l->next->prev = l->prev;
+       }
        /*!
         * \note
         * If the removed entry 'l' has no next element, it is the last element.
@@ -114,8 +119,9 @@ struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
         *
         * If we didn't care about this, the head element(list) can indicates the invalid element.
         */
-       else if (list)
+       else if (list) {
                list->prev = l->prev;
+       }
 
        free(l);
        return list;
@@ -127,8 +133,9 @@ struct dlist *dlist_find_data(struct dlist *list, void *data)
        void *_data;
 
        dlist_foreach(list, l, _data) {
-               if (data == _data)
+               if (data == _data) {
                        return l;
+               }
        }
 
        return NULL;
@@ -170,8 +177,9 @@ struct dlist *dlist_nth(struct dlist *l, int nth)
 
        i = 0;
        for (n = l; n; n = n->next) {
-               if (i == nth)
+               if (i == nth) {
                        return n;
+               }
                i++;
        }
 
index b634499..9da8d3b 100644 (file)
@@ -57,24 +57,27 @@ struct packet {
 
 EAPI const enum packet_type const packet_type(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return PACKET_ERROR;
+       }
 
        return packet->data->head.type;
 }
 
 EAPI unsigned long packet_mask(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return 0;
+       }
 
        return packet->data->head.mask;
 }
 
 EAPI int packet_set_mask(struct packet *packet, unsigned long mask)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return -EINVAL;
+       }
 
        packet->data->head.mask = mask;
        return 0;
@@ -82,16 +85,18 @@ EAPI int packet_set_mask(struct packet *packet, unsigned long mask)
 
 EAPI const enum packet_flag const packet_flag(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return PACKET_FLAG_ERROR;
+       }
 
        return packet->data->head.flag;
 }
 
 EAPI int packet_set_flag(struct packet *packet, enum packet_flag flag)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return -EINVAL;
+       }
 
        packet->data->head.flag = flag;
        return 0;
@@ -99,16 +104,18 @@ EAPI int packet_set_flag(struct packet *packet, enum packet_flag flag)
 
 EAPI const unsigned long const packet_source(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return 0;
+       }
 
        return packet->data->head.source;
 }
 
 EAPI int packet_set_source(struct packet *packet, unsigned long source)
 {
-       if (!packet || packet->state != VALID || !packet->data || !source)
+       if (!packet || packet->state != VALID || !packet->data || !source) {
                return -EINVAL;
+       }
 
        packet->data->head.source = source;
        return 0;
@@ -116,16 +123,18 @@ EAPI int packet_set_source(struct packet *packet, unsigned long source)
 
 EAPI const unsigned long const packet_destination(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return 0;
+       }
 
        return packet->data->head.destination;
 }
 
 EAPI int packet_set_destination(struct packet *packet, unsigned long destination)
 {
-       if (!packet || packet->state != VALID || !packet->data || !destination)
+       if (!packet || packet->state != VALID || !packet->data || !destination) {
                return -EINVAL;
+       }
 
        packet->data->head.destination = destination;
        return 0;
@@ -133,8 +142,9 @@ EAPI int packet_set_destination(struct packet *packet, unsigned long destination
 
 EAPI const int const packet_version(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return PACKET_ERROR;
+       }
 
        return packet->data->head.version;
 }
@@ -148,40 +158,45 @@ EAPI const int const packet_header_size(void)
 
 EAPI const int const packet_size(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return -EINVAL;
+       }
 
        return sizeof(*packet->data) + packet->data->head.payload_size;
 }
 
 EAPI const double const packet_seq(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return 0;
+       }
 
        return packet->data->head.seq;
 }
 
 EAPI const int const packet_payload_size(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return -EINVAL;
+       }
 
        return packet->data->head.payload_size;
 }
 
 EAPI const char * const packet_command(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID || !packet->data)
+       if (!packet || packet->state != VALID || !packet->data) {
                return NULL;
+       }
 
        return packet->data->head.command;
 }
 
 EAPI const void * const packet_data(const struct packet *packet)
 {
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return NULL;
+       }
 
        return packet->data;
 }
@@ -190,8 +205,9 @@ static inline __attribute__((always_inline)) struct data *check_and_expand_packe
 {
        struct data *new_packet;
 
-       if (packet->head.payload_size < *payload_size)
+       if (packet->head.payload_size < *payload_size) {
                return packet;
+       }
 
        new_packet = realloc(packet, sizeof(*packet) + *payload_size + BUFSIZ); /*!< Expanding to +BUFSIZ */
        if (!new_packet) {
@@ -289,8 +305,9 @@ EAPI struct packet *packet_create_reply(const struct packet *packet, const char
        struct packet *result;
        va_list va;
 
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return NULL;
+       }
 
        result = malloc(sizeof(*result));
        if (!result) {
@@ -331,8 +348,9 @@ EAPI int packet_swap_address(struct packet *packet)
 {
        unsigned long tmp;
 
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return -EINVAL;
+       }
 
        tmp = packet->data->head.source;
        packet->data->head.source = packet->data->head.destination;
@@ -446,8 +464,9 @@ EAPI int packet_get(const struct packet *packet, const char *fmt, ...)
        double *double_ptr;
        char **str_ptr;
 
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return -EINVAL;
+       }
 
        va_start(va, fmt);
 
@@ -490,8 +509,9 @@ out:
 
 EAPI struct packet *packet_ref(struct packet *packet)
 {
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return NULL;
+       }
 
        packet->refcnt++;
        return packet;
@@ -499,8 +519,9 @@ EAPI struct packet *packet_ref(struct packet *packet)
 
 EAPI struct packet *packet_unref(struct packet *packet)
 {
-       if (!packet || packet->state != VALID)
+       if (!packet || packet->state != VALID) {
                return NULL;
+       }
 
        packet->refcnt--;
        if (packet->refcnt < 0) {
index d3ae477..dd54924 100644 (file)
@@ -92,10 +92,11 @@ static inline int create_inet_socket(const char *peer, int port, struct sockaddr
 
        in_addr->sin_port = htons(port);
        in_addr->sin_family = AF_INET;
-       if (*peer == '\0')
+       if (*peer == '\0') {
                in_addr->sin_addr.s_addr = htonl(INADDR_ANY);
-       else
+       } else {
                in_addr->sin_addr.s_addr = inet_addr(peer);
+       }
 
        handle = socket(AF_INET, SOCK_STREAM, 0);
        if (handle < 0) {
@@ -150,8 +151,9 @@ static inline char *parse_scheme(const char *peer, int *port, struct function_ta
                peer += COM_CORE_LOCAL_SCHEME_LEN;
 
                addr = strdup(peer);
-               if (!addr)
+               if (!addr) {
                        ErrPrint("Heap: %s\n", strerror(errno));
+               }
 
                vtable->create_socket = create_unix_socket;
                vtable->setup_handle = setup_unix_handle;
@@ -174,8 +176,10 @@ static inline char *parse_scheme(const char *peer, int *port, struct function_ta
                        goto out;
                }
 
-               if (len > 0)
+               if (len > 0) {
                        strncpy(addr, peer, len);
+               }
+
                addr[len] = '\0';
 
                peer += len + 1;
@@ -240,24 +244,27 @@ EAPI int secure_socket_create_client(const char *peer)
 
        handle = vtable.create_socket(addr, port, sockaddr);
        free(addr);
-       if (handle < 0)
+       if (handle < 0) {
                return handle;
+       }
 
        ret = connect(handle, sockaddr, addrlen);
        if (ret < 0) {
                ret = -errno;
                ErrPrint("Failed to connect to server [%s] %s\n",
                                                        peer, strerror(errno));
-               if (close(handle) < 0)
+               if (close(handle) < 0) {
                        ErrPrint("close: %s\n", strerror(errno));
+               }
 
                return ret;
        }
 
        ret = vtable.setup_handle(handle);
        if (ret < 0) {
-               if (close(handle) < 0)
+               if (close(handle) < 0) {
                        ErrPrint("close: %s\n", strerror(errno));
+               }
 
                return ret;
        }
@@ -299,15 +306,17 @@ EAPI int secure_socket_create_server(const char *peer)
 
        handle = vtable.create_socket(addr, port, sockaddr);
        free(addr);
-       if (handle < 0)
+       if (handle < 0) {
                return handle;
+       }
 
        ret = bind(handle, sockaddr, addrlen);
        if (ret < 0) {
                ret = -errno;
                ErrPrint("bind: %s\n", strerror(errno));
-               if (close(handle) < 0)
+               if (close(handle) < 0) {
                        ErrPrint("close: %s\n", strerror(errno));
+               }
                return ret;
        }
 
@@ -315,14 +324,16 @@ EAPI int secure_socket_create_server(const char *peer)
        if (ret < 0) {
                ret = -errno;
                ErrPrint("listen: %s\n", strerror(errno));
-               if (close(handle) < 0)
+               if (close(handle) < 0) {
                        ErrPrint("close: %s\n", strerror(errno));
+               }
                return ret;
        }
 
        if (vtable.type == SCHEME_LOCAL) {
-               if (chmod(peer, 0666) < 0)
+               if (chmod(peer, 0666) < 0) {
                        ErrPrint("Failed to change the permission of a socket (%s)\n", strerror(errno));
+               }
        }
 
        return handle;
@@ -356,16 +367,18 @@ EAPI int secure_socket_get_connection_handle(int server_handle)
        if (addr->sa_family == AF_UNIX) {
                ret = setup_unix_handle(handle);
                if (ret < 0) {
-                       if (close(handle) < 0)
+                       if (close(handle) < 0) {
                                ErrPrint("close: %s\n", strerror(errno));
+                       }
 
                        handle = ret;
                }
        } else if (addr->sa_family == AF_INET) {
                ret = setup_inet_handle(handle);
                if (ret < 0) {
-                       if (close(handle) < 0)
+                       if (close(handle) < 0) {
                                ErrPrint("close: %s\n", strerror(errno));
+                       }
 
                        handle = ret;
                }
@@ -416,11 +429,13 @@ EAPI int secure_socket_recv(int handle, char *buffer, int size, int *sender_pid)
        int _pid;
        int ret;
 
-       if (size <= 0 || !buffer)
+       if (size <= 0 || !buffer) {
                return -EINVAL;
+       }
 
-       if (!sender_pid)
+       if (!sender_pid) {
                sender_pid = &_pid;
+       }
 
        memset(&msg, 0, sizeof(msg));
        iov.iov_base = buffer;