From 62dec5b1762ceb56e22d56bd4ecafa2bdc97554a Mon Sep 17 00:00:00 2001 From: Sangho Park Date: Wed, 27 Jan 2016 17:36:24 +0900 Subject: [PATCH] monitoring: modified posix lock to shared Current posix file locking method has two problems. 1. An emulator can think that other emulator is running even though no emulator runs and just the manager locks the file. 2. An emulator manager can think that an emulator is running even though no emulator runs and just other manager locks the file. Changing the lock by shared can eliminate the above 2 problems if the emulator checks the type of lock. With qemu patch, the problems can be avoided. Change-Id: Id24b51a241890da781546186e2efb9f1b7346a48 Signed-off-by: Sangho Park --- .../tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/org/tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java b/src/org/tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java index a5d9368..aa0d5f3 100644 --- a/src/org/tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java +++ b/src/org/tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java @@ -50,8 +50,9 @@ final class PosixLockFileMonitor extends LockFileMonitor { assert Files.isRegularFile(lockfile) && Files.isWritable(lockfile); - FileChannel fc = FileChannel.open(lockfile, StandardOpenOption.WRITE); - FileLock lock = fc.tryLock(); + FileChannel fc = FileChannel.open(lockfile, StandardOpenOption.READ); + // Lock the file by shared. Only emulator lock the file exclusively. + FileLock lock = fc.tryLock(0, 1, true); if (lock != null && lock.isValid()) { lock.release(); @@ -111,4 +112,4 @@ final class PosixLockFileMonitor extends LockFileMonitor { } } } -} \ No newline at end of file +} -- 2.7.4