summaryrefslogtreecommitdiff
path: root/tizen/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'tizen/src/util')
-rw-r--r--tizen/src/util/osutil-darwin.c4
-rw-r--r--tizen/src/util/osutil-linux.c4
-rw-r--r--tizen/src/util/osutil-win32.c5
-rw-r--r--tizen/src/util/osutil.c29
-rw-r--r--tizen/src/util/osutil.h5
5 files changed, 31 insertions, 16 deletions
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);