Only log native library loading errors if we attempt to use it
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@663 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -44,7 +44,7 @@ public class Unsafe
|
|||||||
public static void setGCEnabled (boolean enabled)
|
public static void setGCEnabled (boolean enabled)
|
||||||
{
|
{
|
||||||
// we don't support nesting, NOOP if the state doesn't change
|
// we don't support nesting, NOOP if the state doesn't change
|
||||||
if (_loaded) {
|
if (isLoaded()) {
|
||||||
if (!_initialized && !(_initialized = init())) {
|
if (!_initialized && !(_initialized = init())) {
|
||||||
// no joy initializing things
|
// no joy initializing things
|
||||||
return;
|
return;
|
||||||
@@ -69,7 +69,7 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
public static void sleep (int millis)
|
public static void sleep (int millis)
|
||||||
{
|
{
|
||||||
if (_loaded && RunAnywhere.isLinux()) {
|
if (RunAnywhere.isLinux() && isLoaded()) {
|
||||||
nativeSleep(millis);
|
nativeSleep(millis);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -87,7 +87,7 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
public static boolean setuid (int uid)
|
public static boolean setuid (int uid)
|
||||||
{
|
{
|
||||||
if (_loaded && !RunAnywhere.isWindows()) {
|
if (!RunAnywhere.isWindows() && isLoaded()) {
|
||||||
return nativeSetuid(uid);
|
return nativeSetuid(uid);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -100,7 +100,7 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
public static boolean setgid (int gid)
|
public static boolean setgid (int gid)
|
||||||
{
|
{
|
||||||
if (_loaded && !RunAnywhere.isWindows()) {
|
if (!RunAnywhere.isWindows() && isLoaded()) {
|
||||||
return nativeSetgid(gid);
|
return nativeSetgid(gid);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -113,7 +113,7 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
public static boolean seteuid (int uid)
|
public static boolean seteuid (int uid)
|
||||||
{
|
{
|
||||||
if (_loaded && !RunAnywhere.isWindows()) {
|
if (!RunAnywhere.isWindows() && isLoaded()) {
|
||||||
return nativeSeteuid(uid);
|
return nativeSeteuid(uid);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -126,12 +126,25 @@ public class Unsafe
|
|||||||
*/
|
*/
|
||||||
public static boolean setegid (int gid)
|
public static boolean setegid (int gid)
|
||||||
{
|
{
|
||||||
if (_loaded && !RunAnywhere.isWindows()) {
|
if (!RunAnywhere.isWindows() && isLoaded()) {
|
||||||
return nativeSetegid(gid);
|
return nativeSetegid(gid);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the native library was successfully loaded, and if this is the first time
|
||||||
|
* it's been checked and it failed, reports the failure.
|
||||||
|
*/
|
||||||
|
protected static boolean isLoaded ()
|
||||||
|
{
|
||||||
|
if (_loadError != null) {
|
||||||
|
log.warning("Unable to load 'unsafe' library", "e", _loadError);
|
||||||
|
_loadError = null;
|
||||||
|
}
|
||||||
|
return _loaded;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reenable garbage collection after a call to {@link #disableGC}.
|
* Reenable garbage collection after a call to {@link #disableGC}.
|
||||||
*/
|
*/
|
||||||
@@ -181,14 +194,18 @@ public class Unsafe
|
|||||||
/** Whether or not we were able to initialize our library (i.e. get access to jvmpi) */
|
/** Whether or not we were able to initialize our library (i.e. get access to jvmpi) */
|
||||||
protected static boolean _initialized;
|
protected static boolean _initialized;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The error that occurred when loading the native library, or null if none occurred or it was
|
||||||
|
* already reported.
|
||||||
|
*/
|
||||||
|
protected static Throwable _loadError;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
System.loadLibrary("unsafe");
|
System.loadLibrary("unsafe");
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
} catch (SecurityException se) {
|
} catch (Throwable t) {
|
||||||
log.warning("Failed to load 'unsafe' library: " + se + ".");
|
_loadError = t;
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
log.warning("Failed to load 'unsafe' library: " + e + ".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user