Skip to content

Commit 81c8c56

Browse files
authored
Enable multi-user OpenJ9 attachment by enforcing 0666 lock file permissions (#1899)
1 parent f8670d3 commit 81c8c56

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,13 +1717,23 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di
17171717
? new File(dispatcher.getTemporaryFolder(processId), ".com_ibm_tools_attach")
17181718
: new File(temporary);
17191719
long userId = dispatcher.userId();
1720-
RandomAccessFile attachLock = new RandomAccessFile(new File(directory, "_attachlock"), "rw");
1720+
File attachLockFile = new File(directory, "_attachlock");
1721+
boolean attachLockCreated = attachLockFile.createNewFile();
1722+
RandomAccessFile attachLock = new RandomAccessFile(attachLockFile, "rw");
17211723
try {
1724+
if (attachLockCreated || userId == 0 || dispatcher.getOwnerIdOf(attachLockFile) == userId) {
1725+
dispatcher.setPermissions(attachLockFile, 0666);
1726+
}
17221727
FileLock attachLockLock = attachLock.getChannel().lock();
17231728
try {
17241729
List<Properties> virtualMachines;
1725-
RandomAccessFile master = new RandomAccessFile(new File(directory, "_master"), "rw");
1730+
File masterFile = new File(directory, "_master");
1731+
boolean masterCreated = masterFile.createNewFile();
1732+
RandomAccessFile master = new RandomAccessFile(masterFile, "rw");
17261733
try {
1734+
if (masterCreated || userId == 0 || dispatcher.getOwnerIdOf(masterFile) == userId) {
1735+
dispatcher.setPermissions(masterFile, 0666);
1736+
}
17271737
FileLock masterLock = master.getChannel().lock();
17281738
try {
17291739
File[] vmFolder = directory.listFiles();

0 commit comments

Comments
 (0)