Log the server pid to java logging.
@@ -559,7 +559,11 @@ public final class BlazeRuntime {
// Run Blaze in batch mode.
System.exit(batchMain(modules, args));
}
- LOG.info("Starting Blaze server with args " + Arrays.toString(args));
+ LOG.info(
+ "Starting Blaze server with pid "
+ + maybeGetPidString()
+ + " and args "
+ + Arrays.toString(args));
try {
// Run Blaze in server mode.
System.exit(serverMain(modules, OutErr.SYSTEM_OUT_ERR, args));
@@ -736,7 +740,10 @@ public final class BlazeRuntime {
private static int batchMain(Iterable<BlazeModule> modules, String[] args) {
captureSigint();
CommandLineOptions commandLineOptions = splitStartupOptions(modules, args);
- LOG.info("Running Blaze in batch mode with startup args "
+ LOG.info(
+ "Running Blaze in batch mode with "
+ + maybeGetPidString()
+ + "startup args "
+ commandLineOptions.getStartupArgs());
BlazeRuntime runtime;
@@ -933,7 +940,7 @@ public final class BlazeRuntime {
PathFragment installBase = startupOptions.installBase;
PathFragment outputBase = startupOptions.outputBase;
- maybeForceJNI(installBase); // Must be before first use of JNI.
+ maybeForceJNIByGettingPid(installBase); // Must be before first use of JNI.
// From the point of view of the Java program --install_base and --output_base
// are mandatory options, despite the comment in their declarations.
@@ -1017,13 +1024,15 @@ public final class BlazeRuntime {
return runtime;
}
- /**
- * Loads JNI libraries, if necessary under the current platform.
- */
- public static void maybeForceJNI(PathFragment installBase) {
- if (jniLibsAvailable()) {
- forceJNI(installBase);
+ private static String maybeGetPidString() {
+ Integer pid = maybeForceJNIByGettingPid(null);
+ return pid == null ? "" : "pid " + pid + " and ";
}
+
+ /** Loads JNI libraries, if necessary under the current platform. */
+ @Nullable
+ private static Integer maybeForceJNIByGettingPid(@Nullable PathFragment installBase) {
+ return jniLibsAvailable() ? getPidUsingJNI(installBase) : null;
}
private static boolean jniLibsAvailable() {
@@ -1032,13 +1041,19 @@ public final class BlazeRuntime {
// Force JNI linking at a moment when we have 'installBase' handy, and print
// an informative error if it fails.
- private static void forceJNI(PathFragment installBase) {
+ private static int getPidUsingJNI(@Nullable PathFragment installBase) {
try {
- ProcessUtils.getpid(); // force JNI initialization
+ return ProcessUtils.getpid(); // force JNI initialization
} catch (UnsatisfiedLinkError t) {
- System.err.println("JNI initialization failed: " + t.getMessage() + ". "
- + "Possibly your installation has been corrupted; "
- + "if this problem persists, try 'rm -fr " + installBase + "'.");
+ System.err.println(
+ "JNI initialization failed: "
+ + t.getMessage()
+ + ". "
+ + "Possibly your installation has been corrupted"
+ + (installBase == null
+ ? ""
+ : "; if this problem persists, try 'rm -fr " + installBase + "'")
+ + ".");
throw t;
}
}
