shm: Change the segment size if shmget fails
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 26 Apr 2013 02:49:43 +0000 (11:49 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Tue, 30 Apr 2013 01:31:44 +0000 (10:31 +0900)
Change the segment size if shmget fails.

Change-Id: Ibdd8e95b29eac13a7180da06d367072e0fc775e2
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/client/native_src/share.c
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java

index a8bef4e..4063908 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
+#include <errno.h>
 #include "org_tizen_emulator_skin_EmulatorShmSkin.h"
 
 #define MAXLEN 512
@@ -52,7 +53,32 @@ JNIEXPORT jint JNICALL Java_org_tizen_emulator_skin_EmulatorShmSkin_shmget
     if (shmid == -1) {
         fprintf(stderr, "share.c: shmget failed\n");
         fflush(stderr);
-        return 1;
+
+        if (errno == EINVAL) {
+            /* get identifiedr of unavailable segment */
+            shmid = shmget((key_t)shmkey, (size_t)1, 0666 | IPC_CREAT);
+            if (shmid == -1) {
+                perror("share.c: ");
+                return 1;
+            }
+
+            /* a segment with given key existed, but size is greater than
+            the size of that segment */
+            if (shmctl(shmid, IPC_RMID, 0) == -1) {
+                perror("share.c: ");
+                return 1;
+            }
+
+            /* try to shmget one more time */
+            shmid = shmget((key_t)shmkey, (size_t)size, 0666 | IPC_CREAT);
+            if (shmid == -1) {
+                perror("share.c: ");
+                return 1;
+            } else {
+                fprintf(stdout, "share.c: new segment was to be created!\n");
+                fflush(stdout);
+            }
+        }
     }
 
     /* We now make the shared memory accessible to the program */
index 0490227..cf8822d 100644 (file)
@@ -1705,7 +1705,12 @@ public class EmulatorSkin {
                                                communicator.terminate();
                                        }
 
-                                       System.exit(-1);
+                                       shell.getDisplay().asyncExec(new Runnable() {
+                                               @Override
+                                               public void run() {
+                                                       System.exit(-1);
+                                               }
+                                       });
                                }
                        }
                });