summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangho Park <sangho.p@samsung.com>2016-02-01 15:03:53 +0900
committerSeokYeon Hwang <syeon.hwang@samsung.com>2016-02-11 13:54:09 +0900
commita3d0d3da9ad5b00fd9d925adb6d4b4695c7d2976 (patch)
treedb245e9fbb8a7857b45353ad6d18d8d2898179f9
parente3fea05c242744a56101e992a1e1601d4edaf458 (diff)
downloadqemu-a3d0d3da9ad5b00fd9d925adb6d4b4695c7d2976.tar.gz
qemu-a3d0d3da9ad5b00fd9d925adb6d4b4695c7d2976.tar.bz2
qemu-a3d0d3da9ad5b00fd9d925adb6d4b4695c7d2976.zip
osutil: minor refactoring on vm_lock
* Remove assertion on remove vm_lock because lock_file can be INVALID_HANDLE_VALUE or -1 * Add assertion on locking vm * Remove redundant g_strdup() Change-Id: Ica262b8522aeec26561e5f06b46295b48159b307 Signed-off-by: Sangho Park <sangho.p@samsung.com>
-rw-r--r--tizen/src/util/osutil-win32.c36
-rw-r--r--tizen/src/util/osutil.c4
2 files changed, 24 insertions, 16 deletions
diff --git a/tizen/src/util/osutil-win32.c b/tizen/src/util/osutil-win32.c
index 388d7dfa05..a19bf75541 100644
--- a/tizen/src/util/osutil-win32.c
+++ b/tizen/src/util/osutil-win32.c
@@ -48,7 +48,7 @@
#include "new_debug_ch.h"
DECLARE_DEBUG_CHANNEL(osutil);
-static char *lock_filename;
+static char *lock_filename = NULL;
static HANDLE lock_file = INVALID_HANDLE_VALUE;
static sdcard_info info = {
@@ -58,12 +58,15 @@ static sdcard_info info = {
static void remove_vm_lock_os(void)
{
- g_assert(lock_file != INVALID_HANDLE_VALUE);
+ g_free(lock_filename);
+ lock_filename = NULL;
- CloseHandle(lock_file);
+ if (lock_file == INVALID_HANDLE_VALUE) {
+ return;
+ }
+ CloseHandle(lock_file);
lock_file = INVALID_HANDLE_VALUE;
- g_free(lock_filename);
}
static void notify_remove_lock(Notifier *notifier, void *data)
@@ -81,18 +84,22 @@ emulator-manager.
*/
void make_vm_lock_os(void)
{
- char *drive_image_filename = g_strdup(get_drive_image_file());
+ g_assert(lock_file == INVALID_HANDLE_VALUE);
+ g_assert(lock_filename == NULL);
- lock_filename = g_strdup_printf("%s.lock", drive_image_filename);
+ lock_filename = g_strdup_printf("%s.lock", get_drive_image_file());
- g_free(drive_image_filename);
-
- if(g_mkdir_with_parents(g_path_get_dirname(lock_filename), 0777)) {
- LOG_WARNING("Can not create lock file: %ld\n", GetLastError());
+ if (g_mkdir_with_parents(g_path_get_dirname(lock_filename), 0777)) {
+ LOG_WARNING("Can not create directory for lock file: %ld\n",
+ GetLastError());
}
- lock_file = CreateFile(lock_filename, GENERIC_READ | GENERIC_WRITE, 0,
- NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
+ lock_file = CreateFile(lock_filename,
+ GENERIC_READ | GENERIC_WRITE,
+ 0, // No share
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
if (lock_file == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
// On Windows, the file opened by CreateFile has exclusive lock
@@ -103,8 +110,7 @@ void make_vm_lock_os(void)
exit(1);
}
- LOG_WARNING("Can not create lock file: %0xlx\n", error);
-
+ LOG_WARNING("Failed to create lock file: %0xlx\n", error);
}
emulator_add_exit_notifier(&remove_lock);
diff --git a/tizen/src/util/osutil.c b/tizen/src/util/osutil.c
index f3e0abf436..371e1ac072 100644
--- a/tizen/src/util/osutil.c
+++ b/tizen/src/util/osutil.c
@@ -100,7 +100,9 @@ static bool fd_checklock(int fd)
static void remove_vm_lock_posix(void)
{
- g_assert(lock_file != -1);
+ if (lock_file == -1) {
+ return;
+ }
if (fd_unlock(lock_file)) {
LOG_INFO("Failed to remove lock from lock file");