suspend/resume: NOT allow to add duplicated client. 66/12566/3
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 19 Nov 2013 07:09:53 +0000 (16:09 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Tue, 19 Nov 2013 07:16:54 +0000 (16:16 +0900)
Change-Id: Ib1ac637058413b8051cfb9af4825ca75b80bfe94
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/guest_server.c

index 0bfbb8c..d4265b7 100644 (file)
@@ -391,7 +391,7 @@ static void ecs_read(ECS_Client *cli) {
 #endif
 
     if (to_read_bytes == 0) {
-        LOG("ioctl FIONREAD: 0\n");
+        LOG("ioctl FIONREAD: 0");
         goto fail;
     }
 
index 40a7857..51a0d3f 100644 (file)
@@ -125,7 +125,7 @@ static void send_to_client(GS_Client* client, int state)
     // send message "[4 digit message length]host:sync:emulator-26101:[0|1]"
     sprintf(buf, "%04xhost:sync:%s:%01d", (serial_len + 12), client->serial, state);
 
-    INFO("send %s to client \n", buf);
+    INFO("send %s to client %s\n", buf, inet_ntoa(client->addr.sin_addr));
 
     if (send(s, buf, sizeof(buf), 0) == -1)
     {
@@ -151,12 +151,8 @@ void notify_all_sdb_clients(int state)
 
 static void add_sdb_client(struct sockaddr_in* addr, int port, const char* serial)
 {
-
-    GS_Client *client = g_malloc0(sizeof(GS_Client));
-    if (NULL == client) {
-        INFO("GS_Client allocation failed.\n");
-        return;
-    }
+    GS_Client *cli = NULL;
+    GS_Client *client = NULL;
 
     if (addr == NULL) {
         INFO("GS_Client client's address is EMPTY.\n");
@@ -169,6 +165,20 @@ static void add_sdb_client(struct sockaddr_in* addr, int port, const char* seria
         return;
     }
 
+    QTAILQ_FOREACH(cli, &clients, next)
+    {
+        if (!strcmp(serial, cli->serial) && !strcmp(inet_ntoa(addr->sin_addr), inet_ntoa((cli->addr).sin_addr))) {
+            INFO("Client cannot be duplicated.\n");
+            return;
+        }
+    }
+
+    client = g_malloc0(sizeof(GS_Client));
+    if (NULL == client) {
+        INFO("GS_Client allocation failed.\n");
+        return;
+    }
+
     memcpy(&client->addr, addr, sizeof(struct sockaddr_in));
     client->port = port;
     strcpy(client->serial, serial);
@@ -179,7 +189,7 @@ static void add_sdb_client(struct sockaddr_in* addr, int port, const char* seria
 
     pthread_mutex_unlock(&mutex_clilist);
 
-    INFO("Added new sdb client. ip: %s, port: %d, serial: %s\n", inet_ntoa(client->addr.sin_addr), client->port, client->serial);
+    INFO("Added new sdb client. ip: %s, port: %d, serial: %s\n", inet_ntoa((client->addr).sin_addr), client->port, client->serial);
 
     send_to_client(client, runstate_check(RUN_STATE_SUSPENDED));
 }