Skip to content

Commit c4f271d

Browse files
philwodslomov
authored andcommitted
Automated g4 rollback of commit 3e5edaf.
*** Reason for rollback *** Likely cause for b/38172480 ("blaze now waits for all processes spawned by local tests to terminate") and b/38194553 ("Server terminated abruptly (error code: 14, error message: 'Endpoint read failed'"). I have a fix almost ready, but it consists of many lines of new code - we shouldn't rush that into Bazel's 0.5.0 release. Instead, let's roll this back, do a release using the known good older process-wrapper and then go forward in 0.5.1 with a better and well tested new version of this. *** Original change description *** process-wrapper: Wait for all (grand)children before exiting. This uses Linux's PR_SET_CHILD_SUBREAPER and FreeBSD's PROC_REAP_ACQUIRE features to become an init-like process for all (grand)children spawned by process-wrapper, which allows us to a) kill them reliably and then b) wait for them reliably. Before this change, we only killed the main child, waited for it, then fired off a kill -9 on the process group, without waiting for it. This led to a race condition where Bazel would try to use... *** PiperOrigin-RevId: 156068188
1 parent 48034fd commit c4f271d

9 files changed

Lines changed: 641 additions & 379 deletions

File tree

src/main/tools/BUILD

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
package(default_visibility = ["//src:__subpackages__"])
22

3-
cc_library(
4-
name = "process-tools",
5-
srcs = [
6-
"process-tools.cc",
7-
"process-tools.h",
8-
],
9-
)
10-
113
cc_binary(
124
name = "process-wrapper",
135
srcs = select({
146
"//src:windows_msvc": ["process-wrapper-windows.cc"],
157
"//conditions:default": [
16-
"process-wrapper.cc",
8+
"process-tools.c",
9+
"process-tools.h",
10+
"process-wrapper.c",
1711
],
1812
}),
19-
linkopts = ["-lm"],
20-
deps = select({
13+
copts = select({
2114
"//src:windows_msvc": [],
22-
"//conditions:default": [
23-
":process-tools",
24-
],
15+
"//conditions:default": ["-std=c99"],
2516
}),
17+
linkopts = ["-lm"],
2618
)
2719

2820
cc_binary(
@@ -53,17 +45,6 @@ cc_binary(
5345
],
5446
}),
5547
linkopts = ["-lm"],
56-
deps = select({
57-
"//src:darwin": [],
58-
"//src:darwin_x86_64": [],
59-
"//src:freebsd": [],
60-
"//src:windows": [],
61-
"//src:windows_msys": [],
62-
"//src:windows_msvc": [],
63-
"//conditions:default": [
64-
":process-tools",
65-
],
66-
}),
6748
)
6849

6950
filegroup(

src/main/tools/linux-sandbox-options.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "src/main/tools/linux-sandbox-options.h"
15+
#include "linux-sandbox-options.h"
16+
#include "linux-sandbox-utils.h"
1617

1718
#define DIE(args...) \
1819
{ \
1920
fprintf(stderr, __FILE__ ":" S__LINE__ ": \"" args); \
2021
fprintf(stderr, "\": "); \
21-
perror(nullptr); \
22+
perror(NULL); \
2223
exit(EXIT_FAILURE); \
2324
}
2425

@@ -38,8 +39,6 @@
3839
#include <string>
3940
#include <vector>
4041

41-
#include "src/main/tools/linux-sandbox-utils.h"
42-
4342
using std::ifstream;
4443
using std::unique_ptr;
4544
using std::vector;
@@ -200,7 +199,6 @@ static void ParseCommandLine(unique_ptr<vector<char *>> args) {
200199
if (optind < static_cast<int>(args->size())) {
201200
if (opt.args.empty()) {
202201
opt.args.assign(args->begin() + optind, args->end());
203-
opt.args.push_back(nullptr);
204202
} else {
205203
Usage(args->front(), "Merging commands not supported.");
206204
}
@@ -209,8 +207,8 @@ static void ParseCommandLine(unique_ptr<vector<char *>> args) {
209207

210208
// Expands a single argument, expanding options @filename to read in the content
211209
// of the file and add it to the list of processed arguments.
212-
static unique_ptr<vector<char *>> ExpandArgument(
213-
unique_ptr<vector<char *>> expanded, char *arg) {
210+
unique_ptr<vector<char *>> ExpandArgument(unique_ptr<vector<char *>> expanded,
211+
char *arg) {
214212
if (arg[0] == '@') {
215213
const char *filename = arg + 1; // strip off the '@'.
216214
ifstream f(filename);
@@ -238,7 +236,7 @@ static unique_ptr<vector<char *>> ExpandArgument(
238236
// Pre-processes an argument list, expanding options @filename to read in the
239237
// content of the file and add it to the list of arguments. Stops expanding
240238
// arguments once it encounters "--".
241-
static unique_ptr<vector<char *>> ExpandArguments(const vector<char *> &args) {
239+
unique_ptr<vector<char *>> ExpandArguments(const vector<char *> &args) {
242240
unique_ptr<vector<char *>> expanded(new vector<char *>());
243241
expanded->reserve(args.size());
244242
for (auto arg = args.begin(); arg != args.end(); ++arg) {
@@ -262,6 +260,6 @@ void ParseOptions(int argc, char *argv[]) {
262260
}
263261

264262
if (opt.working_dir.empty()) {
265-
opt.working_dir = getcwd(nullptr, 0);
263+
opt.working_dir = getcwd(NULL, 0);
266264
}
267265
}

0 commit comments

Comments
 (0)