static int _muse_core_set_nonblocking(int fd, bool value);
static int _muse_core_check_server_is_running(void);
+static void _muse_core_dispatch_shutdown(gpointer data, gpointer user_data);
static muse_core_t *_muse_core_create_new_server_from_fd(int fd[], int type);
static int _muse_core_free(muse_core_t *server);
static int _muse_core_server_new(muse_core_channel_e channel);
flags = value ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
if (fcntl(fd, F_SETFL, flags) == -1) {
strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
- LOGE("fcntl (%d, F_SETFL) %s", fd, err_msg);
- return -1;
+ LOGE("fcntl (%d, F_SETFL, %d) %s", fd, flags, err_msg);
+ return MM_ERROR_FILE_INTERNAL;
} else {
LOGD("fcntl (%d, F_SETFL)", fd);
}
+ } else {
+ LOGE("failed to get flags for %d", fd);
+ return MM_ERROR_FILE_INTERNAL;
}
return MM_ERROR_NONE;
return true;
}
+static void _muse_core_dispatch_shutdown(gpointer data, gpointer user_data)
+{
+ muse_module_h module = (muse_module_h)data;
+ LOGI("[%p] shutdown", module);
+ muse_core_cmd_dispatch(module, MUSE_MODULE_COMMAND_SHUTDOWN);
+}
+
static muse_core_t *_muse_core_create_new_server_from_fd(int fd[], int type)
{
muse_core_t *server;
for (i = 0; i < MUSE_CHANNEL_MAX; i++) {
if (!_muse_core_attach_server(fd[i], _muse_core_connection_handler, (gpointer)(intptr_t) i)) {
LOGD("Fail to attach server fd %d", fd[i]);
- muse_core_connection_close(server->fd);
- muse_core_connection_close(server->data_fd);
- MUSE_FREE(server);
+ g_queue_foreach(muse_core_ipc_get_instance()->module_queue, _muse_core_dispatch_shutdown, NULL);
+ muse_core_respawn(SIGTERM);
return NULL;
}
}
client_len = sizeof(client_address);
client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
- LOGI("server: %d client: %d", server_sockfd, client_sockfd);
-
- if (client_sockfd < 0) {
+ if (client_sockfd == SOCK_ERR) {
strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
- LOGE("accept: %s\n", err_msg);
+ LOGE("[Critical Error] accept failure : %s", err_msg);
+ g_queue_foreach(muse_core_ipc_get_instance()->module_queue, _muse_core_dispatch_shutdown, NULL);
+ muse_core_respawn(SIGTERM);
return FALSE;
}
+ LOGI("server: %d client: %d", server_sockfd, client_sockfd);
+
if (channel == MUSE_CHANNEL_MSG) {
if ((module = malloc(sizeof(muse_module_t))) == NULL) {
LOGE("failed to allocated memory for muse_module_t");
if ((ret = connect(sockfd, (struct sockaddr *)&address, len)) < 0) {
strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
- LOGE("connect failure : %s", err_msg);
+ LOGE("[Critical Error] connect failure : %s", err_msg);
close(sockfd);
return ret;
}
{
muse_core_msg_get_instance()->jobj_free(msg_obj);
}
+
+void muse_core_respawn(int signo)
+{
+ pid_t pid = getpid();
+ LOGE("send %d process signal %d", (int)pid, signo);
+ kill(pid, signo);
+}
static gboolean _muse_core_module_dispatch_callback(gpointer data)
{
- muse_module_h saved_module = NULL;
- muse_module_h blocked_module = (muse_module_h) data;
-
- while (!g_queue_is_empty(muse_core_ipc_get_instance()->module_queue)) {
- saved_module = (muse_module_h)g_queue_pop_head(muse_core_ipc_get_instance()->module_queue);
- if (saved_module && blocked_module && saved_module != blocked_module) {
- LOGD("%s executes shutdown", muse_core_config_get_instance()->get_host(saved_module->api_module));
- muse_core_cmd_dispatch(saved_module, MUSE_MODULE_COMMAND_SHUTDOWN);
- }
- }
LOGE("Restart muse server");
- kill(muse_core_ipc_get_instance()->pid, SIGTERM);
+ muse_core_respawn(SIGABRT);
return FALSE;
}