Update dispatch info and check the pid and log fd are valid when muse crash 71/95971/11
authorYoungHun Kim <yh8004.kim@samsung.com>
Mon, 7 Nov 2016 07:46:24 +0000 (16:46 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Fri, 11 Nov 2016 08:03:19 +0000 (17:03 +0900)
Change-Id: I938e3b2170e764ff2b69ea8cc5bff247ba7b4b50

12 files changed:
include/muse_core_ipc.h
include/muse_core_log.h
src/muse_core.c
src/muse_core_config.c
src/muse_core_ipc.c
src/muse_core_log.c
src/muse_core_module.c
src/muse_core_msg_json.c
src/muse_core_security.c
src/muse_core_server.c
src/muse_core_tool.c
src/muse_core_workqueue.c

index a79ce71..03cab32 100644 (file)
@@ -67,7 +67,7 @@ intptr_t muse_core_ipc_get_handle(muse_module_h module);
 int muse_core_ipc_set_handle(muse_module_h module, intptr_t handle);
 int muse_core_ipc_get_fd(muse_module_h module, int *fd);
 int muse_core_ipc_set_fd(muse_module_h module, int fd);
-gboolean muse_core_ipc_is_valid_fd(int fd);
+gboolean muse_core_ipc_fd_is_valid(int fd);
 void muse_core_ipc_delete_data(char *data);
 int muse_core_ipc_get_bufmgr(tbm_bufmgr *bufmgr);
 int muse_core_ipc_get_gdbus_connection(GDBusConnection **gdbus_conn);
index 8544ce3..d4edb80 100644 (file)
@@ -43,7 +43,9 @@ typedef struct muse_core_log {
        void (*set_msg) (char *);
        char* (*get_msg) (void);
        void (*flush_msg) (void);
+       void (*log_api_name) (gpointer);
        void (*free) (void);
+       GMutex log_lock;
 } muse_core_log_t;
 
 /*muse_core_log_init must be called before muse_core_log_get_instance*/
index aeab874..f41b3a0 100644 (file)
@@ -153,7 +153,7 @@ static muse_core_t *_muse_core_create_new_server_from_fd(int fd[], int type)
 
        LOGD("Enter");
        server = malloc(sizeof(muse_core_t));
-       g_return_val_if_fail(server != NULL, NULL);
+       g_return_val_if_fail(server, NULL);
 
        server->fd = fd[MUSE_CHANNEL_MSG];
        server->data_fd = fd[MUSE_CHANNEL_DATA];
@@ -184,7 +184,7 @@ static int _muse_core_free(muse_core_t *server)
        int i;
        LOGD("Enter");
 
-       g_return_val_if_fail(server != NULL, retval);
+       g_return_val_if_fail(server, retval);
 
        retval = server->retval;
        close(server->fd);
@@ -604,10 +604,10 @@ void muse_core_log_process_info(int pid)
        fp = popen(cmd, "r");
 
        if (fp) {
-               while(fgets(buf, MUSE_MAX_PARAM_STRLEN, fp) != NULL)
+               while (fgets(buf, MUSE_MAX_PARAM_STRLEN, fp))
                        LOGD("%s", buf);
 
                if (pclose(fp) == -1)
                        LOGE("Fail to pclose");
        }
-}
\ No newline at end of file
+}
index 60ff10e..8d26e53 100644 (file)
@@ -41,13 +41,13 @@ static int _muse_core_config_parser(void)
        int ret = -1;
        char *ptr = NULL;
 
-       g_return_val_if_fail(g_muse_core_conf != NULL, ret);
+       g_return_val_if_fail(g_muse_core_conf, ret);
 
        g_muse_core_conf->muse_dict = iniparser_load(CONFFILE);
-       g_return_val_if_fail(g_muse_core_conf->muse_dict != NULL, ret);
+       g_return_val_if_fail(g_muse_core_conf->muse_dict, ret);
 
        str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSEHOST, NULL);
-       g_return_val_if_fail(str != NULL, ret);
+       g_return_val_if_fail(str, ret);
 
        g_muse_core_conf->hosts = strdup(str);
        if (!g_muse_core_conf->hosts) {
@@ -56,7 +56,7 @@ static int _muse_core_config_parser(void)
        }
 
        str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSELOG, NULL);
