aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/cpp/blaze.cc13
-rw-r--r--src/main/java/com/google/devtools/build/lib/server/RPCServer.java10
2 files changed, 12 insertions, 11 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index cbcf4167e9..19e03ce4f7 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -546,13 +546,13 @@ static string VerifyJavaVersionAndGetJvm() {
static int StartServer() {
vector<string> jvm_args_vector = GetArgumentArray();
string argument_string = GetArgumentString(jvm_args_vector);
-
+ string server_dir = globals->options.output_base + "/server";
// Write the cmdline argument string to the server dir. If we get to this
// point, there is no server running, so we don't overwrite the cmdline file
// for the existing server. If might be that the server dies and the cmdline
// file stays there, but that is not a problem, since we always check the
// server, too.
- WriteFile(argument_string, globals->options.output_base + "/server/cmdline");
+ WriteFile(argument_string, server_dir + "/cmdline");
// unless we restarted for a new-version, mark this as initial start
if (globals->restart_reason == NO_RESTART) {
@@ -581,6 +581,15 @@ static int StartServer() {
}
Daemonize();
+
+ // TODO(lberki): This writes the wrong PID on Windows because ExecuteProgram()
+ // invokes CreateProcess() there.
+ if (!WriteFile(ToString(getpid()), server_dir + "/server.pid")) {
+ // The exit code does not matter because we are already in the daemonized
+ // server. The output of this operation will end up in jvm.out .
+ pdie(0, "Cannot write PID file");
+ }
+
ExecuteProgram(exe, jvm_args_vector);
pdie(blaze_exit_code::INTERNAL_ERROR, "execv of '%s' failed", exe.c_str());
return -1;
diff --git a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java
index 6c6a8429ea..1997498209 100644
--- a/src/main/java/com/google/devtools/build/lib/server/RPCServer.java
+++ b/src/main/java/com/google/devtools/build/lib/server/RPCServer.java
@@ -15,8 +15,6 @@ package com.google.devtools.build.lib.server;
import com.google.devtools.build.lib.runtime.CommandExecutor;
import com.google.devtools.build.lib.util.Clock;
-import com.google.devtools.build.lib.util.OsUtils;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import java.io.IOException;
@@ -41,17 +39,11 @@ public abstract class RPCServer {
}
protected RPCServer(Path serverDirectory) throws IOException {
- // We create the server.pid file strictly before binding the socket.
+ // server.pid was written in the C++ launcher after fork() but before exec() .
// The client only accesses the pid file after connecting to the socket
// which ensures that it gets the correct pid value.
Path pidFile = serverDirectory.getRelative("server.pid");
RPCServer.deleteAtExit(pidFile, /*deleteParent=*/ false);
- try {
- pidFile.delete();
- } catch (IOException e) {
- // Ignore.
- }
- FileSystemUtils.writeContentAsLatin1(pidFile, String.valueOf(OsUtils.getpid()));
}
/**