modules/core/native-system/src/main/java/org/rhq/core/system/SigarAccess.java
| 2
modules/core/native-system/src/main/java/org/rhq/core/system/SystemInfoFactory.java
| 53 ++++------
modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
| 7 -
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/NativePromptCommand.java
| 16 +--
modules/plugins/lsof/src/main/java/org/rhq/plugins/lsof/LsofDiscoveryComponent.java
| 8 -
5 files changed, 43 insertions(+), 43 deletions(-)
New commits:
commit cb654429a9c0d0d30092a21740da5e1d4e614be2
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Wed Oct 31 10:47:24 2012 -0500
[BZ 869730] Move static block of code that was checking for Sigar availability to a
static method to be able to use correctly at startup both system properties and stored
agent preferences. This change will avoid attempts to load the Sigar library even if
--nonative flag or rhq.agent.disable-native-system property are set to true.
Before this change the static initializer would probe the sigar library as soon as the
SystemInfoFactory class was loaded even if not used later by the agent (native system
disabled). This was causing the entire JVM to crash on some systems and could not be
prevented even with --nonative.
diff --git a/modules/core/native-system/src/main/java/org/rhq/core/system/SigarAccess.java
b/modules/core/native-system/src/main/java/org/rhq/core/system/SigarAccess.java
index f28d92d..ee98a09 100644
--- a/modules/core/native-system/src/main/java/org/rhq/core/system/SigarAccess.java
+++ b/modules/core/native-system/src/main/java/org/rhq/core/system/SigarAccess.java
@@ -69,7 +69,7 @@ public class SigarAccess {
}
public static boolean isSigarAvailable() {
- if (SystemInfoFactory.isNativeSystemInfoAvailable() &&
!SystemInfoFactory.isNativeSystemInfoDisabled()) {
+ if (!SystemInfoFactory.isNativeSystemInfoDisabled() &&
SystemInfoFactory.isNativeSystemInfoAvailable()) {
// its available, but it may not yet have been initialized. If it has not
been initialized,
// make a call that forces it to be initialized and loaded. 99% of the time,
the native layer
// will already be initialized and this check will be very fast.
diff --git
a/modules/core/native-system/src/main/java/org/rhq/core/system/SystemInfoFactory.java
b/modules/core/native-system/src/main/java/org/rhq/core/system/SystemInfoFactory.java
index 8d9e05d..df35169 100644
--- a/modules/core/native-system/src/main/java/org/rhq/core/system/SystemInfoFactory.java
+++ b/modules/core/native-system/src/main/java/org/rhq/core/system/SystemInfoFactory.java
@@ -70,30 +70,6 @@ public class SystemInfoFactory {
load, VERSION_STRING, BUILD_DATE, NATIVE_VERSION_STRING, NATIVE_BUILD_DATE
}
- static {
- try {
- Class<?> clazz = Class.forName(NATIVE_LIBRARY_CLASS_NAME);
-
- nativeApis.put(NativeApi.load, clazz.getMethod(NativeApi.load.name(), new
Class[0]));
- nativeApis.put(NativeApi.VERSION_STRING,
clazz.getField(NativeApi.VERSION_STRING.name()));
- nativeApis.put(NativeApi.BUILD_DATE,
clazz.getField(NativeApi.BUILD_DATE.name()));
- nativeApis.put(NativeApi.NATIVE_VERSION_STRING,
clazz.getField(NativeApi.NATIVE_VERSION_STRING.name()));
- nativeApis.put(NativeApi.NATIVE_BUILD_DATE,
clazz.getField(NativeApi.NATIVE_BUILD_DATE.name()));
-
- invokeApi(NativeApi.load);
-
- nativeLibraryLoadable = true;
- } catch (Throwable t) {
- // We don't have the JNI classes (sigar.jar) and/or the native shared
library (e.g. libsigar-amd64-linux.so).
- // This might be expected (e.g. the admin console WAR (Embedded Jopr) does
not include SIGAR), so don't log
- // anything, but store the Throwable, so callers can log the cause when
appropriate.
- nativeLibraryLoadable = false;
- nativeLibraryLoadThrowable = t;
- }
-
- disabled = !nativeLibraryLoadable; // automatically disable native system info
iff the native library is not loadable
- }
-
/**
* If the native system is both {@link #isNativeSystemInfoAvailable() available} and
* {@link #isNativeSystemInfoDisabled() enabled}, this will return the native
system's version string. Otherwise, a
@@ -107,7 +83,7 @@ public class SystemInfoFactory {
initialize(); // make sure we've loaded the native libraries, if appropriate
- if (isNativeSystemInfoAvailable() && !isNativeSystemInfoDisabled()) {
+ if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable()) {
try {
version = "Version=" + invokeApi(NativeApi.VERSION_STRING) +
" (" + invokeApi(NativeApi.BUILD_DATE)
+ "); Native version=" +
invokeApi(NativeApi.NATIVE_VERSION_STRING) + " ("
@@ -173,6 +149,8 @@ public class SystemInfoFactory {
* @see JavaSystemInfo
*/
public static boolean isNativeSystemInfoAvailable() {
+ initialize();
+
return nativeLibraryLoadable;
}
@@ -213,7 +191,7 @@ public class SystemInfoFactory {
SystemInfo nativePlatform = null;
- if (isNativeSystemInfoAvailable() && !isNativeSystemInfoDisabled())
{
+ if (!isNativeSystemInfoDisabled() && isNativeSystemInfoAvailable())
{
// we could use SIGAR here, but this should be enough
if
(System.getProperty("os.name").toLowerCase().indexOf("windows") >
-1) {
nativePlatform = new WindowsNativeSystemInfo();
@@ -276,15 +254,32 @@ public class SystemInfoFactory {
*/
private static synchronized void initialize() {
if (!initialized) {
- if (isNativeSystemInfoAvailable() && !isNativeSystemInfoDisabled())
{
+ if (!isNativeSystemInfoDisabled()) {
try {
+ Class<?> clazz = Class.forName(NATIVE_LIBRARY_CLASS_NAME);
+
+ nativeApis.put(NativeApi.load, clazz.getMethod(NativeApi.load.name(),
new Class[0]));
+ nativeApis.put(NativeApi.VERSION_STRING,
clazz.getField(NativeApi.VERSION_STRING.name()));
+ nativeApis.put(NativeApi.BUILD_DATE,
clazz.getField(NativeApi.BUILD_DATE.name()));
+ nativeApis.put(NativeApi.NATIVE_VERSION_STRING,
clazz.getField(NativeApi.NATIVE_VERSION_STRING.name()));
+ nativeApis.put(NativeApi.NATIVE_BUILD_DATE,
clazz.getField(NativeApi.NATIVE_BUILD_DATE.name()));
+
invokeApi(NativeApi.load);
+
+ nativeLibraryLoadable = true;
+
initialized = true; // we only set this to true when we actually
initialized the native layer
} catch (Throwable t) {
+ // We don't have the JNI classes (sigar.jar) and/or the native
shared library (e.g. libsigar-amd64-linux.so).
+ // This might be expected (e.g. the admin console WAR (Embedded Jopr)
does not include SIGAR), so don't log
+ // anything, but store the Throwable, so callers can log the cause
when appropriate.
+ nativeLibraryLoadable = false;
+ nativeLibraryLoadThrowable = t;
+
LOG.warn("Native library not available on this platform: "
+ ThrowableUtil.getAllMessages(t));
LOG.debug("Native library failure stack trace follows: ",
t);
- nativeLibraryLoadable = false;
- disabled = true;
+
+ disabled = true; // automatically disable native system info if the
native library is not loadable
}
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
index 730effc..46e72bd 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/StandaloneContainer.java
@@ -431,9 +431,12 @@ public class StandaloneContainer {
SystemInfoFactory.disableNativeSystemInfo();
System.out.println("Native layer disabled.");
} else if (what.startsWith("s")) {
- System.out.println(SystemInfoFactory.isNativeSystemInfoAvailable() ?
"Available" : "Not Available");
+ System.out.println("Native layer is:");
System.out.println(SystemInfoFactory.isNativeSystemInfoDisabled() ?
"Disabled" : "Enabled");
- System.out.println(SystemInfoFactory.isNativeSystemInfoInitialized() ?
"Initialized" : "Not initialized");
+ if (!SystemInfoFactory.isNativeSystemInfoDisabled()) {
+ System.out.println(SystemInfoFactory.isNativeSystemInfoAvailable() ?
"Available" : "Not Available");
+ System.out.println(SystemInfoFactory.isNativeSystemInfoInitialized() ?
"Initialized" : "Not initialized");
+ }
} else {
System.err.println("Unknown option. Only 'e', 'd' and
's' are applicable (enable/disable/status)");
return;
diff --git
a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/NativePromptCommand.java
b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/NativePromptCommand.java
index 5ef242f..9ebf4b5 100644
---
a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/NativePromptCommand.java
+++
b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/NativePromptCommand.java
@@ -54,16 +54,18 @@ public class NativePromptCommand implements AgentPromptCommand {
if (args.length <= 1) {
out.println(MSG
- .getMsg(SystemInfoFactory.isNativeSystemInfoAvailable() ?
AgentI18NResourceKeys.NATIVE_IS_AVAILABLE
- : AgentI18NResourceKeys.NATIVE_IS_NOT_AVAILABLE));
-
- out.println(MSG
.getMsg(SystemInfoFactory.isNativeSystemInfoDisabled() ?
AgentI18NResourceKeys.NATIVE_IS_DISABLED
: AgentI18NResourceKeys.NATIVE_IS_NOT_DISABLED));
- out.println(MSG
- .getMsg(SystemInfoFactory.isNativeSystemInfoInitialized() ?
AgentI18NResourceKeys.NATIVE_IS_INITIALIZED
- : AgentI18NResourceKeys.NATIVE_IS_NOT_INITIALIZED));
+ if (!SystemInfoFactory.isNativeSystemInfoDisabled()) {
+ out.println(MSG
+ .getMsg(SystemInfoFactory.isNativeSystemInfoAvailable() ?
AgentI18NResourceKeys.NATIVE_IS_AVAILABLE
+ : AgentI18NResourceKeys.NATIVE_IS_NOT_AVAILABLE));
+
+ out.println(MSG
+ .getMsg(SystemInfoFactory.isNativeSystemInfoInitialized() ?
AgentI18NResourceKeys.NATIVE_IS_INITIALIZED
+ : AgentI18NResourceKeys.NATIVE_IS_NOT_INITIALIZED));
+ }
return true;
}
diff --git
a/modules/plugins/lsof/src/main/java/org/rhq/plugins/lsof/LsofDiscoveryComponent.java
b/modules/plugins/lsof/src/main/java/org/rhq/plugins/lsof/LsofDiscoveryComponent.java
index a5bfe31..22820a9 100644
--- a/modules/plugins/lsof/src/main/java/org/rhq/plugins/lsof/LsofDiscoveryComponent.java
+++ b/modules/plugins/lsof/src/main/java/org/rhq/plugins/lsof/LsofDiscoveryComponent.java
@@ -53,14 +53,14 @@ public class LsofDiscoveryComponent extends ScriptDiscoveryComponent
{
switch (detectionMechanism) {
case INTERNAL:
- if (!SystemInfoFactory.isNativeSystemInfoAvailable()) {
- throw new InvalidPluginConfigurationException(
- "The native system is not available - cannot use the internal
detection mechanism");
- }
if (SystemInfoFactory.isNativeSystemInfoDisabled()) {
throw new InvalidPluginConfigurationException(
"The native system is disabled - cannot use the internal
detection mechanism");
}
+ if (!SystemInfoFactory.isNativeSystemInfoAvailable()) {
+ throw new InvalidPluginConfigurationException(
+ "The native system is not available - cannot use the internal
detection mechanism");
+ }
String version = LsofComponent.VERSION;
details = new DiscoveredResourceDetails(discoveryContext.getResourceType(),
"*lsof-internal*",
DEFAULT_NAME, version, DEFAULT_DESCRIPTION, pluginConfig, null);