g_mutex_lock(&dispatch_lock);
if (muse_core_msg_object_get_value(MSG_KEY_MODULE_INDEX, jobj, MUSE_TYPE_INT, &idx)) {
m->idx = idx;
- LOGW("client module %s", ms_get_instance()->conf->host[m->idx]);
if (_ms_ipc_module_instance_creation_is_allowed(idx) == FALSE) {
ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
g_mutex_unlock(&dispatch_lock);
ms_exit_worker(m);
}
- if (muse_core_msg_object_get_value(MSG_KEY_PID, jobj, MUSE_TYPE_INT, &pid) && m->pid != pid) {
+ if (muse_core_msg_object_get_value(MSG_KEY_PID, jobj, MUSE_TYPE_INT, &pid) && m->pid != pid)
LOGW("connected pid [%d] msg [%d] is different", m->pid, pid);
- }
ms_connection_register(m);
m->is_create_api_called = true;
m->ch[MUSE_CHANNEL_MSG].dll_handle = ms_module_open(idx);
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
muse_module_h m = NULL;
muse_module_h peeked_m = NULL;
+ muse_module_h candidate_m = NULL;
intptr_t module_addr = 0;
ms_workqueue_job_t *job = NULL;
- GQueue *instance_queue;
+ GQueue *instance_queue = NULL;
LOGI("Enter");
return FALSE;
}
- LOGI("server: %d client: %d", server_sockfd, client_sockfd);
+ LOGI("server : %d client [%d] : %d", server_sockfd, channel, client_sockfd);
pid = _ms_get_pid(client_sockfd);
instance_queue = ms_get_instance()->connection->instance_queue;
length = g_queue_get_length(instance_queue);
+ _ms_get_module_addr(client_sockfd, &module_addr);
+
+ m = (muse_module_h)module_addr;
+
for (idx = 0; idx < length; idx++) {
peeked_m = (muse_module_h)g_queue_peek_nth(instance_queue, idx);
- if (peeked_m->pid == pid) {
- SECURE_LOGI("instance #%d - %s %p (%d)", idx, muse_server->conf->host[peeked_m->idx], peeked_m, peeked_m->pid);
- m = peeked_m;
- m->ch[MUSE_CHANNEL_DATA].sock_fd = client_sockfd;
- break;
+ if (peeked_m->pid != pid)
+ continue;
+
+ if (!m) {
+ if (candidate_m) {
+ LOGE("muse-server can't support the error case which threre are several modules now");
+ goto out;
+ }
+
+ if (!muse_core_fd_is_valid(peeked_m->ch[MUSE_CHANNEL_DATA].sock_fd))
+ candidate_m = peeked_m;
+ else
+ SECURE_LOGW("already paired module %p", peeked_m);
+
+ continue;
}
- }
- /* we can remove below when client don't send msg of module addr because it is able to module addr with using _ms_get_pid */
- _ms_get_module_addr(client_sockfd, &module_addr);
- if (m)
+ if (m != peeked_m)
+ continue;
+
+ if (muse_core_fd_is_valid(m->ch[MUSE_CHANNEL_DATA].sock_fd)) {
+ SECURE_LOGE("[%d] %s pid %d %p you had better check if instance destroy completed properly", client_sockfd, muse_server->conf->host[m->idx], pid, m);
+ goto out;
+ }
+
+ m->ch[MUSE_CHANNEL_DATA].sock_fd = client_sockfd;
SECURE_LOGI("%s (pid %d) module : %p module addr from client : %p", muse_server->conf->host[m->idx], pid, m, module_addr);
- }
+ break;
+ }
- if (m == NULL) {
- LOGW("[%d] pid %d channel %d failed to get module addr for muse_module_t", pid, client_sockfd, channel);
- goto out;
+ if (candidate_m) {
+ m = candidate_m;
+ m->ch[MUSE_CHANNEL_DATA].sock_fd = client_sockfd;
+ SECURE_LOGW("[%d] %s pid %d %p restore module address at the only one null data channel", client_sockfd, muse_server->conf->host[m->idx], pid, m);
+ }
}
job = malloc(sizeof(ms_workqueue_job_t));
out:
close(server_sockfd);
close(client_sockfd);
- if (channel == MUSE_CHANNEL_MSG)
- MUSE_FREE(m);
+
+ if (m) {
+ if (channel == MUSE_CHANNEL_MSG)
+ free(m);
+ else
+ muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
+ }
+
MUSE_FREE(job);
_ms_unlock_state();
g_mutex_clear(&muse_server->state_lock);
- for (idx = 0; idx < muse_server->conf->host_cnt; idx++)
+ for (idx = 0; idx < muse_server->conf->host_cnt; idx++)
ms_module_deinit(muse_server->module[idx]);
ms_workqueue_deinit(muse_server->workqueue);