| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d7d8819 commit 7bd4f72
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ cc_binary( | |||
| 4 | 4 | name = "daemonize", | |
| 5 | 5 | srcs = ["daemonize.cc"], | |
| 6 | 6 | deps = [ | |
| 7 | + ":logging", | ||
| 7 | 8 | ":process-tools", | |
| 8 | 9 | ], | |
| 9 | 10 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ | |||
| 49 | 49 | #include <sys/types.h> | |
| 50 | 50 | #include <unistd.h> | |
| 51 | 51 | ||
| 52 | + #include "src/main/tools/logging.h" | ||
| 52 | 53 | #include "src/main/tools/process-tools.h" | |
| 53 | 54 | ||
| 54 | 55 | // 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) { | |||
| 80 | 81 | err(EXIT_FAILURE, "dup failed"); | |
| 81 | 82 | } | |
| 82 | 83 | assert(fd == STDERR_FILENO); | |
| 84 | + | ||
| 85 | + global_debug = stderr; | ||
| 83 | 86 | } | |
| 84 | 87 | ||
| 85 | 88 | // 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) { | |||
| 324 | 327 | strcmp(fs_vfstype, "cgroup2") == 0) { | |
| 325 | 328 | char* procs_path; | |
| 326 | 329 | 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 | + } | ||
| 328 | 344 | free(procs_path); | |
| 329 | 345 | } | |
| 330 | 346 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments