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>
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();
}
}
}
-}
\ No newline at end of file
+}