static int port;
static int port_setting = -1;
+static int log_fd = -1;
+
static pthread_mutex_t mutex_clilist = PTHREAD_MUTEX_INITIALIZER;
static char* get_emulator_ecs_log_path(void)
stdout[0] = flog[0];
stderr[0] = flog[0];
#else
- int fd = open("/dev/null", O_RDONLY);
- dup2(fd, 0);
+ log_fd = open("/dev/null", O_RDONLY);
+ dup2(log_fd, 0);
- fd = creat(path, 0640);
- if (fd < 0) {
- fd = open("/dev/null", O_WRONLY);
+ log_fd = creat(path, 0640);
+ if (log_fd < 0) {
+ log_fd = open("/dev/null", O_WRONLY);
}
- dup2(fd, 1);
- dup2(fd, 2);
+ dup2(log_fd, 1);
+ dup2(log_fd, 2);
#endif
}
+static inline void stop_logging(void) {
+ int ret = -1;
+ if (log_fd >= 0) {
+ ret = close(log_fd);
+ if (ret != 0) {
+ LOG("failed to close log fd.");
+ }
+ }
+}
+
int ecs_write(int fd, const uint8_t *buf, int len) {
LOG("write buflen : %d, buf : %s", len, (char*)buf);
if (fd < 0) {
}
void ecs_client_close(ECS_Client* clii) {
+ if (clii == NULL)
+ return;
+
pthread_mutex_lock(&mutex_clilist);
- if (0 <= clii->client_fd) {
+ if (clii->client_fd > 0) {
LOG("ecs client closed with fd: %d", clii->client_fd);
closesocket(clii->client_fd);
#ifndef CONFIG_LINUX
}
QTAILQ_REMOVE(&clients, clii, next);
- if (NULL != clii) {
- g_free(clii);
- clii = NULL;
- }
+
+ g_free(clii);
+ clii = NULL;
pthread_mutex_unlock(&mutex_clilist);
}
ECS_Client *clii;
LOG("### Good bye! ECS ###");
+ if (cs == NULL)
+ return;
+
if (0 <= cs->listen_fd) {
LOG("close listen_fd: %d", cs->listen_fd);
closesocket(cs->listen_fd);
cs->listen_fd = -1;
}
- if (NULL != cs->mon) {
+ if (cs->mon != NULL) {
g_free(cs->mon);
cs->mon = NULL;
}
g_free(keepalive_buf);
}
- if (NULL != cs->alive_timer) {
+ if (cs->alive_timer != NULL) {
qemu_del_timer(cs->alive_timer);
cs->alive_timer = NULL;
}
ecs_client_close(clii);
}
- if (NULL != cs) {
- g_free(cs);
- cs = NULL;
- }
+ g_free(cs);
+ cs = NULL;
+ current_ecs = NULL;
+
+ stop_logging();
}
#ifndef _WIN32
send_keep_alive_msg(clii);
}
+ if (current_ecs == NULL) {
+ LOG("alive checking is failed because current ecs is null.");
+ return;
+ }
+
qemu_mod_timer(current_ecs->alive_timer,
qemu_get_clock_ns(vm_clock) + get_ticks_per_sec() * TIMER_ALIVE_S);
if (!msg)
goto fail;
msgproc_nfc_req(cli, msg);
- }
+ }
#if 0
else if (master->type == ECS__MASTER__TYPE__CHECKVERSION_REQ)
{
get_sensor_proxi();
}
} else {
- set_sensor_data(length, data);
+ if (data != NULL) {
+ set_sensor_data(length, data);
+ }
}
} else if (!strncmp(cmd, "Network", 7)) {
LOG(">>> Network msg: '%s'", data);
}
if (!strncmp(cmd, MSG_TYPE_NFC, 3)) {
- send_to_nfc(request_nfc_set, data, msg->data.len);
+ if (data != NULL) {
+ send_to_nfc(request_nfc_set, data, msg->data.len);
+ }
}
return true;
const char* ijdata = (data + catsize + 2 + 1 + 1);
- char *encoded_ijdata = NULL;
+ const char *encoded_ijdata = "";
LOG("<< header cat = %s, length = %d, action=%d, group=%d", cat, length,
action, group);