monitoring: modified posix lock to shared
authorSangho Park <sangho.p@samsung.com>
Wed, 27 Jan 2016 08:36:24 +0000 (17:36 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 29 Jan 2016 06:24:56 +0000 (15:24 +0900)
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 <sangho.p@samsung.com>
src/org/tizen/emulator/manager/vms/monitor/PosixLockFileMonitor.java

index a5d9368..aa0d5f3 100644 (file)
@@ -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
+}