-       g_return_val_if_fail(str != NULL, ret);
+       g_return_val_if_fail(str, ret);
 
        g_muse_core_conf->logfile = strdup(str);
        if (!g_muse_core_conf->logfile) {
@@ -88,7 +88,7 @@ static int _muse_core_config_parser(void)
        g_muse_core_conf->type = 0;
        host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
 
-       while (host != NULL) {
+       while (host) {
                g_strstrip(host);
                g_muse_core_conf->host[g_muse_core_conf->type] = strdup(host);
                LOGD("host: %s", g_muse_core_conf->host[g_muse_core_conf->type]);
@@ -151,7 +151,7 @@ static void _muse_core_config_free(void)
        int i = 0;
        char *ptr = NULL;
 
-       g_return_if_fail(g_muse_core_conf != NULL);
+       g_return_if_fail(g_muse_core_conf);
 
        if (g_muse_core_conf->muse_dict)
                iniparser_freedict(g_muse_core_conf->muse_dict);
@@ -159,7 +159,7 @@ static void _muse_core_config_free(void)
        host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
        g_muse_core_conf->type = 0;
 
-       while (host != NULL) {
+       while (host) {
                LOGD("host: %s", host);
                MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]->path);
                MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]->preloaded);
@@ -181,12 +181,12 @@ static void _muse_core_config_free(void)
 static void _muse_core_config_init_instance(void (*free)(void), char* (*get_path)(int), char* (*get_preloaded)(int), int (*get_gst_param_cnt)(void),
        char* (*get_gst_param_str)(int), char* (*get_host)(int), int (*get_host_cnt)(void))
 {
-       g_return_if_fail(free != NULL);
-       g_return_if_fail(get_path != NULL);
+       g_return_if_fail(free);
+       g_return_if_fail(get_path);
        g_return_if_fail(g_muse_core_conf == NULL);
 
        g_muse_core_conf = calloc(1, sizeof(*g_muse_core_conf));
-       g_return_if_fail(g_muse_core_conf != NULL);
+       g_return_if_fail(g_muse_core_conf);
        g_muse_core_conf->hosts = NULL;
        g_muse_core_conf->type = 0;
        g_muse_core_conf->logfile = NULL;
@@ -206,31 +206,31 @@ static void _muse_core_config_init_instance(void (*free)(void), char* (*get_path
 
 static char *_muse_core_config_get_host(int index)
 {
-       g_return_val_if_fail(g_muse_core_conf->host != NULL, NULL);
+       g_return_val_if_fail(g_muse_core_conf->host, NULL);
        return g_muse_core_conf->host[index];
 }
 
 static int _muse_core_config_get_host_cnt(void)
 {
-       g_return_val_if_fail(g_muse_core_conf != NULL, 0);
+       g_return_val_if_fail(g_muse_core_conf, 0);
        return g_muse_core_conf->type;
 }
 
 static int _muse_core_config_get_gst_param_cnt(void)
 {
-       g_return_val_if_fail(g_muse_core_conf != NULL, 0);
+       g_return_val_if_fail(g_muse_core_conf, 0);
        return g_muse_core_conf->gst_param_cnt;
 }
 
 static char *_muse_core_config_get_gst_param_str(int idx)
 {
-       g_return_val_if_fail(g_muse_core_conf->gst_param_str[idx] != NULL, NULL);
+       g_return_val_if_fail(g_muse_core_conf->gst_param_str[idx], NULL);
        return g_muse_core_conf->gst_param_str[idx];
 }
 
 static char *_muse_core_config_get_path(int api_client)
 {
-       g_return_val_if_fail(g_muse_core_conf->host_infos[api_client]->path != NULL, NULL);
+       g_return_val_if_fail(g_muse_core_conf->host_infos[api_client]->path, NULL);
 
        LOGD("%s", g_muse_core_conf->host_infos[api_client]->path);
        return g_muse_core_conf->host_infos[api_client]->path;
@@ -238,7 +238,7 @@ static char *_muse_core_config_get_path(int api_client)
 
 static char *_muse_core_config_get_preloaded(int api_client)
 {
-       g_return_val_if_fail(g_muse_core_conf->host_infos[api_client]->preloaded!= NULL, NULL);
+       g_return_val_if_fail(g_muse_core_conf->host_infos[api_client]->preloaded, NULL);
 
        return g_muse_core_conf->host_infos[api_client]->preloaded;
 }
index 07bfd9c..9375f49 100644 (file)
@@ -75,7 +75,7 @@ static int _muse_core_ipc_get_valid_fd_count(int *fds);
 
 static void _muse_core_ipc_client_cleanup(muse_module_h module)
 {
-       g_return_if_fail(module != NULL);
+       g_return_if_fail(module);
 
 #ifndef MUSE_NO_LOG
        muse_core_log_get_instance()->flush_msg();
@@ -104,10 +104,10 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
        gboolean value = TRUE;
        void *jobj = NULL;
        char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
-       g_return_val_if_fail(data != NULL, NULL);
+       g_return_val_if_fail(data, NULL);
        int tbm_fd[MUSE_NUM_FD] = { SOCK_ERR, };
        module = (muse_module_h)data;
-       g_return_val_if_fail(module != NULL, NULL);
+       g_return_val_if_fail(module, NULL);
 
        LOGD("Enter");
 
@@ -127,21 +127,21 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
 #ifndef MUSE_NO_LOG
                        muse_core_log_get_instance()->log(module->recvMsg);
 #endif
-                       while (module->msg_offset < len) {
 
+                       while (module->msg_offset < len) {
                                jobj = muse_core_msg_json_object_new(module->recvMsg+module->msg_offset, &parse_len, NULL);
                                if (jobj == NULL) {
                                        LOGE("jobj is null");
                                        break;
                                }
 
-                               if (muse_core_msg_json_object_get_value(MUSE_API, jobj, &cmd, MUSE_TYPE_INT) ==TRUE) {
+                               if (muse_core_msg_json_object_get_value(MUSE_API, jobj, &cmd, MUSE_TYPE_INT)) {
                                        switch (cmd) {
                                        module->disp_api = cmd;
                                        case API_CREATE:
                                                LOGD("CREATE ### %p", module);
                                                pthread_mutex_lock(&muse_core_workqueue_get_instance()->jobs_mutex);
-                                               if (muse_core_msg_json_object_get_value(MUSE_MODULE, jobj, &api_module, MUSE_TYPE_INT) == TRUE) {
+                                               if (muse_core_msg_json_object_get_value(MUSE_MODULE, jobj, &api_module, MUSE_TYPE_INT)) {
                                                        module->api_module = api_module;
                                                        module->is_create_api_called = true;
                                                        module->ch[MUSE_CHANNEL_MSG].dll_handle = muse_core_module_get_instance()->load(api_module);
@@ -166,7 +166,7 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
 
                                                        pthread_mutex_lock(&muse_core_workqueue_get_instance()->jobs_mutex);
 
-                                                       if (muse_core_msg_json_object_get_value(MUSE_MODULE, jobj, &api_module, MUSE_TYPE_INT) == TRUE) {
+                                                       if (muse_core_msg_json_object_get_value(MUSE_MODULE, jobj, &api_module, MUSE_TYPE_INT)) {
                                                                module->api_module = api_module;
                                                                module->ch[MUSE_CHANNEL_DATA].queue = g_queue_new();
                                                                g_mutex_init(&module->ch[MUSE_CHANNEL_DATA].mutex);
@@ -217,6 +217,7 @@ static gpointer _muse_core_ipc_data_worker(gpointer data)
        int qDataSize = 0;
        void *jobj = NULL;
        intptr_t module_addr = 0;
+       muse_recv_data_t *qData = NULL;
        char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
        g_return_val_if_fail(fd > 0, NULL);
 
@@ -243,9 +244,9 @@ static gpointer _muse_core_ipc_data_worker(gpointer data)
                        break;
                } else {
                        if (module) {
-                               muse_recv_data_t *qData;
                                module->ch[MUSE_CHANNEL_DATA].fd = fd;
-                               while ((qData = _muse_core_ipc_new_qdata(&recvBuff, currLen, &allocSize)) != NULL) {
+                               qData = _muse_core_ipc_new_qdata(&recvBuff, currLen, &allocSize);
+                               while (qData) {
                                        qDataSize = qData->header.size + sizeof(muse_recv_data_head_t);
                                        if (currLen > qDataSize) {
                                                allocSize = allocSize - qDataSize;
@@ -280,7 +281,7 @@ static gpointer _muse_core_ipc_data_worker(gpointer data)
 
                                if (module) {
                                        module->ch[MUSE_CHANNEL_DATA].p_gthread = g_thread_self();
-                                       g_return_val_if_fail(module->ch[MUSE_CHANNEL_DATA].p_gthread != NULL, NULL);
+                                       g_return_val_if_fail(module->ch[MUSE_CHANNEL_DATA].p_gthread, NULL);
                                        module->ch[MUSE_CHANNEL_DATA].fd = fd;
                                } else {
                                        LOGE("we have to check %s", recvBuff);
@@ -338,7 +339,7 @@ static size_t _muse_core_ipc_get_complete_msg_len(int sock_fd, char *msg)
        if (g_muse_core_ipc == NULL)
                return 0;
 
-       g_return_val_if_fail(msg != NULL, 0);
+       g_return_val_if_fail(msg, 0);
 
        muse_msg = (muse_msg_h)g_hash_table_lookup(g_muse_core_ipc->table, GINT_TO_POINTER(sock_fd));
 
@@ -375,7 +376,7 @@ static int _muse_core_ipc_verify_msg_complete(int sock_fd, char *msg, int msg_le
        gpointer orig_value;
        muse_msg_h muse_msg = NULL;
 
-       g_return_val_if_fail(msg != NULL, 0);
+       g_return_val_if_fail(msg, 0);
 
        if (msg_len > MUSE_MSG_MAX_LENGTH)
                msg_len = MUSE_MSG_MAX_LENGTH;
@@ -422,7 +423,7 @@ static gboolean _muse_core_ipc_init_bufmgr(void)
 {
        LOGD("Enter");
 
-       g_return_val_if_fail(g_muse_core_ipc != NULL, FALSE);
+       g_return_val_if_fail(g_muse_core_ipc, FALSE);
 
        g_muse_core_ipc->bufmgr = tbm_bufmgr_init(-1);
        if (g_muse_core_ipc->bufmgr == NULL) {
@@ -439,7 +440,7 @@ static gboolean _muse_core_ipc_get_gdbus(void)
        LOGD("Enter");
        GError *error = NULL;
 
-       g_return_val_if_fail(g_muse_core_ipc != NULL, FALSE);
+       g_return_val_if_fail(g_muse_core_ipc, FALSE);
 
        g_muse_core_ipc->gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
        if (g_muse_core_ipc->gdbus_conn == NULL) {
@@ -470,7 +471,7 @@ static void _muse_core_ipc_free(void)
 {
        LOGD("Enter");
 
-       g_return_if_fail(g_muse_core_ipc != NULL);
+       g_return_if_fail(g_muse_core_ipc);
 
        _muse_core_ipc_deinit_bufmgr();
 
@@ -487,18 +488,18 @@ static void _muse_core_ipc_free(void)
 
 static void _muse_core_ipc_init_instance(void (*free)(void))
 {
-       g_return_if_fail(free != NULL);
+       g_return_if_fail(free);
        g_return_if_fail(g_muse_core_ipc == NULL);
 
        g_muse_core_ipc = calloc(1, sizeof(*g_muse_core_ipc));
-       g_return_if_fail(g_muse_core_ipc != NULL);
+       g_return_if_fail(g_muse_core_ipc);
 
-       g_return_if_fail(_muse_core_ipc_init_bufmgr() == TRUE);
+       g_return_if_fail(_muse_core_ipc_init_bufmgr());
 
-       g_return_if_fail(_muse_core_ipc_get_gdbus() == TRUE);
+       g_return_if_fail(_muse_core_ipc_get_gdbus());
 
        g_muse_core_ipc->table = g_hash_table_new(g_direct_hash, g_direct_equal);
-       g_return_if_fail(g_muse_core_ipc->table != NULL);
+       g_return_if_fail(g_muse_core_ipc->table);
 
        g_muse_core_ipc->free = free;
 }
@@ -518,10 +519,10 @@ int muse_core_ipc_get_client_from_job(muse_core_workqueue_job_t *job)
        LOGD("Enter");
        muse_module_h module = NULL;
 
-       g_return_val_if_fail(job != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(job, MM_ERROR_INVALID_ARGUMENT);
 
        module = (muse_module_h) job->user_data;
-       g_return_val_if_fail(module != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(module, MM_ERROR_INVALID_ARGUMENT);
 
        LOGD("Leave");
        return module->api_module;
@@ -533,10 +534,10 @@ gboolean muse_core_ipc_job_function(muse_core_workqueue_job_t *job)
        muse_module_h module = NULL;
        GError *error = NULL;
 
-       g_return_val_if_fail(job != NULL, FALSE);
+       g_return_val_if_fail(job, FALSE);
 
        module = (muse_module_h) job->user_data;
-       g_return_val_if_fail(module != NULL, FALSE);
+       g_return_val_if_fail(module, FALSE);
 
        LOGD("[%p] client's msg channel fd : %d", module, module->ch[MUSE_CHANNEL_MSG].fd);
 
@@ -549,7 +550,7 @@ gboolean muse_core_ipc_job_function(muse_core_workqueue_job_t *job)
        }
 
        MUSE_FREE(job);
-       g_return_val_if_fail(module->ch[MUSE_CHANNEL_MSG].p_gthread != NULL, FALSE);
+       g_return_val_if_fail(module->ch[MUSE_CHANNEL_MSG].p_gthread, FALSE);
 
        LOGD("Leave");
        return TRUE;
@@ -562,7 +563,7 @@ gboolean muse_core_ipc_data_job_function(muse_core_workqueue_job_t *job)
        GError *error = NULL;
        GThread *p_gthread = NULL;
 
-       g_return_val_if_fail(job != NULL, FALSE);
+       g_return_val_if_fail(job, FALSE);
 
        fd = GPOINTER_TO_INT(job->user_data);
        g_return_val_if_fail(fd > 0, FALSE);
@@ -574,7 +575,7 @@ gboolean muse_core_ipc_data_job_function(muse_core_workqueue_job_t *job)
                g_error_free (error);
 
        MUSE_FREE(job);
-       g_return_val_if_fail(p_gthread != NULL, FALSE);
+       g_return_val_if_fail(p_gthread, FALSE);
 
        LOGD("Leave");
        return TRUE;
@@ -582,7 +583,7 @@ gboolean muse_core_ipc_data_job_function(muse_core_workqueue_job_t *job)
 
 int muse_core_ipc_send_msg(int sock_fd, const char *msg)
 {
-       g_return_val_if_fail(msg != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(msg, MM_ERROR_INVALID_ARGUMENT);
        return muse_core_ipc_send_fd_msg(sock_fd, NULL, msg);
 }
 
@@ -597,7 +598,7 @@ int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf)
        int *fdptr;
        int fd_cnt = 0;
 
-       g_return_val_if_fail(buf != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(buf, MM_ERROR_INVALID_ARGUMENT);
 
 #ifndef MUSE_NO_LOG
        muse_core_log_get_instance()->log((char*)buf);
@@ -645,7 +646,7 @@ int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf)
 
 int muse_core_ipc_recv_msg(int sock_fd, char *msg)
 {
-       g_return_val_if_fail(msg != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(msg, MM_ERROR_INVALID_ARGUMENT);
        return muse_core_ipc_recv_fd_msg(sock_fd, msg, NULL);
 }
 
@@ -659,7 +660,7 @@ int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd)
        char data[CMSG_SPACE(sizeof(int) * MUSE_NUM_FD)];
        char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
 
-       g_return_val_if_fail(buf != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(buf, MM_ERROR_INVALID_ARGUMENT);
 
        completed_msg_len = _muse_core_ipc_get_complete_msg_len(sock_fd, buf);
 
@@ -706,7 +707,7 @@ int muse_core_ipc_push_data(int sock_fd, const char *data, int size, uint64_t da
        int ret = MM_ERROR_NONE;
 
        muse_recv_data_head_t header;
-       g_return_val_if_fail(data != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(data, MM_ERROR_INVALID_ARGUMENT);
 
        header.marker = MUSE_DATA_HEAD;
        header.size = size;
@@ -800,7 +801,7 @@ int muse_core_ipc_set_fd(muse_module_h module, int fd)
 {
        g_return_val_if_fail(module, MM_ERROR_INVALID_ARGUMENT);
 
-       if ((muse_core_ipc_is_valid_fd(fd) != TRUE) && (fd > STDERR_FILENO)) {
+       if (muse_core_ipc_fd_is_valid(fd) != TRUE) {
                LOGE("invalid fd: %d", fd);
                return MM_ERROR_INVALID_ARGUMENT;
        }
@@ -809,7 +810,7 @@ int muse_core_ipc_set_fd(muse_module_h module, int fd)
        return MM_ERROR_NONE;
 }
 
-gboolean muse_core_ipc_is_valid_fd(int fd)
+gboolean muse_core_ipc_fd_is_valid(int fd)
 {
        return (fcntl(fd, F_GETFL) != -1 || errno != EBADF) && (fd > STDERR_FILENO);
 }
index b17fcac..8ee1f77 100644 (file)
 #ifndef MUSE_NO_LOG
 static muse_core_log_t *g_muse_core_log = NULL;
 
+static gboolean _muse_core_log_pid_is_valid(pid_t pid);
 static void _muse_core_log_pid_info(pid_t pid);
 static void _muse_core_log_cmdline(pid_t pid);
 static void _muse_core_log_process_info(pid_t pid);
+static void _muse_core_log_api_name(gpointer ptr);
 static void _muse_core_log_api_info(void);
 static void _muse_core_log_binary_info(void);
 static void _muse_core_log_sig_abort(int signo, pid_t pid);
@@ -58,7 +60,7 @@ static int _muse_core_log_fd_set_block(int fd);
 static void _muse_core_log_sigaction(int signo, siginfo_t *si, void *arg);
 static void _muse_core_log_set_log_fd(void);
 static void _muse_core_log_init_instance(void (*log)(char *), void (*log_attr)(const char *, ...), void (*fatal)(char *), void (*set_msg) (char *),
-                                               char * (*get_msg) (void), void (*flush_msg) (void), void (*free) (void));
+                                               char * (*get_msg) (void), void (*flush_msg) (void), void (*log_api_name) (gpointer), void (*free) (void));
 static void _muse_core_log_write_buffer(const void *buf, size_t len);
 static void _muse_core_log_attributes(const char *msg, ...);
 static void _muse_core_log_monitor(char *msg);
@@ -68,14 +70,32 @@ static char *_muse_core_log_get_msg(void);
 static void _muse_core_log_flush_msg(void);
 static void _muse_core_log_free(void);
 
+static gboolean _muse_core_log_pid_is_valid(pid_t pid)
+{
+       char client_buf[MAX_ERROR_MSG_LEN];
+
+       snprintf(client_buf, sizeof(client_buf), "/proc/%d", (int)pid);
+
+       if (access(client_buf, F_OK) != 0) {
+               LOGD("%d process doesn't exist", (int)pid);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 static void _muse_core_log_pid_info(pid_t pid)
 {
        char client_buf[MAX_ERROR_MSG_LEN];
 
-       snprintf(client_buf, sizeof(client_buf), "[PID] %d", (int) pid);
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
+       g_return_if_fail(_muse_core_log_pid_is_valid(pid));
+
+       snprintf(client_buf, sizeof(client_buf), "[PID] %d", (int)pid);
        if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
                LOGE("There was an error writing client pid to logfile");
-       else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
+       else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
                LOGE("%s", client_buf);
 }
 
@@ -84,7 +104,11 @@ static void _muse_core_log_cmdline(pid_t pid)
        char client_buf[MAX_ERROR_MSG_LEN];
        FILE *fp;
 
-       snprintf(client_buf, sizeof(client_buf), "/proc/%d/cmdline", (int) pid);
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
+       g_return_if_fail(_muse_core_log_pid_is_valid(pid));
+
+       snprintf(client_buf, sizeof(client_buf), "/proc/%d/cmdline", (int)pid);
        fp = fopen(client_buf, "r");
        if (fp) {
                size_t size = fread(client_buf, sizeof(char), MAX_ERROR_MSG_LEN, fp);
@@ -92,7 +116,7 @@ static void _muse_core_log_cmdline(pid_t pid)
 
                if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
                        LOGE("There was an error writing client name to logfile");
-               else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
+               else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
                        LOGE("[Process Name] %s", client_buf);
 
                fclose(fp);
@@ -104,12 +128,16 @@ static void _muse_core_log_process_info(pid_t pid)
        char client_buf[MAX_ERROR_MSG_LEN];
        FILE *fp;
 
-       snprintf(client_buf, sizeof(client_buf), "ps -Lo pcpu,pmem,tid,comm -p %d", (int) pid);
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
+       g_return_if_fail(_muse_core_log_pid_is_valid(pid));
+
+       snprintf(client_buf, sizeof(client_buf), "ps -Lo pcpu,pmem,tid,comm -p %d", (int)pid);
        fp = popen(client_buf, "r");
        if (fp) {
                if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
-                       LOGE("muse-server %d writing command to logfile", (int) pid);
-               else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
+                       LOGE("muse-server %d writing command to logfile", (int)pid);
+               else if (write(g_muse_core_log->log_fd, "\0", 1) == WRITE_FAIL)
                        LOGE("Fail to write process command");
 
                while (fgets(client_buf, MAX_ERROR_MSG_LEN, fp)) {
@@ -121,22 +149,38 @@ static void _muse_core_log_process_info(pid_t pid)
        }
 }
 
+static void _muse_core_log_api_name(gpointer ptr)
+{
+       Dl_info info;
+
+       g_return_if_fail(ptr);
+
+       memset(&info, 0, sizeof(info));
+
+       if (dladdr((const void *) ptr, &info) && info.dli_sname)
+               _muse_core_log_monitor((char *)info.dli_sname);
+       else
+               LOGE("fail to log api name");
+}
+
 static void _muse_core_log_api_info(void)
 {
+       Dl_info info;
        char client_buf[MAX_ERROR_MSG_LEN];
-       int i;
        gpointer ptr;
-       Dl_info info;
+       int i;
 
-       memset(&info, 0, sizeof(info));
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
 
        for (i = 0; i < MUSE_MODULE_MAX; i++) {
                muse_core_module_get_instance()->get_value(i, DISPATCHER_PTR, &ptr);
+               memset(&info, 0, sizeof(info));
                if (dladdr((const void *) ptr, &info) && info.dli_sname) {
-                       snprintf(client_buf, sizeof(client_buf), "[The latest called api name] %s [The latest message] %s", info.dli_sname, _muse_core_log_get_msg());
+                       snprintf(client_buf, sizeof(client_buf), "[The latest called api name] %s [The latest message] %s", (char *)info.dli_sname, _muse_core_log_get_msg());
                        if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
                                LOGE("There was an error writing client's latest called api to logfile");
-                       else if (write(g_muse_core_log->log_fd, "\n", 1) != WRITE_FAIL)
+                       else if (write(g_muse_core_log->log_fd, "\0", 1) != WRITE_FAIL)
                                LOGE("%s", client_buf);
                }
        }
@@ -150,6 +194,9 @@ static void _muse_core_log_binary_info(void)
        char *value;
        char *ptr = NULL;
 
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
+
        snprintf(client_buf, sizeof(client_buf), "/etc/tizen-release");
 
        fp = fopen(client_buf, "r");
@@ -238,8 +285,8 @@ static void _muse_core_log_sigaction(int signo, siginfo_t *si, void *arg)
        ucontext_t *uctxt = NULL;
        char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
 
-       g_return_if_fail(si != NULL);
-       g_return_if_fail(arg != NULL);
+       g_return_if_fail(si);
+       g_return_if_fail(arg);
 
        LOGE("----------BEGIN MUSE DYING MESSAGE----------");
 
@@ -312,8 +359,10 @@ static void _muse_core_log_create_fd(void)
        LOGD("filename: %s", file[selected_index]);
        /* open log file again */
        g_muse_core_log->log_fd = _muse_core_log_open_work(file[selected_index]);
-       if (g_muse_core_log->log_fd < 0)
+       if (!muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd))
                LOGE("couldn't open log file");
+       else
+               LOGD("log fd : %d", g_muse_core_log->log_fd);
 
        return;
 }
@@ -321,10 +370,12 @@ static void _muse_core_log_create_fd(void)
 static void _muse_core_log_set_log_fd(void)
 {
        char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
-       g_return_if_fail(g_muse_core_log != NULL);
+       g_return_if_fail(g_muse_core_log);
 
        _muse_core_log_create_fd();
 
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
+
        if (fcntl(g_muse_core_log->log_fd, F_SETFD, FD_CLOEXEC) < 0) {
                strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN);
                LOGE("unable to set CLO_EXEC on log fd %d: %s", g_muse_core_log->log_fd, err_msg);
@@ -334,14 +385,14 @@ static void _muse_core_log_set_log_fd(void)
 }
 
 static void _muse_core_log_init_instance(void (*log)(char *), void (*log_attr)(const char *, ...), void (*fatal)(char *), void (*set_msg) (char *),
-                                               char * (*get_msg) (void), void (*flush_msg) (void), void (*free) (void))
+                                               char* (*get_msg) (void), void (*flush_msg) (void), void (*log_api_name) (gpointer), void (*free) (void))
 {
-       g_return_if_fail(log != NULL);
-       g_return_if_fail(fatal != NULL);
+       g_return_if_fail(log);
+       g_return_if_fail(fatal);
        g_return_if_fail(g_muse_core_log == NULL);
 
        g_muse_core_log = calloc(1, sizeof(*g_muse_core_log));
-       g_return_if_fail(g_muse_core_log != NULL);
+       g_return_if_fail(g_muse_core_log);
        memset(g_muse_core_log->buf, 0, MUSE_MSG_MAX_LENGTH + 1);
        g_muse_core_log->size = 0;
        memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
@@ -351,30 +402,27 @@ static void _muse_core_log_init_instance(void (*log)(char *), void (*log_attr)(c
        g_muse_core_log->set_msg = set_msg;
        g_muse_core_log->get_msg = get_msg;
        g_muse_core_log->flush_msg = flush_msg;
+       g_muse_core_log->log_api_name = log_api_name;
        g_muse_core_log->free = free;
+       g_mutex_init(&g_muse_core_log->log_lock);
 }
 
 static void
 _muse_core_log_write_buffer(const void *buf, size_t len)
 {
-       g_return_if_fail(buf != NULL);
+       g_return_if_fail(buf);
+       g_return_if_fail(g_muse_core_log);
+
        memcpy(g_muse_core_log->cache + strlen(g_muse_core_log->cache), buf, len);
-       memcpy(g_muse_core_log->cache + strlen(g_muse_core_log->cache), "\n", 1);
+       memcpy(g_muse_core_log->cache + strlen(g_muse_core_log->cache), "\0", 1);
 }
 
-
 static void _muse_core_log_attributes(const char *msg, ...)
 {
        va_list ap;
        char buf[MUSE_MSG_MAX_LENGTH + 1] = {0,};
 
-       g_return_if_fail(msg != NULL);
-       g_return_if_fail(g_muse_core_log != NULL);
-
-       if (g_muse_core_log->log_fd < 0) {
-               LOGE("Error - log fd");
-               return;
-       }
+       g_return_if_fail(msg);
 
        va_start(ap, msg);
        vsnprintf(buf, sizeof(buf), msg, ap);
@@ -385,22 +433,23 @@ static void _muse_core_log_attributes(const char *msg, ...)
 
 static void _muse_core_log_monitor(char *msg)
 {
-       g_return_if_fail(msg != NULL);
-       g_return_if_fail(g_muse_core_log != NULL);
+       g_return_if_fail(msg);
+       g_return_if_fail(g_muse_core_log);
 
-       if (g_muse_core_log->log_fd < 0) {
-               LOGE("Error - log fd");
-               return;
-       }
+       g_mutex_lock(&g_muse_core_log->log_lock);
 
-       if (strlen(g_muse_core_log->cache) + strlen(msg) < MUSE_LOG_MSG_CACHE_MAX_LENGTH) {
-               _muse_core_log_write_buffer(msg, strlen(msg));
-       } else {
-               if (write(g_muse_core_log->log_fd, g_muse_core_log->cache, strlen(g_muse_core_log->cache)) != WRITE_FAIL) {
-                       memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
+       if (muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd)) {
+               if (strlen(g_muse_core_log->cache) + strlen(msg) < MUSE_LOG_MSG_CACHE_MAX_LENGTH) {
                        _muse_core_log_write_buffer(msg, strlen(msg));
+               } else {
+                       if (write(g_muse_core_log->log_fd, g_muse_core_log->cache, strlen(g_muse_core_log->cache)) != WRITE_FAIL) {
+                               memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
+                               _muse_core_log_write_buffer(msg, strlen(msg));
+                       }
                }
        }
+
+       g_mutex_unlock(&g_muse_core_log->log_lock);
 }
 
 static void _muse_core_log_fatal(char *msg)
@@ -417,6 +466,8 @@ static void _muse_core_log_free(void)
 {
        LOGD("Enter");
 
+       g_mutex_clear(&g_muse_core_log->log_lock);
+
        MUSE_FREE(g_muse_core_log);
 
        LOGD("Leave");
@@ -424,8 +475,8 @@ static void _muse_core_log_free(void)
 
 static void _muse_core_log_set_msg(char *msg)
 {
-       g_return_if_fail(g_muse_core_log != NULL);
-       g_return_if_fail(msg != NULL);
+       g_return_if_fail(g_muse_core_log);
+       g_return_if_fail(msg);
 
        size_t size = strlen(msg);
 
@@ -437,31 +488,32 @@ static void _muse_core_log_set_msg(char *msg)
 
 static char *_muse_core_log_get_msg(void)
 {
-       g_return_val_if_fail(g_muse_core_log != NULL, NULL);
-       g_return_val_if_fail(g_muse_core_log->buf != NULL, NULL);
+       g_return_val_if_fail(g_muse_core_log, NULL);
+       g_return_val_if_fail(g_muse_core_log->buf, NULL);
 
        return g_muse_core_log->buf;
 }
 
 static void _muse_core_log_flush_msg(void)
 {
-       g_return_if_fail(g_muse_core_log->cache != NULL);
+       g_return_if_fail(g_muse_core_log->cache);
+       g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
 
        size_t str_len = strlen(g_muse_core_log->cache);
 
        if (str_len < MUSE_MSG_MAX_LENGTH) {
-               if (write(g_muse_core_log->log_fd, g_muse_core_log->cache, str_len) != (int) str_len)
+               if (write(g_muse_core_log->log_fd, g_muse_core_log->cache, str_len) == WRITE_FAIL)
                        LOGE("There was an error writing to logfile [%d] %s", str_len, g_muse_core_log->cache);
-       } else {
-               memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
        }
+
+       memset(g_muse_core_log->cache, 0, MUSE_LOG_MSG_CACHE_MAX_LENGTH + 1);
 }
 
 muse_core_log_t *muse_core_log_get_instance(void)
 {
        if (g_muse_core_log == NULL)
                _muse_core_log_init_instance(_muse_core_log_monitor, _muse_core_log_attributes, _muse_core_log_fatal, _muse_core_log_set_msg,
-                                                               _muse_core_log_get_msg, _muse_core_log_flush_msg, _muse_core_log_free);
+                                                               _muse_core_log_get_msg, _muse_core_log_flush_msg, _muse_core_log_api_name, _muse_core_log_free);
 
        return g_muse_core_log;
 }
@@ -472,7 +524,7 @@ void muse_core_log_init(void)
 
        if (g_muse_core_log == NULL)
                _muse_core_log_init_instance(_muse_core_log_monitor, _muse_core_log_attributes, _muse_core_log_fatal, _muse_core_log_set_msg,
-                                                               _muse_core_log_get_msg, _muse_core_log_flush_msg, _muse_core_log_free);
+                                                               _muse_core_log_get_msg, _muse_core_log_flush_msg, _muse_core_log_api_name, _muse_core_log_free);
 
        _muse_core_log_set_log_fd();
        _muse_core_log_init_signals();
index c8f71e6..747c76a 100644 (file)
@@ -72,6 +72,7 @@ static void _muse_core_module_dispatch(int cmd, muse_module_h module)
                if (dispatcher && dispatcher[cmd]) {
 #ifndef MUSE_NO_LOG
                        muse_core_module_get_instance()->set_value(module->api_module, DISPATCHER_PTR, (gpointer) dispatcher[cmd]);
+                       muse_core_log_get_instance()->log_api_name((gpointer) dispatcher[cmd]);
 #endif
                        dispatcher[cmd](module);
                } else {
@@ -83,7 +84,7 @@ static void _muse_core_module_dispatch(int cmd, muse_module_h module)
 
 static gboolean _muse_core_module_close(muse_module_h module)
 {
-       g_return_val_if_fail(module != NULL, FALSE);
+       g_return_val_if_fail(module, FALSE);
 
        LOGD("Closing module %s", g_module_name(module->ch[MUSE_CHANNEL_MSG].dll_handle));
        if (!g_module_close(module->ch[MUSE_CHANNEL_MSG].dll_handle)) {
@@ -97,13 +98,13 @@ static gboolean _muse_core_module_close(muse_module_h module)
 }
 static GModule *_muse_core_module_get_dllsymbol(int api_module)
 {
-       g_return_val_if_fail(g_muse_core_module != NULL, NULL);
+       g_return_val_if_fail(g_muse_core_module, NULL);
        return g_muse_core_module->module[api_module];
 }
 
 static void _muse_core_module_set_dllsymbol_loaded_value(int api_module, GModule *module, gboolean value)
 {
-       g_return_if_fail(g_muse_core_module!= NULL);
+       g_return_if_fail(g_muse_core_module);
 
        g_muse_core_module->module_loaded[api_module] = value;
        g_muse_core_module->module[api_module] = module;
@@ -112,14 +113,14 @@ static void _muse_core_module_set_dllsymbol_loaded_value(int api_module, GModule
 
 static gboolean _muse_core_module_get_dllsymbol_loaded_value(int api_module)
 {
-       g_return_val_if_fail(g_muse_core_module != NULL, false);
+       g_return_val_if_fail(g_muse_core_module, false);
        return g_muse_core_module->module_loaded[api_module];
 }
 
 static void _muse_core_module_set_dllsymbol_value(int api_module, const char *keyname, gpointer value)
 {
-       g_return_if_fail(g_muse_core_module!= NULL);
-       g_return_if_fail(keyname != NULL);
+       g_return_if_fail(g_muse_core_module);
+       g_return_if_fail(keyname);
 
        gpointer orig_key;
 
@@ -140,8 +141,8 @@ static void _muse_core_module_set_dllsymbol_value(int api_module, const char *ke
 
 static int _muse_core_module_get_dllsymbol_value(int api_module, const char *keyname, gpointer *value)
 {
-       g_return_val_if_fail(g_muse_core_module!= NULL, MM_ERROR_INVALID_ARGUMENT);
-       g_return_val_if_fail(keyname != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(g_muse_core_module, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(keyname, MM_ERROR_INVALID_ARGUMENT);
 
        if (value) {
                *value = g_hash_table_lookup(g_muse_core_module->table[api_module], keyname);
@@ -161,7 +162,7 @@ static void _muse_core_module_free(void)
 {
        int idx = 0;
 
-       g_return_if_fail(g_muse_core_module != NULL);
+       g_return_if_fail(g_muse_core_module);
 
        for (idx = 0; idx < MUSE_MODULE_MAX; idx++) {
                g_mutex_clear(&g_muse_core_module->module_lock[idx]);
@@ -181,7 +182,7 @@ static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispa
 
        int idx = 0;
        g_muse_core_module = calloc(1, sizeof(*g_muse_core_module));
-       g_return_if_fail(g_muse_core_module != NULL);
+       g_return_if_fail(g_muse_core_module);
 
        g_muse_core_module->load = load;
        g_muse_core_module->dispatch = dispatch;
@@ -197,7 +198,7 @@ static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispa
                g_mutex_init(&g_muse_core_module->module_lock[idx]);
                g_muse_core_module->module_loaded[idx] = false;
                g_muse_core_module->table[idx] = g_hash_table_new(g_str_hash, g_str_equal);
-               g_return_if_fail(g_muse_core_module->table[idx] != NULL);
+               g_return_if_fail(g_muse_core_module->table[idx]);
        }
 }
 
index 49f6174..aeebc73 100644 (file)
@@ -29,9 +29,9 @@ static json_object *_muse_core_msg_json_find_obj(json_object * jobj, const char
 {
        size_t key_len = 0;
 
-       g_return_val_if_fail(jobj != NULL, NULL);
+       g_return_val_if_fail(jobj, NULL);
 
-       g_return_val_if_fail(find_key != NULL, NULL);
+       g_return_val_if_fail(find_key, NULL);
 
        key_len = strlen(find_key);
 
@@ -45,7 +45,7 @@ static json_object *_muse_core_msg_json_find_obj(json_object * jobj, const char
 
 static void _muse_core_msg_json_set_error(muse_core_msg_parse_err_e *err, int jerr)
 {
-       if (err != NULL) {
+       if (err) {
                switch (jerr) {
                case json_tokener_success:
                        *err = MUSE_MSG_PARSE_ERROR_NONE;
@@ -65,14 +65,14 @@ static json_object *_muse_core_msg_json_tokener_parse_len(const char *str, int *
        struct json_tokener *tok;
        struct json_object *obj;
 
-       g_return_val_if_fail(str != NULL, NULL);
+       g_return_val_if_fail(str, NULL);
 
        tok = json_tokener_new();
 
-       g_return_val_if_fail(tok != NULL, NULL);
+       g_return_val_if_fail(tok, NULL);
 
        obj = json_tokener_parse_ex(tok, str, strlen(str));
-       g_return_val_if_fail(obj != NULL, NULL);
+       g_return_val_if_fail(obj, NULL);
 
        if (len)
                *len = tok->char_offset;
@@ -141,7 +141,7 @@ char *muse_core_msg_json_factory_new(int api, ...)
 
        jobj = json_object_new_object();
 
-       g_return_val_if_fail(jobj != NULL, NULL);
+       g_return_val_if_fail(jobj, NULL);
 
        json_object_object_add(jobj, MUSE_API, json_object_new_int(api));
 
@@ -175,12 +175,12 @@ gboolean muse_core_msg_json_deserialize(
        int j_type;
        json_object *val, *jobj;
 
-       g_return_val_if_fail(key != NULL, FALSE);
-       g_return_val_if_fail(buf != NULL, FALSE);
-       g_return_val_if_fail(data != NULL, FALSE);
+       g_return_val_if_fail(key, FALSE);
+       g_return_val_if_fail(buf, FALSE);
+       g_return_val_if_fail(data, FALSE);
 
        jobj = _muse_core_msg_json_tokener_parse_len(buf, parse_len, err);
-       g_return_val_if_fail(jobj != NULL, FALSE);
+       g_return_val_if_fail(jobj, FALSE);
 
        val = _muse_core_msg_json_find_obj(jobj, key);
        if (!val) {
@@ -237,7 +237,7 @@ gboolean muse_core_msg_json_deserialize(
 
 void *muse_core_msg_json_object_new(char *str, int *parse_len, muse_core_msg_parse_err_e *err)
 {
-       g_return_val_if_fail(str != NULL, NULL);
+       g_return_val_if_fail(str, NULL);
        return (void *)_muse_core_msg_json_tokener_parse_len(str, parse_len, err);
 }
 
@@ -246,9 +246,9 @@ gboolean muse_core_msg_json_object_get_value(const char *key, void* jobj, void *
        int j_type;
        json_object *val;
 
-       g_return_val_if_fail(key != NULL, FALSE);
-       g_return_val_if_fail(jobj != NULL, FALSE);
-       g_return_val_if_fail(data != NULL, FALSE);
+       g_return_val_if_fail(key, FALSE);
+       g_return_val_if_fail(jobj, FALSE);
+       g_return_val_if_fail(data, FALSE);
 
        val = _muse_core_msg_json_find_obj((json_object *)jobj, key);
        if (!val) {
@@ -306,6 +306,6 @@ gboolean muse_core_msg_json_object_get_value(const char *key, void* jobj, void *
 
 void muse_core_msg_json_object_free(void *jobj)
 {
-       g_return_if_fail(jobj != NULL);
+       g_return_if_fail(jobj);
        json_object_put((json_object *)jobj);
 }
index 327bec7..1501a73 100644 (file)
@@ -154,11 +154,11 @@ CLEANUP:
 
 static void _muse_core_security_init_instance(int (*new)(void), void (*free)(void))
 {
-       g_return_if_fail(new != NULL);
-       g_return_if_fail(free != NULL);
+       g_return_if_fail(new);
+       g_return_if_fail(free);
 
        g_muse_core_security = calloc(1, sizeof(*g_muse_core_security));
-       g_return_if_fail(g_muse_core_security != NULL);
+       g_return_if_fail(g_muse_core_security);
        g_muse_core_security->p_cynara= NULL;
        g_muse_core_security->new= new;
        g_muse_core_security->free = free;
index 431f308..adc824d 100644 (file)
@@ -52,11 +52,11 @@ static void _muse_core_server_gst_init(char **cmd)
 
        gst_param_cnt = muse_core_config_get_instance()->get_gst_param_cnt();
        argc = malloc(sizeof(gint));
-       g_return_if_fail(argc != NULL);
+       g_return_if_fail(argc);
 
        /* add gst_param */
        argv = malloc(sizeof(gchar*) * (gst_param_cnt + 1));
-       g_return_if_fail(argv != NULL);
+       g_return_if_fail(argv);
        memset(argv, 0, sizeof(gchar*) * (gst_param_cnt + 1));
 
        *argc = 0;
index f78a429..d54c581 100644 (file)
@@ -155,14 +155,14 @@ void muse_core_tool_recursive_rmdir(const char *path)
        FTS *fts;
        FTSENT *ftsent;
 
-       g_return_if_fail(path != NULL);
+       g_return_if_fail(path);
 
        char *const paths[] = { (char *)path, NULL };
 
        /* This means there can't be any autofs mounts yet, so this is the first time we're being run since a reboot. Clean out any stuff left in /Network from the reboot. */
        fts = fts_open(paths, FTS_NOCHDIR | FTS_PHYSICAL, NULL);
-       if (fts != NULL) {
-               while ((ftsent = fts_read(fts)) != NULL) {
+       if (fts) {
+               while ((ftsent = fts_read(fts))) {
                        /* We only remove directories - if there are files, we assume they're there for a purpose.
                        * We remove directories after we've removed their children, so we want to process directories visited in post-order.*/
                        if (ftsent->fts_info == FTS_DP && ftsent->fts_level >= FTS_ROOTLEVEL)
index 4761185..c7dc986 100644 (file)
@@ -14,8 +14,8 @@
 }
 
 #define LL_REMOVE(item, list) { \
-       if (item->prev != NULL) item->prev->next = item->next; \
-       if (item->next != NULL) item->next->prev = item->prev; \
+       if (item->prev) item->prev->next = item->next; \
+       if (item->next) item->next->prev = item->prev; \
        if (list == item) list = item->next; \
        item->prev = item->next = NULL; \
 }
@@ -48,7 +48,7 @@ static void *_muse_core_workqueue_worker_function(void *ptr)
                        break;
 
                job = worker->workqueue->waiting_jobs;
-               if (job != NULL)
+               if (job)
                        LL_REMOVE(job, worker->workqueue->waiting_jobs);
 
                pthread_mutex_unlock(&worker->workqueue->jobs_mutex);
@@ -73,10 +73,10 @@ static void _muse_core_workqueue_shutdown(void)
        LOGD("Enter");
 
        muse_core_workqueue_worker_t *worker = NULL;
-       g_return_if_fail(g_workqueue != NULL);
+       g_return_if_fail(g_workqueue);
 
        /* Set all workers to terminate. */
-       for (worker = g_workqueue->workers; worker != NULL; worker = worker->next)
+       for (worker = g_workqueue->workers; worker; worker = worker->next)
                worker->terminate = 1;
 
        pthread_mutex_lock(&g_workqueue->jobs_mutex);
@@ -101,9 +101,9 @@ static void _muse_core_workqueue_add_job(muse_core_workqueue_job_t *job)
 
 static void _muse_core_workqueue_init_instance(void (*shutdown)(void), void (*add_job)(muse_core_workqueue_job_t *))
 {
-       g_return_if_fail(shutdown != NULL);
-       g_return_if_fail(add_job != NULL);
-       g_return_if_fail(g_workqueue != NULL);
+       g_return_if_fail(shutdown);
+       g_return_if_fail(add_job);
+       g_return_if_fail(g_workqueue);
 
        g_workqueue->shutdown = shutdown;
        g_workqueue->add_job = add_job;
@@ -125,7 +125,7 @@ int muse_core_workqueue_init(int numWorkers)
        pthread_mutex_t blank_mutex = PTHREAD_MUTEX_INITIALIZER;
 
        g_workqueue = calloc(1, sizeof(muse_core_workqueue_workqueue_t));
-       g_return_val_if_fail(g_workqueue != NULL, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(g_workqueue, MM_ERROR_INVALID_ARGUMENT);
 
        if (numWorkers < 1)
                numWorkers = 1;
@@ -135,7 +135,7 @@ int muse_core_workqueue_init(int numWorkers)
 
        for (i = 0; i < numWorkers; i++) {
                worker = malloc(sizeof(muse_core_workqueue_worker_t));
-               g_return_val_if_fail(worker != NULL, MM_ERROR_INVALID_ARGUMENT);
+               g_return_val_if_fail(worker, MM_ERROR_INVALID_ARGUMENT);
                memset(worker, 0, sizeof(*worker));
                worker->workqueue = g_workqueue;
                if (pthread_create(&worker->thread, NULL, _muse_core_workqueue_worker_function, (void *)worker)) {