Allow bazel run on windows to handle Ctrl+C signals

Currently bazel run on windows prevents the process it's running from receiving Ctrl+C events.

This is because the windows implementation (unlike posix execv) runs the target as a subprocess of the bazel cli maintaining it's Ctrl+C interceptor which tries to interrupt the (no longer running) server instead of the spawned process (three times and then kills).

Not specifying CREATE_NEW_PROCESS_GROUP during CreateProcessW for this case resolves that issue. Potentially a de-register of the bazel cli Ctrl+C handler is desired since it still prints "Bazel Ctrl+C handler; shutting down.".

Closes #11144.

PiperOrigin-RevId: 310547476
diff --git a/src/main/native/windows/process.cc b/src/main/native/windows/process.cc
index 5f24c16..d6ee527 100644
--- a/src/main/native/windows/process.cc
+++ b/src/main/native/windows/process.cc
@@ -60,7 +60,7 @@
   // it works on all supported Windows versions.
   // Fixes https://github.com/bazelbuild/bazel/issues/8676
   return Create(argv0, argv_rest, env, wcwd, INVALID_HANDLE_VALUE,
-                INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, nullptr, true,
+                INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, nullptr, true, true,
                 error);
 }
 
@@ -71,7 +71,7 @@
                              LARGE_INTEGER* opt_out_start_time,
                              std::wstring* error) {
   return Create(argv0, argv_rest, env, wcwd, stdin_process, stdout_process,
-                stderr_process, opt_out_start_time, false, error);
+                stderr_process, opt_out_start_time, false, false, error);
 }
 
 bool WaitableProcess::Create(const std::wstring& argv0,
@@ -79,7 +79,8 @@
                              const std::wstring& wcwd, HANDLE stdin_process,
                              HANDLE stdout_process, HANDLE stderr_process,
                              LARGE_INTEGER* opt_out_start_time,
-                             bool create_window, std::wstring* error) {
+                             bool create_window, bool handle_signals,
+                             std::wstring* error) {
   std::wstring cwd;
   std::wstring error_msg(AsShortPath(wcwd, &cwd));
   if (!error_msg.empty()) {
@@ -177,7 +178,9 @@
           /* lpThreadAttributes */ NULL,
           /* bInheritHandles */ attr_list->InheritAnyHandles() ? TRUE : FALSE,
           /* dwCreationFlags */ (create_window ? 0 : CREATE_NO_WINDOW) |
-              CREATE_NEW_PROCESS_GROUP  // So that Ctrl-Break isn't propagated
+              (handle_signals ? 0
+                              : CREATE_NEW_PROCESS_GROUP)  // So that Ctrl-Break
+                                                           // isn't propagated
               | CREATE_SUSPENDED  // So that it doesn't start a new job itself
               | EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
           /* lpEnvironment */ env,
diff --git a/src/main/native/windows/process.h b/src/main/native/windows/process.h
index cceb780..45044ef 100644
--- a/src/main/native/windows/process.h
+++ b/src/main/native/windows/process.h
@@ -61,7 +61,7 @@
               void* env, const std::wstring& wcwd, HANDLE stdin_process,
               HANDLE stdout_process, HANDLE stderr_process,
               LARGE_INTEGER* opt_out_start_time, bool create_window,
-              std::wstring* error);
+              bool handle_signals, std::wstring* error);
 
   AutoHandle process_, job_, ioport_;
   DWORD pid_, exit_code_;