Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenJ9 attach on macOS #763

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,8 @@ public int getOwnerIdOf(File file) {
try {
// The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
// stat is called as a separate command. This is less efficient but more portable.
Process process = Runtime.getRuntime().exec("stat -c=%u " + file.getAbsolutePath());
String statUserSwitch = Platform.isMac() ? "-f" : "-c";
Process process = Runtime.getRuntime().exec("stat " + statUserSwitch + " %u " + file.getAbsolutePath());
int attempts = this.attempts;
boolean exited = false;
String line = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8")).readLine();
Expand All @@ -2043,7 +2044,7 @@ public int getOwnerIdOf(File file) {
process.destroy();
throw new IllegalStateException("Command for stat did not exit in time");
}
return Integer.parseInt(line.substring(1));
return Integer.parseInt(line);
} catch (IOException exception) {
throw new IllegalStateException("Unable to execute stat command", exception);
}
Expand Down Expand Up @@ -2091,7 +2092,8 @@ private void notifySemaphore(File directory, String name, int count, short opera
try {
library.semop(semaphore, target, 1);
} catch (LastErrorException exception) {
if (acceptUnavailable && Native.getLastError() == PosixLibrary.EAGAIN) {
if (acceptUnavailable && (Native.getLastError() == PosixLibrary.EAGAIN
|| Native.getLastError() == PosixLibrary.EDEADLK)) {
break;
} else {
throw exception;
Expand Down Expand Up @@ -2123,6 +2125,11 @@ protected interface PosixLibrary extends Library {
*/
int EAGAIN = 11;

/**
* Indicates a dead lock on a resource.
*/
int EDEADLK = 35;

/**
* Indicates that a semaphore's operations should be undone at process shutdown.
*/
Expand Down