Skip to content

Commit bb4df0c

Browse files
committed
Fixes OpenHFT#48
1 parent 9c918a9 commit bb4df0c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

affinity/src/main/java/net/openhft/affinity/lockchecker/FileBasedLockChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public boolean obtainLock(int id, String metaInfo) throws IOException {
3838
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
3939
new FileOutputStream(file, false), "utf-8"))) {
4040
writer.write(metaInfo + "\n" + df.format(new Date()));
41+
file.setWritable(true, false);
42+
file.setExecutable(false, false);
4143
return true;
4244
}
4345
}

affinity/src/main/java/net/openhft/affinity/lockchecker/FileLockBasedLockChecker.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
import java.nio.channels.OverlappingFileLockException;
1212
import java.nio.file.Files;
1313
import java.nio.file.StandardOpenOption;
14+
import java.nio.file.attribute.PosixFilePermission;
1415
import java.nio.file.attribute.PosixFilePermissions;
16+
import java.util.Arrays;
1517
import java.util.Date;
18+
import java.util.HashSet;
1619

20+
import static java.nio.file.StandardOpenOption.*;
1721
import static net.openhft.affinity.impl.VanillaCpuLayout.MAX_CPUS_SUPPORTED;
1822

1923
/**
@@ -54,7 +58,7 @@ private boolean isLockFree(File file, int id) {
5458

5559
//does another process have the lock?
5660
try {
57-
FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.WRITE);
61+
FileChannel fc = FileChannel.open(file.toPath(), WRITE);
5862
FileLock fileLock = fc.tryLock();
5963
if (fileLock == null) {
6064
return false;
@@ -77,8 +81,9 @@ public boolean obtainLock(int id, String metaInfo) throws IOException {
7781
return false;
7882
}
7983

80-
FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE_NEW,
81-
StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.SYNC);
84+
FileChannel fc = FileChannel.open(file.toPath(),
85+
new HashSet<>(Arrays.asList(CREATE_NEW, WRITE, READ, SYNC)),
86+
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-rw-rw-")));
8287
FileLock fl = fc.tryLock();
8388

8489
if(fl == null) {

0 commit comments

Comments
 (0)