diff options
author | Munkyu Im <munkyu.im@samsung.com> | 2016-09-26 18:14:21 +0900 |
---|---|---|
committer | Munkyu Im <munkyu.im@samsung.com> | 2016-09-26 18:23:39 +0900 |
commit | c14765c5052b04ec3b85a1adb458e400c0e0a5e7 (patch) | |
tree | a8937a0f292911336fcf7a109a07fbd048bfaf8e | |
parent | 168fae707fb10068ea59795f3e4e49a59b2ef688 (diff) | |
download | qemu-c14765c5052b04ec3b85a1adb458e400c0e0a5e7.tar.gz qemu-c14765c5052b04ec3b85a1adb458e400c0e0a5e7.tar.bz2 qemu-c14765c5052b04ec3b85a1adb458e400c0e0a5e7.zip |
osutil: adjust vm lock module
- move it to an earlier time.(early launching time)
- make the same lock file(vm.lock) on each host OS.
Change-Id: I80744500bf7c25c536061d2952f7f6552a0406f1
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
-rw-r--r-- | tizen/src/emulator.c | 2 | ||||
-rw-r--r-- | tizen/src/util/osutil-darwin.c | 4 | ||||
-rw-r--r-- | tizen/src/util/osutil-linux.c | 4 | ||||
-rw-r--r-- | tizen/src/util/osutil-win32.c | 5 | ||||
-rw-r--r-- | tizen/src/util/osutil.c | 29 | ||||
-rw-r--r-- | tizen/src/util/osutil.h | 5 |
6 files changed, 32 insertions, 17 deletions
diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index b1d6bab6c8..940e0d1409 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -240,7 +240,6 @@ const char *prepare_maru(const char * const kernel_cmdline) void prepare_maru_after_device_init(void) { - make_vm_lock_os(); init_device_hotplug(); start_ecs(); @@ -308,6 +307,7 @@ static int emulator_main(int argc, char *argv[], char **envp) set_bin_path_os(_qemu_argv[0]); if (launch_conf_file) { + make_vm_lock_os(g_path_get_dirname(launch_conf_file)); if (!load_conf(launch_conf_file)) { return -1; } diff --git a/tizen/src/util/osutil-darwin.c b/tizen/src/util/osutil-darwin.c index b27ed7ca24..c797ca8df0 100644 --- a/tizen/src/util/osutil-darwin.c +++ b/tizen/src/util/osutil-darwin.c @@ -47,8 +47,8 @@ #include "new_debug_ch.h" DECLARE_DEBUG_CHANNEL(osutil); -void make_vm_lock_os(void) { - make_vm_lock_posix(); +void make_vm_lock_os(gchar *vms_path) { + make_vm_lock_posix(vms_path); } void set_bin_path_os(char const *const exec_argv) diff --git a/tizen/src/util/osutil-linux.c b/tizen/src/util/osutil-linux.c index 8e432f990b..c46e46123f 100644 --- a/tizen/src/util/osutil-linux.c +++ b/tizen/src/util/osutil-linux.c @@ -50,8 +50,8 @@ #include "new_debug_ch.h" DECLARE_DEBUG_CHANNEL(osutil); -void make_vm_lock_os(void) { - make_vm_lock_posix(); +void make_vm_lock_os(gchar *vms_path) { + make_vm_lock_posix(vms_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 a76edfc2e6..bced9f8e7a 100644 --- a/tizen/src/util/osutil-win32.c +++ b/tizen/src/util/osutil-win32.c @@ -83,12 +83,13 @@ 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 *vms_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", vms_path, VMLOCK_FILE); if (g_mkdir_with_parents(g_path_get_dirname(lock_filename), 0777)) { LOG_WARNING("Can not create directory for lock file: %ld\n", diff --git a/tizen/src/util/osutil.c b/tizen/src/util/osutil.c index 099e1780b7..de78c53d42 100644 --- a/tizen/src/util/osutil.c +++ b/tizen/src/util/osutil.c @@ -46,6 +46,7 @@ DECLARE_DEBUG_CHANNEL(osutil) static int lock_file = -1; +static gchar *lock_filename = NULL; static struct flock _lock = { .l_type = F_WRLCK, .l_start = 0, @@ -101,6 +102,7 @@ static bool fd_checklock(int fd) static void remove_vm_lock_posix(void) { + int error = 0; if (lock_file == -1) { return; } @@ -110,6 +112,16 @@ static void remove_vm_lock_posix(void) } close(lock_file); + if (lock_filename != NULL) { + if (unlink(lock_filename) == -1) { + error = errno; + LOG_WARNING("Failed to unlink lock file(%d): %s\n", + error, strerror(error)); + } + g_free(lock_filename); + lock_filename = NULL; + } + lock_file = -1; } @@ -120,21 +132,22 @@ 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; + lock_filename = g_strdup_printf("%s/%s", vms_path, VMLOCK_FILE); - g_assert(lock_file == -1); - g_assert(image_file != NULL); + 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; - LOG_WARNING("Failed to open image file for lock: %s\n", - strerror(error)); - return; + 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); } if (fd_lock(lock_file) == -1) { diff --git a/tizen/src/util/osutil.h b/tizen/src/util/osutil.h index 8e9d2ac519..7dc9fea2f4 100644 --- a/tizen/src/util/osutil.h +++ b/tizen/src/util/osutil.h @@ -42,15 +42,16 @@ #define ERR_NODEV 4 /* ACT_SDCARD_DETACH_FAIL. No sdcard attached. */ #define ERR_BUSY 5 /* ACT_SDCARD_ATTACH_FAIL. Already sdcard attached. */ #define ERR_NOENT 6 /* ACT_SDCARD_NO_ATTACH_FOUND. Other sdcard attached. */ +#define VMLOCK_FILE "vm.lock" extern const char *pac_tempfile; -void make_vm_lock_os(void); +void make_vm_lock_os(gchar *vms_path); bool make_sdcard_lock_os(char *sdcard); int remove_sdcard_lock_os(char *sdcard); #ifndef CONFIG_WIN32 -void make_vm_lock_posix(void); +void make_vm_lock_posix(gchar *dirname); bool make_sdcard_lock_posix(char *sdcard); int remove_sdcard_lock_posix(char *sdcard); |