emulator: modify VM lock
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 1 Nov 2016 07:09:12 +0000 (16:09 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Mon, 7 Nov 2016 08:34:43 +0000 (17:34 +0900)
check whether vm_launch.conf file exist.
skip making lock file if it's failed to create.

Change-Id: I2073d752e7fca9dfcce137b6ac0b6ecffcc0d05d
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/emulator.c
tizen/src/util/osutil-win32.c
tizen/src/util/osutil.c

index e4a1707..b63d020 100644 (file)
@@ -317,6 +317,11 @@ static int emulator_main(int argc, char *argv[], char **envp)
     set_bin_path_os(_qemu_argv[0]);
 
     if (launch_conf_file) {
+        if (!g_file_test(launch_conf_file, G_FILE_TEST_EXISTS)) {
+            fprintf(stderr, "conf_file(%s) does not exist.\n", launch_conf_file);
+            return -1;
+        }
+
         make_vm_lock_os(g_path_get_dirname(launch_conf_file));
         if (!load_conf(launch_conf_file)) {
             return -1;
index f733aed..48220da 100644 (file)
@@ -94,6 +94,10 @@ void make_vm_lock_os(gchar *vms_path)
     if (g_mkdir_with_parents(g_path_get_dirname(lock_filename), 0777)) {
         LOG_WARNING("Can not create directory for lock file: %ld\n",
                     GetLastError());
+        // do not create the lock file.
+        g_free(lock_filename);
+        lock_filename = NULL;
+        return;
     }
     lock_file = CreateFile(lock_filename,
             GENERIC_READ | GENERIC_WRITE,
@@ -107,6 +111,8 @@ void make_vm_lock_os(gchar *vms_path)
         // On Windows, the file opened by CreateFile has exclusive lock
         // naturally unless FILE_SHARE_* attribute is set.
         if (error == ERROR_SHARING_VIOLATION) {
+            g_free(lock_filename);
+            lock_filename = NULL;
             error_report("Can not execute this VM. "
                     "The same VM may be running now.");
             exit(1);
index de78c53..5405793 100644 (file)
@@ -145,9 +145,10 @@ retry:
         error = errno;
         LOG_WARNING("Failed to open file for lock(%d): %s\n",
                 error, strerror(error));
-        error_report("Can not execute this VM. "
-                     "The same VM may be running now.");
-        exit(1);
+        // do not create the lock file.
+        g_free(lock_filename);
+        lock_filename = NULL;
+        return;
     }
 
     if (fd_lock(lock_file) == -1) {
@@ -165,10 +166,7 @@ retry:
             exit(1);
         }
 
-        LOG_WARNING("Failed to lock image file: %s\n", strerror(error));
-        close(lock_file);
-        lock_file = -1;
-        return;
+        LOG_WARNING("Failed to lock file: %s\n", strerror(error));
     }
 
     emulator_add_exit_notifier(&remove_lock);