Remove the check for the existence of the server process in the signal handler in the client.

This makes Ctrl-C work on Windows somewhat: in particular, in non-batch mode and while no actions are running.

--
MOS_MIGRATED_REVID=125318172
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 6efa0f5..c706c37 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1466,19 +1466,15 @@
 
 // Signal handler.
 static void handler(int signum) {
-  // A defensive measure:
-  if (kill(globals->server_pid, 0) == -1 && errno == ESRCH) {
-    sigprintf("\n%s server has died; client exiting.\n\n",
-              globals->options.GetProductName().c_str());
-    _exit(1);
-  }
-
   switch (signum) {
     case SIGINT:
       if (++globals->sigint_count >= 3)  {
         sigprintf("\n%s caught third interrupt signal; killed.\n\n",
                   globals->options.GetProductName().c_str());
-        killpg(globals->server_pid, SIGKILL);
+        if (globals->server_pid != -1) {
+          KillServerProcess(globals->server_pid, globals->options.output_base,
+                            globals->options.install_base);
+        }
         _exit(1);
       }
       sigprintf("\n%s caught interrupt signal; shutting down.\n\n",
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index e40f808..0c5ced0 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -176,7 +176,7 @@
 }
 
 // Replaces 'contents' with contents of 'fd' file descriptor.
-// Returns false on error.
+// Returns false on error. Can be called from a signal handler.
 bool ReadFileDescriptor(int fd, string *content) {
   content->clear();
   char buf[4096];
@@ -193,7 +193,7 @@
 }
 
 // Replaces 'content' with contents of file 'filename'.
-// Returns false on error.
+// Returns false on error. Can be called from a signal handler.
 bool ReadFile(const string &filename, string *content) {
   int fd = open(filename.c_str(), O_RDONLY);
   if (fd == -1) return false;
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 3e34fa4..4b477d3 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -49,11 +49,11 @@
 int MakeDirectories(const string &path, mode_t mode);
 
 // Replaces 'content' with contents of file 'filename'.
-// Returns false on error.
+// Returns false on error. Can be called from a signal handler.
 bool ReadFile(const string &filename, string *content);
 
 // Replaces 'content' with contents of file descriptor 'fd'.
-// Returns false on error.
+// Returns false on error. Can be called from a signal handler.
 bool ReadFileDescriptor(int fd, string *content);
 
 // Writes 'content' into file 'filename', and makes it executable.
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 5a3ce94..ac6d3c1 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -182,6 +182,7 @@
   return blaze_util::Dirname(blaze_util::Dirname(javac_dir));
 }
 
+// Called from a signal handler!
 static bool GetStartTime(const string& pid, string* start_time) {
   string statfile = "/proc/" + pid + "/stat";
   string statline;
@@ -221,6 +222,9 @@
 // On Linux we use a combination of PID and start time to identify the server
 // process. That is supposed to be unique unless one can start more processes
 // than there are PIDs available within a single jiffy.
+//
+// This looks complicated, but all it does is an open(), then read(), then
+// close(), all of which are safe to call from signal handlers.
 void KillServerProcess(
     int pid, const string& output_base, const string& install_base) {
   string start_time;
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 461323a..b59a86b 100644
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -118,6 +118,7 @@
 void ReleaseLock(BlazeLock* blaze_lock);
 
 // Kills a server process based on its output base and PID.
+// This function can be called from a signal handler!
 void KillServerProcess(
     int pid, const string& output_base, const string& install_base);