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);
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*/
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];
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);
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
+}
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) {
}
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) {
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]);
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);
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);
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;
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;
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;
}
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();
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");
#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);
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);
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);
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;
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);
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));
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;
{
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) {
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) {
{
LOGD("Enter");
- g_return_if_fail(g_muse_core_ipc != NULL);
+ g_return_if_fail(g_muse_core_ipc);
_muse_core_ipc_deinit_bufmgr();
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;
}
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;
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);
}
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;
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);
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;
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);
}
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);
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);
}
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);
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;
{
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;
}
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);
}
#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);
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);
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);
}
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);
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);
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)) {
}
}
+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);
}
}
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");
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----------");
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;
}
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);
}
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);
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);
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)
{
LOGD("Enter");
+ g_mutex_clear(&g_muse_core_log->log_lock);
+
MUSE_FREE(g_muse_core_log);
LOGD("Leave");
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);
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;
}
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();
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 {
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)) {
}
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;
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;
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);
{
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]);
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;
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]);
}
}
{
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);
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;
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;
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));
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) {
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);
}
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) {
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);
}
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;
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;
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)
}
#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; \
}
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);
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);
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;
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;
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)) {