Update the resource error handling with same coding rule 54/165554/1 accepted/tizen/4.0/unified/20180103.064741 submit/tizen_4.0/20180102.063252 tizen_4.0.IoT.p2_release
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 28 Dec 2017 10:06:08 +0000 (19:06 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Tue, 2 Jan 2018 06:28:50 +0000 (06:28 +0000)
Change-Id: I9981933c8de119db591a07d7b0714e3cd0733d86
(cherry picked from commit 8a1f0b0bdb1eb24d82d4cb978f8a43febde94af7)

core/src/muse_core.c
server/src/muse_server.c
server/src/muse_server_ipc.c
server/src/muse_server_module.c
server/src/muse_server_private.c
server/src/muse_server_signal.c
server/src/muse_server_system.c
server/src/muse_server_tool.c
server/src/muse_server_workqueue.c

index 6fd2b65..0dc0219 100644 (file)
@@ -299,7 +299,7 @@ int muse_core_msg_send_fd(int sock_fd, int *fds, const char *buf)
        msg.msg_iov = &iov;
        msg.msg_iovlen = 1;
 
-       if (fds == NULL) { /* when muse_core_msg_send is called */
+       if (!fds) { /* when muse_core_msg_send is called */
                msg.msg_control = NULL;
                msg.msg_controllen = 0;
        } else {
index 560b5fa..1470671 100644 (file)
@@ -256,7 +256,7 @@ int muse_server_ipc_get_bufmgr(tbm_bufmgr *bufmgr)
        LOGD("Enter");
 
        g_return_val_if_fail(bufmgr, MM_ERROR_INVALID_ARGUMENT);
-       if (ms_get_instance()->bufmgr == NULL)
+       if (!ms_get_instance()->bufmgr)
                g_return_val_if_fail(ms_init_bufmgr(), MM_ERROR_INVALID_ARGUMENT);
 
        LOGD("bufmgr: %p", ms_get_instance()->bufmgr);
@@ -290,7 +290,7 @@ char *muse_server_ipc_get_data(muse_module_h m)
        g_return_val_if_fail(ch->data_queue, NULL);
 
        g_mutex_lock(&ch->data_mutex);
-       while ((raw_data = (char *)g_queue_pop_head(ch->data_queue)) == NULL) {
+       while (!(raw_data = (char *)g_queue_pop_head(ch->data_queue))) {
                if (!g_cond_wait_until(&ch->data_cond, &ch->data_mutex, end_time)) {
                        LOGE("[%d] timeout has passed", ch->sock_fd);
                        break;
index e4e6e8e..8a31188 100644 (file)
@@ -114,7 +114,7 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
 
                        while (m->msg_offset < len) {
                                jobj = muse_core_msg_object_new(m->recv_msg + m->msg_offset, &parse_len, NULL);
-                               if (jobj == NULL) {
+                               if (!jobj) {
                                        LOGE("jobj is null");
                                        break;
                                }
@@ -128,7 +128,7 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                                if (muse_core_msg_object_get_value(MSG_KEY_MODULE_INDEX, jobj, MUSE_TYPE_INT, &idx)) {
                                                        m->idx = idx;
                                                        m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(idx);
-                                                       if (_ms_ipc_module_instance_creation_is_allowed(idx) == FALSE) {
+                                                       if (!_ms_ipc_module_instance_creation_is_allowed(idx) || !m->ch[MUSE_CHANNEL_MSG].data_thread) {
                                                                ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
                                                                g_mutex_unlock(&dispatch_lock);
                                                                ms_exit_worker(m);
@@ -167,12 +167,12 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
                                        default:
                                                m->ch[MUSE_CHANNEL_MSG].tbm_fd = tbm_fd[0];
 
-                                               if (m->is_create_api_called == false) {
+                                               if (!m->is_create_api_called) {
                                                        g_mutex_lock(&dispatch_lock);
                                                        if (muse_core_msg_object_get_value(MSG_KEY_MODULE_INDEX, jobj, MUSE_TYPE_INT, &idx)) {
                                                                m->idx = idx;
                                                                m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(idx);
-                                                               if (_ms_ipc_module_instance_creation_is_allowed(idx) == FALSE) {
+                                                               if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
                                                                        ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
                                                                        g_mutex_unlock(&dispatch_lock);
                                                                        ms_exit_worker(m);
@@ -187,7 +187,7 @@ static gpointer _ms_ipc_dispatch_worker(gpointer data)
 
                                                ms_module_dispatch(m, cmd);
 
-                                               if (m->is_create_api_called == false) {
+                                               if (!m->is_create_api_called) {
                                                        SECURE_LOGW("_ms_ipc_module_cleanup [module %p] [loaded value %d]", m, value);
                                                        if (!value) {
                                                                LOGW("release module dll handle");
@@ -358,12 +358,10 @@ gboolean ms_ipc_job_function(ms_workqueue_job_t *job)
        SECURE_LOGD("[%p] module's msg channel fd : %d", m, m->ch[MUSE_CHANNEL_MSG].sock_fd);
 
        m->ch[MUSE_CHANNEL_MSG].data_thread = g_thread_try_new(MSG_THREAD_NAME, _ms_ipc_dispatch_worker, (gpointer)m, &error);
-       if (m->ch[MUSE_CHANNEL_MSG].data_thread == NULL && error) {
+       if (!m->ch[MUSE_CHANNEL_MSG].data_thread && error) {
                LOGE("thread creation failed : %s", error->message);
                g_error_free(error);
                ms_log_process_info(ms_get_instance()->pid);
-               m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(API_CREATE);
-               ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
        }
 
        MUSE_FREE(job);
@@ -386,11 +384,12 @@ gboolean ms_ipc_data_job_function(ms_workqueue_job_t *job)
        g_return_val_if_fail(m, FALSE);
 
        m->ch[MUSE_CHANNEL_DATA].data_thread = g_thread_try_new(DATA_THREAD_NAME, _ms_ipc_data_worker, (gpointer)m, &error);
-       if (m->ch[MUSE_CHANNEL_DATA].data_thread == NULL && error) {
+       if (!m->ch[MUSE_CHANNEL_DATA].data_thread && error) {
                LOGE("thread creation failed : %s", error->message);
                g_error_free(error);
                ms_log_process_info(ms_get_instance()->pid);
                ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
+               muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
        }
 
        MUSE_FREE(job);
index 4c7b47f..da6fc7c 100644 (file)
@@ -91,7 +91,7 @@ GModule *ms_module_open(int idx)
 
        g_mutex_lock(&module->lock);
 
-       if (ms_module_get_loaded_dllsym(idx) == false) {
+       if (!ms_module_get_loaded_dllsym(idx)) {
                dllsym = g_module_open(ms_config_get_path(idx), G_MODULE_BIND_LAZY);
 
                if (!dllsym)
index f222590..1f5cef7 100644 (file)
@@ -344,8 +344,8 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
                }
        }
 
-       job = malloc(sizeof(ms_workqueue_job_t));
-       if (job == NULL) {
+       job = calloc(1, sizeof(ms_workqueue_job_t));
+       if (!job) {
                LOGE("failed to allocate memory for job state");
                goto out;
        }
@@ -605,7 +605,7 @@ int ms_run(void)
        muse_server->main_loop = g_main_loop_new(NULL, FALSE);
 
        muse_server->diag_thread = g_thread_try_new("muse_server_diag_thread", _ms_diag_thread, muse_server->main_loop, &error);
-       if (muse_server->diag_thread == NULL && error) {
+       if (!muse_server->diag_thread && error) {
                snprintf(err_msg, sizeof(err_msg), "diag_thread creation failed : %s", error->message);
                LOGE("%s", err_msg);
                g_error_free(error);
@@ -767,7 +767,7 @@ gboolean ms_init_bufmgr(void)
        LOGD("Enter");
 
        muse_server->bufmgr = tbm_bufmgr_init(-1);
-       if (muse_server->bufmgr == NULL) {
+       if (!muse_server->bufmgr) {
                LOGE("Error - tbm_bufmgr_init");
                return FALSE;
        }
index 990566e..aa928ba 100644 (file)
@@ -114,7 +114,7 @@ static void _ms_signal_backtrace(void *arg)
        trace[1] = (void *) uctxt->uc_mcontext.gregs[REG_RIP];
        #endif
        strings = backtrace_symbols(trace, tracesize);
-       if (strings == NULL) {
+       if (!strings) {
                strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
                LOGE("backtrace_symbols error: %s", err_msg);
        } else {
index c03e499..c2d2fab 100644 (file)
@@ -143,7 +143,7 @@ void ms_system_init(ms_system_t *system)
        LOGD("Enter");
 
        system->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (system->connection == NULL) {
+       if (!system->connection) {
                if (error) {
                        LOGE("fail to get gdbus connection (%s)", error->message);
                        g_error_free(error);
index 9151bad..979fe6f 100644 (file)
@@ -49,7 +49,7 @@ static int _ms_tool_getopt(int argc, char **argv, const char *opts)
                        return(EOF);
        }
        ms_tool_optopt = ri = argv[ms_tool_optind][si];
-       if (ri == ':' || (cp = strchr(opts, ri)) == NULL) {
+       if (ri == ':' || !(cp = strchr(opts, ri))) {
                if (argv[ms_tool_optind][++si] == '\0') {
                        ms_tool_optind++;
                        si = 1;
index 80ad01f..c6f1d88 100644 (file)
@@ -31,7 +31,7 @@ static void *_ms_workqueue_worker_function(void *ptr)
        while (1) {
                /* Wait until we get notified. */
                pthread_mutex_lock(&worker->workqueue->jobs_mutex);
-               while (worker->workqueue->waiting_jobs == NULL) {
+               while (!worker->workqueue->waiting_jobs) {
                        /* If we're supposed to terminate, break out of our continuous loop. */
                        if (worker->terminate)
                                break;
@@ -50,11 +50,11 @@ static void *_ms_workqueue_worker_function(void *ptr)
                pthread_mutex_unlock(&worker->workqueue->jobs_mutex);
 
                /* If we didn't get a job, then there's nothing to do at this time. */
-               if (job == NULL)
+               if (!job)
                        continue;
 
                /* Execute the job. */
-               if (job->job_function(job) != TRUE) {
+               if (!job->job_function(job)) {
                        snprintf(err_msg, sizeof(err_msg), "Error - Execute the workqueue job, Restart muse server...");
                        LOGE("%s", err_msg);
                        ms_respawn(SIGABRT);