void prepare_maru_after_device_init(void)
{
- make_vm_lock_os();
init_device_hotplug();
start_ecs();
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;
}
#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)
#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)
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",
static int lock_file = -1;
+static gchar *lock_filename = NULL;
static struct flock _lock = {
.l_type = F_WRLCK,
.l_start = 0,
static void remove_vm_lock_posix(void)
{
+ int error = 0;
if (lock_file == -1) {
return;
}
}
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;
}
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) {
#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);