FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Do not fail if cgroups cannot be written · codemod/bazel-java@7bd4f72 · GitHub

Repository navigation

Commit 7bd4f72

Browse files
authored andcommitted
Do not fail if cgroups cannot be written
From comment bazelbuild#21618 (comment): as per documentation > It is not an error if the specified cgroup is not writable for one or more of the controllers However WriteFile will fail if the file cannot be written, so it cannot be used in this context Closes bazelbuild#23540. PiperOrigin-RevId: 751125468 Change-Id: Ie6c1b7fb3e3dbd5cbb25665345422e9e7d8df38c
1 parent d7d8819 commit 7bd4f72

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/main/tools/BUILD‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ cc_binary(
44
name = "daemonize",
55
srcs = ["daemonize.cc"],
66
deps = [
7+
":logging",
78
":process-tools",
89
],
910
)

‎src/main/tools/daemonize.cc‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <sys/types.h>
5050
#include <unistd.h>
5151

52+
#include "src/main/tools/logging.h"
5253
#include "src/main/tools/process-tools.h"
5354

5455
// Configures std{in,out,err} of the current process to serve as a daemon.
@@ -80,6 +81,8 @@ static void SetupStdio(const char* log_path, bool log_append) {
8081
err(EXIT_FAILURE, "dup failed");
8182
}
8283
assert(fd == STDERR_FILENO);
84+
85+
global_debug = stderr;
8386
}
8487

8588
// Writes the given pid to a new file at pid_path.
@@ -324,7 +327,20 @@ static void MoveToCgroup(pid_t pid, const char* cgroup_path) {
324327
strcmp(fs_vfstype, "cgroup2") == 0) {
325328
char* procs_path;
326329
asprintf(&procs_path, "%s%s/cgroup.procs", fs_file, cgroup_path);
327-
WriteFile(procs_path, "%d", pid);
330+
FILE* procs = fopen(procs_path, "w");
331+
if (procs == NULL) {
332+
PRINT_DEBUG(
333+
"Failed to open %s. Falling back to running without cgroups",
334+
procs_path);
335+
} else if (fprintf(procs, "%d", pid) < 0) {
336+
PRINT_DEBUG(
337+
"Failed to write %s. Falling back to running without cgroups",
338+
procs_path);
339+
} else if (fclose(procs) < 0) {
340+
PRINT_DEBUG(
341+
"Failed to close %s. Falling back to running without cgroups",
342+
procs_path);
343+
}
328344
free(procs_path);
329345
}
330346
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL