void prepare_maru_after_device_init(void)
{
- make_vm_lock_os();
maru_device_hotplug_init();
qemu_add_opts(&qemu_ecs_opts);
start_ecs();
set_bin_path(_qemu_argv[0]);
+ make_vm_lock_os(g_path_get_dirname(conf));
if (!load_conf(conf)) {
return -1;
}
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;
{ "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)
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,
// 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);
}
#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,
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;
+ ERR("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;
- 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) {
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);
}
#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);
#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);