#define READ 0x02
#define PERSIST 0x10
+#define MAX_ERROR_MSG_LEN 128
#define DISPATCHER "dispatcher"
#define CMD_DISPATCHER "cmd_dispatcher"
static int _muse_core_set_nonblocking(int fd, bool value)
{
int flags = fcntl(fd, F_GETFL, NULL);
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
if (flags >= 0) {
flags = value ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
if (fcntl(fd, F_SETFL, flags) == -1) {
- LOGE("fcntl (%d, F_SETFL) %s", fd, strerror(errno));
+ LOGE("fcntl (%d, F_SETFL) %s", fd, strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
return -1;
} else {
LOGD("fcntl (%d, F_SETFL)", fd);
return false;
src = g_io_create_watch(channel, G_IO_IN);
- if (!src)
+ if (!src) {
+ g_io_channel_unref(channel);
+ channel = NULL;
return false;
+ }
g_source_set_callback(src, (GSourceFunc) callback, param, NULL);
g_source_attach(src, g_main_loop_get_context(g_loop));
struct sockaddr *address;
struct sockaddr_un addr_un;
socklen_t address_len;
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
if (channel >= MUSE_CHANNEL_MAX)
return -1;
/* Create Socket */
fd = socket(AF_UNIX, SOCK_STREAM, 0); /* Unix Domain Socket */
if (fd < 0) {
- LOGE("socket failed sock: %s", strerror(errno));
+ LOGE("socket failed sock: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
return -1;
} else {
LOGD("fd: %d", fd);
}
if (bind(fd, (struct sockaddr *)&addr_un, sizeof(addr_un)) != 0)
- LOGE("bind failed sock: %s", strerror(errno));
+ LOGE("bind failed sock: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
close(fd);
return -1;
}
socklen_t client_len;
struct sockaddr_un client_address;
muse_core_channel_e channel = (muse_core_channel_e)data;
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
LOGD("Enter");
if (client_sockfd < 0) {
LOGE("failed to accept");
- return FALSE;
+ if (errno == EWOULDBLOCK || errno == ECONNABORTED)
+ return FALSE;
+ else
+ LOGE("accept: %s\n", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
}
if (channel == MUSE_CHANNEL_MSG) {
LOGD("Leave");
return TRUE;
out:
- close(client_sockfd);
+ if (client_sockfd)
+ close(client_sockfd);
MUSE_FREE(module);
MUSE_FREE(job);
struct sockaddr_un address;
int len, ret = -1;
int sockfd;
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
LOGD("Enter");
if (channel >= MUSE_CHANNEL_MAX)
/*Create socket*/
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- LOGE("[socket failure] sock: %s", strerror(errno));
+ LOGE("[socket failure] sock: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
return ret;
} else {
LOGD("sockfd: %d", sockfd);
if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) {
- LOGE("unable to set on ctrls socket fd %d: %s", sockfd, strerror(errno));
+ LOGE("unable to set on ctrls socket fd %d: %s", sockfd, strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
(void) close(sockfd);
return -1;
}
char *str;
int idx;
int ret = -1;
+ char *ptr = NULL;
g_return_val_if_fail(g_muse_core_conf != NULL, ret);
}
g_muse_core_conf->type = 0;
- host = strtok(g_muse_core_conf->hosts, COMMA);
+ host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
while (host != NULL) {
g_muse_core_conf->host[g_muse_core_conf->type] = strdup(host);
/* path */
strncpy(host_name, host, strlen(host) + 1);
- strcat(host_name, COLON);
- strcat(host_name, PATH);
+ strncat(host_name, COLON, strlen(COLON));
+ strncat(host_name, PATH, strlen(PATH));
g_strstrip(host_name); /*Removes leading and trailing whitespace from a string*/
g_muse_core_conf->host_infos[g_muse_core_conf->type] = (host_info_t *) malloc(sizeof(host_info_t));
/* path */
strncpy(host_name, host, strlen(host) + 1);
- strcat(host_name, COLON);
- strcat(host_name, PRELOADED);
+ strncat(host_name, COLON, strlen(COLON));
+ strncat(host_name, PRELOADED, strlen(PRELOADED));
g_strstrip(host_name); /*Removes leading and trailing whitespace from a string*/
g_muse_core_conf->host_infos[g_muse_core_conf->type]->preloaded= strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL));
return ret;
}
- host = strtok(NULL, COMMA);
+ host = strtok_r(NULL, COMMA, &ptr);
g_muse_core_conf->type++;
MUSE_FREE(host_name);
}
{
char *host;
int i = 0;
+ char *ptr = NULL;
g_return_if_fail(g_muse_core_conf != NULL);
if (g_muse_core_conf->muse_dict)
iniparser_freedict(g_muse_core_conf->muse_dict);
- host = strtok(g_muse_core_conf->hosts, COMMA);
+ host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
g_muse_core_conf->type = 0;
while (host != NULL) {
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);
MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]);
- host = strtok(NULL, COMMA);
+ host = strtok_r(NULL, COMMA, &ptr);
g_muse_core_conf->type++;
}
MUSE_FREE(g_muse_core_conf->hosts);
int len, parse_len, cmd, api_module;
muse_module_h module = NULL;
muse_core_msg_parse_err_e err = MUSE_MSG_PARSE_ERROR_NONE;
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
g_return_val_if_fail(data != NULL, NULL);
module = (muse_module_h)data;
memset(module->recvMsg, 0x00, sizeof(module->recvMsg));
len = muse_core_ipc_recv_msg(module->ch[MUSE_CHANNEL_MSG].fd, module->recvMsg);
if (len <= 0) {
- LOGE("recv : %s (%d)", strerror(errno), errno);
+ LOGE("recv : %s (%d)", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN), errno);
muse_core_cmd_dispatch(module, MUSE_MODULE_EVENT_SHUTDOWN);
_muse_core_ipc_client_cleanup(module);
} else {
muse_module_h module = NULL;
char *recvBuff = NULL;
int allocSize = 0;
-
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
g_return_val_if_fail(fd > 0, NULL);
while (1) {
currLen += recvLen;
LOGD("buff %p, recvLen %d, currLen %d, allocSize %d", recvBuff, recvLen, currLen, allocSize);
if (recvLen <= 0) {
- LOGE("[%d] recv : %s (%d)", fd, strerror(errno), errno);
+ LOGE("[%d] recv : %s (%d)", fd, strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN), errno);
break;
} else {
if (module) {
int muse_core_ipc_recv_msg(int sock_fd, char *msg)
{
int ret = MM_ERROR_NONE;
-
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
g_return_val_if_fail(msg != NULL, MM_ERROR_INVALID_ARGUMENT);
if ((ret = recv(sock_fd, msg, MUSE_MSG_MAX_LENGTH, 0)) < 0)
- LOGE("fail to receive msg (%s)", strerror(errno));
+ LOGE("fail to receive msg (%s)", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
else
msg[ret] = '\0';
static void _muse_core_log_sig_abort(int signo)
{
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
if (SIG_ERR == signal(SIGABRT, SIG_DFL))
- LOGE("SIGABRT handler: %s", strerror(errno));
+ LOGE("SIGABRT handler: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
static char client_name[256];
memset(client_name, '\0', sizeof(client_name));
int i;
char **strings = NULL;
ucontext_t *uctxt = NULL;
+ char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
g_return_if_fail(si != NULL);
g_return_if_fail(arg != NULL);
tracesize = backtrace(trace, TUNABLE_CALLER_DEPTH);
if (tracesize < 0)
- LOGE("backtrace error: %s", strerror(errno));
+ LOGE("backtrace error: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
uctxt = (ucontext_t *) arg;
#endif
strings = backtrace_symbols(trace, tracesize);
if (strings == NULL) {
- LOGE("backtrace_symbols error: %s", strerror(errno));
+ LOGE("backtrace_symbols error: %s", strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
} else {
/* skip the first stack frame because it just points here. */
for (i = 1; i < tracesize; ++i) {
static int _muse_core_log_open_work(const char *path)
{
- if (access(path, F_OK) == 0)
- unlink(path);
return open(path, O_CREAT | O_APPEND | O_WRONLY | O_NONBLOCK, 0666);
}
stat(file[index], &st);
g_muse_core_log->size = st.st_size;
if (g_muse_core_log->size > MAX_SIZE) {
- if (index == MAX_FILE_NUM - 1)
- selected_index = 0;
- else
- selected_index = index + 1;
-
+ selected_index = (index + 1) % MAX_FILE_NUM;
break;
} else {
selected_index = index;
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);
_muse_core_log_create_fd();
if (fcntl(g_muse_core_log->log_fd, F_SETFD, FD_CLOEXEC) < 0)
- LOGE("unable to set CLO_EXEC on log fd %d: %s", g_muse_core_log->log_fd, strerror(errno));
+ LOGE("unable to set CLO_EXEC on log fd %d: %s", g_muse_core_log->log_fd, strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN));
(void) _muse_core_log_fd_set_block(g_muse_core_log->log_fd);
}
}
/* release */
- for (i = 0; i < *argc; i++) {
+ for (i = 0; i <= *argc; i++)
MUSE_FREE(argv[i]);
- }
MUSE_FREE(argv);
MUSE_FREE(argc);