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

handle UnsatisfiedLinkError in LinuxPOSIX constructor, resolves #187 #188

Merged
merged 1 commit into from
Feb 7, 2024
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
57 changes: 19 additions & 38 deletions src/main/java/jnr/posix/LinuxPOSIX.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@
import jnr.constants.platform.Pathconf;

final class LinuxPOSIX extends BaseNativePOSIX implements Linux {
private volatile boolean use_fxstat64 = true;
private volatile boolean use_lxstat64 = true;
private volatile boolean use_xstat64 = true;
private final boolean use_stat64;
private final int statVersion;

LinuxPOSIX(LibCProvider libcProvider, POSIXHandler handler) {
super(libcProvider, handler);

statVersion = getStatVersion();
use_stat64 = statVersion >= 0;
}

private int getStatVersion() {
if (Platform.IS_32_BIT || "sparcv9".equals(Platform.ARCH) || Platform.ARCH.contains("mips64")) {
statVersion = 3;
return 3;
} else {
FileStat stat = allocateStat();

if (((LinuxLibC) libc()).__xstat64(0, "/dev/null", stat) < 0) {
statVersion = 1;
} else {
statVersion = 0;
try {
if (((LinuxLibC) libc()).__xstat64(0, "/dev/null", stat) < 0) {
return 1;
}
return 0;
} catch (UnsatisfiedLinkError ex) {
return -1;
}
}
}
Expand Down Expand Up @@ -85,20 +89,8 @@ private int old_fstat(int fd, FileStat stat) {

@Override
public int fstat(int fd, FileStat stat) {
if (use_fxstat64) {
int ret;
try {
if ((ret = ((LinuxLibC) libc()).__fxstat64(statVersion, fd, stat)) < 0) {
handler.error(Errno.valueOf(errno()), "fstat", Integer.toString(fd));
}

return ret;

} catch (UnsatisfiedLinkError ex) {
use_fxstat64 = false;
return old_fstat(fd, stat);
}

if (use_stat64) {
return ((LinuxLibC) libc()).__fxstat64(statVersion, fd, stat);
} else {
return old_fstat(fd, stat);
}
Expand Down Expand Up @@ -137,13 +129,8 @@ private final int old_lstat(String path, FileStat stat) {

@Override
public int lstat(String path, FileStat stat) {
if (use_lxstat64) {
try {
return ((LinuxLibC) libc()).__lxstat64(statVersion, path, stat);
} catch (UnsatisfiedLinkError ex) {
use_lxstat64 = false;
return old_lstat(path, stat);
}
if (use_stat64) {
return ((LinuxLibC) libc()).__lxstat64(statVersion, path, stat);
} else {
return old_lstat(path, stat);
}
Expand All @@ -169,14 +156,8 @@ private final int old_stat(String path, FileStat stat) {
@Override
public int stat(String path, FileStat stat) {

if (use_xstat64) {
try {
return ((LinuxLibC) libc()).__xstat64(statVersion, path, stat);
} catch (UnsatisfiedLinkError ex) {
use_xstat64 = false;
return old_stat(path, stat);
}

if (use_stat64) {
return ((LinuxLibC) libc()).__xstat64(statVersion, path, stat);
} else {
return old_stat(path, stat);
}
Expand Down
Loading