From: jihye Date: Thu, 29 Sep 2016 03:08:50 +0000 (+0900) Subject: osutil: modfiy vm lock module X-Git-Tag: Tizen_Studio_1.3_Release_p2.3~8^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f4f95501d8cb2c90241e567753fd495751a3731;p=sdk%2Femulator%2Fqemu.git osutil: modfiy vm lock module Change-Id: I33e811ee554fe86b0ee6997d2fdc017df867a26b Signed-off-by: jihye --- diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 8216832992..93dda3d7af 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -287,7 +287,6 @@ const char *prepare_maru(const gchar * const kernel_cmdline) void prepare_maru_after_device_init(void) { - make_vm_lock_os(); maru_device_hotplug_init(); qemu_add_opts(&qemu_ecs_opts); start_ecs(); @@ -370,6 +369,7 @@ static int emulator_main(int argc, char *argv[], char **envp) set_bin_path(_qemu_argv[0]); + make_vm_lock_os(g_path_get_dirname(conf)); if (!load_conf(conf)) { return -1; } diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index 2ebc6c4fa1..a09df65285 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -46,8 +46,8 @@ MULTI_DEBUG_CHANNEL(qemu, osutil); -void make_vm_lock_os(void) { - make_vm_lock_posix(); +void make_vm_lock_os(gchar *vm_path) { + make_vm_lock_posix(vm_path); } static CFDictionaryRef proxySettings; diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index 164e92c960..eb20628b3c 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -65,9 +65,9 @@ static const char* gproxycmds[][2] = { { "gconftool-2 -g /system/proxy/socks_port", "gsettings get org.gnome.system.proxy.socks port" }, }; -void make_vm_lock_os(void) +void make_vm_lock_os(gchar *vm_path) { - make_vm_lock_posix(); + make_vm_lock_posix(vm_path); } void set_bin_path_os(char const *const exec_argv) diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c index e460011f77..f0b2f0d57f 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -81,15 +81,15 @@ image file and kernel log file are aleady opened with exclusive write lock by pre-executed emulator. But it is still useful for emulator-manager. */ -void make_vm_lock_os(void) +void make_vm_lock_os(gchar *vm_path) { g_assert(lock_file == INVALID_HANDLE_VALUE); g_assert(lock_filename == NULL); - lock_filename = g_strdup_printf("%s.lock", get_drive_image_file()); + lock_filename = g_strdup_printf("%s\\%s", vm_path, VMLOCK_FILE); if (g_mkdir_with_parents(g_path_get_dirname(lock_filename), 0777)) { - ERR("Can not create directory for lock file: %ld\n", + ERR("Cannot create directory for lock file: %ld\n", GetLastError()); } lock_file = CreateFile(lock_filename, @@ -105,7 +105,7 @@ void make_vm_lock_os(void) // naturally unless FILE_SHARE_* attribute is set. if (error == ERROR_SHARING_VIOLATION) { maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "Can not execute this VM.\n" + "Cannot execute this VM.\n" "The same VM may be running now."); exit(1); } diff --git a/tizen/src/util/osutil.c b/tizen/src/util/osutil.c index e8a3a5d186..6a0b8cdc79 100644 --- a/tizen/src/util/osutil.c +++ b/tizen/src/util/osutil.c @@ -46,6 +46,7 @@ MULTI_DEBUG_CHANNEL(emulator, osutil); #include "maru_err_table.h" static int lock_file = -1; +static gchar *lock_filename = NULL; static struct flock _lock = { .l_type = F_WRLCK, .l_start = 0, @@ -162,6 +163,7 @@ static bool fd_checklock(int fd) static void remove_vm_lock_posix(void) { + int error = 0; if (lock_file == -1) { return; } @@ -171,6 +173,15 @@ static void remove_vm_lock_posix(void) } close(lock_file); + if (lock_filename != NULL) { + if (unlink(lock_filename) == -1) { + error = errno; + ERR("Failed to unlink lock file(%d): %s\n", + error, strerror(error)); + } + g_free(lock_filename); + lock_filename = NULL; + } lock_file = -1; } @@ -181,21 +192,25 @@ static void notify_remove_lock(Notifier *notifier, void *data) static Notifier remove_lock = { .notify = notify_remove_lock }; -void make_vm_lock_posix(void) +void make_vm_lock_posix(gchar *vms_path) { - const char *image_file = get_drive_image_file(); int error = 0; - g_assert(lock_file == -1); - g_assert(image_file != NULL); + lock_filename = g_strdup_printf("%s/%s", vms_path, VMLOCK_FILE); + + g_assert(lock_filename != NULL); retry: - lock_file = open(image_file, O_RDWR); + lock_file = open(lock_filename, O_RDWR|O_CREAT, 0666); if (lock_file == -1) { error = errno; - ERR("Failed to open image file for lock: %s\n", - strerror(error)); - return; + ERR("Failed to create file for lock(%d): %s\n", + error, strerror(error)); + maru_register_exit_msg(MARU_EXIT_UNKNOWN, + "Cannot execute this VM.\n" + "Failed to create file for lock."); + exit(1); + } if (fd_lock(lock_file) == -1) { @@ -209,8 +224,8 @@ retry: goto retry; } maru_register_exit_msg(MARU_EXIT_UNKNOWN, - "Can not execute this VM.\n" - "The same name is running now."); + "Cannot execute this VM.\n" + "The same VM may be running now."); exit(1); } diff --git a/tizen/src/util/osutil.h b/tizen/src/util/osutil.h index ce63254a9c..8dbe58e735 100644 --- a/tizen/src/util/osutil.h +++ b/tizen/src/util/osutil.h @@ -64,10 +64,11 @@ #define ERR_UNLCK 4 #define ERR_LCK 5 #define ERR_NOENT 6 +#define VMLOCK_FILE "vm.lock" extern const char *pac_tempfile; -void make_vm_lock_os(void); +void make_vm_lock_os(gchar *vm_path); bool make_sdcard_lock_os(char *sdcard); int remove_sdcard_lock_os(char *sdcard); @@ -84,7 +85,7 @@ typedef struct sdcard_info #ifndef CONFIG_WIN32 -void make_vm_lock_posix(void); +void make_vm_lock_posix(gchar *vm_path); bool make_sdcard_lock_posix(char *sdcard); int remove_sdcard_lock_posix(char *sdcard);