From 77d7b82a14b00e4d57f7b7c47117da80ce4ba6e6 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 13 May 2022 22:36:12 -0400 Subject: [PATCH] Add Crash Report Dialog --- dependencies/zenity/src | 2 +- launcher/CMakeLists.txt | 2 +- launcher/src/bootstrap.c | 32 +++- launcher/src/client/launcher.cpp | 3 +- launcher/src/crash-report.c | 213 +++++++++++++++++++++++ launcher/src/crash-report.h | 11 ++ launcher/src/patchelf.c | 2 +- libreborn/CMakeLists.txt | 4 +- libreborn/include/libreborn/exec.h | 6 + libreborn/include/libreborn/log.h | 20 +-- libreborn/src/patch/patch.c | 4 +- libreborn/src/util/exec.c | 41 ++++- libreborn/src/util/log.c | 16 -- media-layer/core/src/media.c | 4 +- media-layer/extras/src/SDL.c | 5 +- media-layer/include/SDL/SDL.h | 2 +- media-layer/proxy/src/client/client.cpp | 26 ++- media-layer/proxy/src/media-layer-core.c | 9 +- media-layer/proxy/src/server/server.cpp | 1 + mods/src/compat/compat.c | 14 +- 20 files changed, 360 insertions(+), 57 deletions(-) create mode 100644 launcher/src/crash-report.c create mode 100644 launcher/src/crash-report.h delete mode 100644 libreborn/src/util/log.c diff --git a/dependencies/zenity/src b/dependencies/zenity/src index 3dbcdbb3..775bea89 160000 --- a/dependencies/zenity/src +++ b/dependencies/zenity/src @@ -1 +1 @@ -Subproject commit 3dbcdbb34a0c92297155de48ed491ea3e587b208 +Subproject commit 775bea8911f27848d1359ae656cf074dc0a07396 diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index f1779fb9..210e9c19 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -2,7 +2,7 @@ project(launcher) # Launcher if(BUILD_NATIVE_COMPONENTS) - add_executable(launcher src/bootstrap.c src/patchelf.c) + add_executable(launcher src/bootstrap.c src/patchelf.c src/crash-report.c) if(MCPI_SERVER_MODE) target_sources(launcher PRIVATE src/server/launcher.c) else() diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index bd82051c..96deb4b2 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -12,6 +12,7 @@ #include "bootstrap.h" #include "patchelf.h" +#include "crash-report.h" // Set Environmental Variable #define PRESERVE_ENVIRONMENTAL_VARIABLE(name) \ @@ -139,6 +140,14 @@ static void load(char **ld_preload, char *folder) { #define MCPI_BINARY "minecraft-pi" #define QEMU_BINARY "qemu-arm" +// Exit Handler +static void exit_handler(__attribute__((unused)) int signal_id) { + // Pass Signal To Child + murder_children(); + while (wait(NULL) > 0) {} + _exit(EXIT_SUCCESS); +} + // Pre-Bootstrap void pre_bootstrap() { // GTK Dark Mode @@ -148,9 +157,11 @@ void pre_bootstrap() { // AppImage #ifdef MCPI_IS_APPIMAGE_BUILD - char *owd = getenv("OWD"); - if (owd != NULL && chdir(owd) != 0) { - ERR("AppImage: Unable To Fix Current Directory: %s", strerror(errno)); + { + char *owd = getenv("OWD"); + if (owd != NULL && chdir(owd) != 0) { + ERR("AppImage: Unable To Fix Current Directory: %s", strerror(errno)); + } } #endif @@ -176,6 +187,21 @@ void pre_bootstrap() { // Free Binary Directory free(binary_directory); + + // Setup Crash Reports + setup_crash_report(); + + // Install Signal Handlers + struct sigaction act_sigint; + memset((void *) &act_sigint, 0, sizeof (struct sigaction)); + act_sigint.sa_flags = SA_RESTART; + act_sigint.sa_handler = &exit_handler; + sigaction(SIGINT, &act_sigint, NULL); + struct sigaction act_sigterm; + memset((void *) &act_sigterm, 0, sizeof (struct sigaction)); + act_sigterm.sa_flags = SA_RESTART; + act_sigterm.sa_handler = &exit_handler; + sigaction(SIGTERM, &act_sigterm, NULL); } // Bootstrap diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index 405c3e68..18b13f77 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -99,7 +99,8 @@ static void run_command_and_set_env(const char *env_name, const char *command[]) } // Check Return Code if (return_code != 0) { - ERR("Launch Interrupted"); + INFO("Launch Interrupted"); + exit(EXIT_SUCCESS); } } } diff --git a/launcher/src/crash-report.c b/launcher/src/crash-report.c new file mode 100644 index 00000000..29423b5e --- /dev/null +++ b/launcher/src/crash-report.c @@ -0,0 +1,213 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "crash-report.h" + +// Show Crash Report Dialog +#ifndef MCPI_HEADLESS_MODE +#define DIALOG_TITLE "Crash Report" +#define CRASH_REPORT_DIALOG_WIDTH "640" +#define CRASH_REPORT_DIALOG_HEIGHT "480" +static void show_report(const char *log_filename) { + const char *command[] = { + "zenity", + "--title", DIALOG_TITLE, + "--class", GUI_TITLE, + "--width", CRASH_REPORT_DIALOG_WIDTH, + "--height", CRASH_REPORT_DIALOG_HEIGHT, + "--text-info", + "--text", "Minecraft: Pi Edition: Reborn has crashed!", + "--filename", log_filename, + "--no-wrap", + "--font", "Monospace", + NULL + }; + free(run_command(command, NULL)); +} +#endif + +// Exit Handler +static void exit_handler(__attribute__((unused)) int signal) { + // Murder + murder_children(); +} + +// Setup +void setup_crash_report() { + // Store Output +#ifndef MCPI_HEADLESS_MODE + int output_pipe[2]; + safe_pipe2(output_pipe, 0); + int error_pipe[2]; + safe_pipe2(error_pipe, 0); +#endif + + // Fork + pid_t ret = fork(); + if (ret == -1) { + ERR("Unable To Fork: %s", strerror(errno)); + } else if (ret == 0) { + // Child Process + + // Pipe stdio +#ifndef MCPI_HEADLESS_MODE + dup2(output_pipe[1], STDOUT_FILENO); + close(output_pipe[0]); + close(output_pipe[1]); + dup2(error_pipe[1], STDERR_FILENO); + close(error_pipe[0]); + close(error_pipe[1]); +#endif + + // Create New Process Group + setpgid(0, 0); + + // Continue Execution + } else { + // Parent Process + track_child(ret); + + // Install Signal Handlers + struct sigaction act_sigint; + memset((void *) &act_sigint, 0, sizeof (struct sigaction)); + act_sigint.sa_flags = SA_RESTART; + act_sigint.sa_handler = &exit_handler; + sigaction(SIGINT, &act_sigint, NULL); + struct sigaction act_sigterm; + memset((void *) &act_sigterm, 0, sizeof (struct sigaction)); + act_sigterm.sa_flags = SA_RESTART; + act_sigterm.sa_handler = &exit_handler; + sigaction(SIGTERM, &act_sigterm, NULL); + + // Capture stdio +#ifndef MCPI_HEADLESS_MODE + // Close Unneeded File Descriptors + close(output_pipe[1]); + close(error_pipe[1]); + + // Create A Buffer +#define BUFFER_SIZE 1024 + char buf[BUFFER_SIZE]; + + // Create Temporary File + char log_filename[] = "/tmp/.minecraft-pi-log-XXXXXX"; + int log_file_fd = mkstemp(log_filename); + if (log_file_fd == -1) { + ERR("Unable To Create Log File: %s", strerror(errno)); + } + + // Setup Polling + int number_fds = 2; + struct pollfd poll_fds[number_fds]; + poll_fds[0].fd = output_pipe[0]; + poll_fds[1].fd = error_pipe[0]; + for (int i = 0; i < number_fds; i++) { + poll_fds[i].events = POLLIN; + } + + // Poll Data + int number_open_fds = number_fds; + while (number_open_fds > 0) { + int poll_ret = poll(poll_fds, number_fds, -1); + if (poll_ret == -1) { + if (errno == EINTR) { + continue; + } else { + ERR("Unable To Poll Data: %s", strerror(errno)); + } + } + + // Handle Data + for (int i = 0; i < number_fds; i++) { + if (poll_fds[i].revents != 0) { + if (poll_fds[i].revents & POLLIN) { + // Data Available + ssize_t bytes_read = read(poll_fds[i].fd, (void *) buf, BUFFER_SIZE - 1 /* Account For NULL-Terminator */); + if (bytes_read == -1) { + ERR("Unable To Read Log Data: %s", strerror(errno)); + } + + // Print To Terminal + buf[bytes_read] = '\0'; + fprintf(i == 0 ? stdout : stderr, "%s", buf); + + // Write To log + if (write(log_file_fd, (void *) buf, bytes_read) == -1) { + ERR("Unable To Write Log Data: %s", strerror(errno)); + } + } else { + // File Descriptor No Longer Accessible + if (close(poll_fds[i].fd) == -1) { + ERR("Unable To Close File Descriptor: %s", strerror(errno)); + } + number_open_fds--; + } + } + } + } +#endif + + // Get Return Code + int status; + waitpid(ret, &status, 0); + untrack_child(ret); + + // Check If Is Crash + int is_crash = WIFEXITED(status) ? WEXITSTATUS(status) != 0 : 1; + + // Log Exit Code To log If Crash + if (is_crash) { + // Create Exit Code Log Line + char *exit_code_line = NULL; + if (WIFEXITED(status)) { + safe_asprintf(&exit_code_line, "[CRASH]: Terminated: Exit Code: %i\n", WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + safe_asprintf(&exit_code_line, "[CRASH]: Terminated: Signal: %i%s\n", WTERMSIG(status), WCOREDUMP(status) ? " (Core Dumped)" : ""); + } else { + safe_asprintf(&exit_code_line, "[CRASH]: Terminated\n"); + } + + // Print Exit Code Log Line + fprintf(stderr, "%s", exit_code_line); + + // Write Exit Code Log Line +#ifndef MCPI_HEADLESS_MODE + if (write(log_file_fd, (void *) exit_code_line, strlen(exit_code_line)) == -1) { + ERR("Unable To Write Exit Code To Log: %s", strerror(errno)); + } +#endif + + // Free Exit Code Log Line + free(exit_code_line); + } + + // Show Crash Log +#ifndef MCPI_HEADLESS_MODE + // Close Log File FD + if (close(log_file_fd) == -1) { + ERR("Unable To Close Log File Descriptor: %s", strerror(errno)); + } + + // Show Report + if (is_crash) { + show_report(log_filename); + } + + // Delete Log File + if (unlink(log_filename) == -1) { + ERR("Unable To Delete Log File: %s", strerror(errno)); + } +#endif + + // Exit + exit(WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE); + } +} diff --git a/launcher/src/crash-report.h b/launcher/src/crash-report.h new file mode 100644 index 00000000..4042a60d --- /dev/null +++ b/launcher/src/crash-report.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void setup_crash_report(); + +#ifdef __cplusplus +} +#endif diff --git a/launcher/src/patchelf.c b/launcher/src/patchelf.c index e56c55a1..946c661a 100644 --- a/launcher/src/patchelf.c +++ b/launcher/src/patchelf.c @@ -8,7 +8,7 @@ #include "patchelf.h" // Duplicate MCPI Executable Into /tmp -#define TMP_DIR "/tmp/.minecraft-pi-tmp" +#define TMP_DIR "/tmp/.minecraft-pi-patched" static void duplicate_mcpi_executable() { // Get Original Path const char *original_path = getenv("MCPI_EXECUTABLE_PATH"); diff --git a/libreborn/CMakeLists.txt b/libreborn/CMakeLists.txt index 63debc81..5d2258b8 100644 --- a/libreborn/CMakeLists.txt +++ b/libreborn/CMakeLists.txt @@ -1,11 +1,11 @@ project(libreborn) -add_library(reborn-util STATIC src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c src/util/log.c) +add_library(reborn-util STATIC src/util/elf.c src/util/exec.c src/util/string.c src/util/util.c) target_include_directories(reborn-util PUBLIC include) if(BUILD_ARM_COMPONENTS) add_library(reborn-patch SHARED src/patch/patch.c) - target_link_libraries(reborn-patch dl reborn-util) + target_link_libraries(reborn-patch dl pthread reborn-util) target_compile_definitions(reborn-patch PUBLIC -DREBORN_HAS_PATCH_CODE) # Install install(TARGETS reborn-patch DESTINATION "${MCPI_LIB_DIR}") diff --git a/libreborn/include/libreborn/exec.h b/libreborn/include/libreborn/exec.h index 92795221..c43cd4e9 100644 --- a/libreborn/include/libreborn/exec.h +++ b/libreborn/include/libreborn/exec.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "log.h" #include "string.h" @@ -29,6 +30,11 @@ __attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const // Run Command And Get Output char *run_command(const char *const command[], int *return_code); +// Track Children +void track_child(pid_t pid); +void untrack_child(pid_t pid); +void murder_children(); + #ifdef __cplusplus } #endif diff --git a/libreborn/include/libreborn/log.h b/libreborn/include/libreborn/log.h index a57dc5b1..b850f3e2 100644 --- a/libreborn/include/libreborn/log.h +++ b/libreborn/include/libreborn/log.h @@ -3,23 +3,9 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - -// Colors -char *color_reset(); -char *color_yellow(); -char *color_faint(); -char *color_red(); - // Logging #define INFO(format, ...) { fprintf(stderr, "[INFO]: " format "\n", ##__VA_ARGS__); } -#define WARN(format, ...) { fprintf(stderr, "%s[WARN]: " format "%s\n", color_yellow(), ##__VA_ARGS__, color_reset()); } -#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL && strlen(debug) > 0) { fprintf(stderr, "%s[DEBUG]: " format "%s\n", color_faint(), ##__VA_ARGS__, color_reset()); } } -#define ERR(format, ...) { fprintf(stderr, "%s[ERR]: (%s:%i): " format "%s\n", color_red(), __FILE__, __LINE__, ##__VA_ARGS__, color_reset()); exit(EXIT_FAILURE); } +#define WARN(format, ...) { fprintf(stderr, "[WARN]: " format "\n", ##__VA_ARGS__); } +#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL && strlen(debug) > 0) { fprintf(stderr, "[DEBUG]: " format "\n", ##__VA_ARGS__); } } +#define ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); } #define IMPOSSIBLE() ERR("This Should Never Be Called") - -#ifdef __cplusplus -} -#endif diff --git a/libreborn/src/patch/patch.c b/libreborn/src/patch/patch.c index d738aa5a..e849958b 100644 --- a/libreborn/src/patch/patch.c +++ b/libreborn/src/patch/patch.c @@ -96,7 +96,9 @@ void _overwrite_call(const char *file, int line, void *start, void *target) { // Add New Target To Code Block update_code_block(target); - uint32_t new_instruction = generate_bl_instruction(start, code_block, 0); + // Patch + int use_b_instruction = ((unsigned char *) start)[3] == B_INSTRUCTION; + uint32_t new_instruction = generate_bl_instruction(start, code_block, use_b_instruction); _patch(file, line, start, (unsigned char *) &new_instruction); // Increment Code Block Position diff --git a/libreborn/src/util/exec.c b/libreborn/src/util/exec.c index 42f928b9..fd3d6516 100644 --- a/libreborn/src/util/exec.c +++ b/libreborn/src/util/exec.c @@ -1,3 +1,6 @@ +#include +#include + #include // Safe execvpe() @@ -86,13 +89,14 @@ char *run_command(const char *const command[], int *return_code) { safe_execvpe(command, (const char *const *) environ); } else { // Parent Process + track_child(ret); // Read stdout close(output_pipe[1]); char *output = NULL; #define BUFFER_SIZE 1024 char buf[BUFFER_SIZE]; - size_t bytes_read = 0; + ssize_t bytes_read = 0; while ((bytes_read = read(output_pipe[0], (void *) buf, BUFFER_SIZE - 1 /* Account For NULL-Terminator */)) > 0) { buf[bytes_read] = '\0'; string_append(&output, "%s", buf); @@ -102,6 +106,7 @@ char *run_command(const char *const command[], int *return_code) { // Get Return Code int status; waitpid(ret, &status, 0); + untrack_child(ret); if (return_code != NULL) { *return_code = WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; } @@ -110,3 +115,37 @@ char *run_command(const char *const command[], int *return_code) { return output; } } + + +// Track Children +#define MAX_CHILDREN 128 +static pid_t children[MAX_CHILDREN] = { 0 }; +static pthread_mutex_t children_lock = PTHREAD_MUTEX_INITIALIZER; +void track_child(pid_t pid) { + pthread_mutex_lock(&children_lock); + for (int i = 0; i < MAX_CHILDREN; i++) { + if (children[i] == 0) { + children[i] = pid; + break; + } + } + pthread_mutex_unlock(&children_lock); +} +void untrack_child(pid_t pid) { + pthread_mutex_lock(&children_lock); + for (int i = 0; i < MAX_CHILDREN; i++) { + if (children[i] == pid) { + children[i] = 0; + } + } + pthread_mutex_unlock(&children_lock); +} +void murder_children() { + pthread_mutex_lock(&children_lock); + for (int i = 0; i < MAX_CHILDREN; i++) { + if (children[i] != 0) { + kill(children[i], SIGTERM); + } + } + pthread_mutex_unlock(&children_lock); +} diff --git a/libreborn/src/util/log.c b/libreborn/src/util/log.c deleted file mode 100644 index b6a2dbcc..00000000 --- a/libreborn/src/util/log.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -#define COLOR(name, value) \ - char *color_##name() { \ - static char *out = NULL; \ - if (out == NULL) { \ - out = isatty(fileno(stderr)) ? "\x1b[" value "m" : ""; \ - } \ - return out; \ - } - -COLOR(reset, "0") -COLOR(yellow, "93") -COLOR(faint, "2") -COLOR(red, "91") diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 4536c5a8..2d367249 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -273,18 +273,20 @@ void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *ic glfwWindowHint(GLFW_AUTO_ICONIFY, GLFW_FALSE); glfwWindowHint(GLFW_ALPHA_BITS, 0); // Fix Transparent Window On Wayland + // Create Window glfw_window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, title, NULL, NULL); if (!glfw_window) { ERR("Unable To Create GLFW Window"); } - // Don't Process Events In Headless Mode + // Event Handlers glfwSetKeyCallback(glfw_window, glfw_key); glfwSetCharCallback(glfw_window, glfw_char); glfwSetCursorPosCallback(glfw_window, glfw_motion); glfwSetMouseButtonCallback(glfw_window, glfw_click); glfwSetScrollCallback(glfw_window, glfw_scroll); + // Make Window Context Current glfwMakeContextCurrent(glfw_window); // Init OpenAL diff --git a/media-layer/extras/src/SDL.c b/media-layer/extras/src/SDL.c index d24bb721..784e60f1 100644 --- a/media-layer/extras/src/SDL.c +++ b/media-layer/extras/src/SDL.c @@ -28,14 +28,15 @@ int SDL_GetWMInfo(SDL_SysWMinfo *info) { } // Quit -__attribute__ ((noreturn)) void SDL_Quit() { +void SDL_Quit() { // Cleanup Media Layer media_cleanup(); // Wait For Children To Stop + signal(SIGCHLD, SIG_IGN); + murder_children(); while (wait(NULL) > 0) {} // Exit INFO("Stopped"); - exit(EXIT_SUCCESS); } diff --git a/media-layer/include/SDL/SDL.h b/media-layer/include/SDL/SDL.h index 23d572b3..38ccbd1d 100644 --- a/media-layer/include/SDL/SDL.h +++ b/media-layer/include/SDL/SDL.h @@ -32,7 +32,7 @@ int SDL_ShowCursor(int toggle); void *SDL_SetVideoMode(int width, int height, int bpp, uint32_t flags); int SDL_GetWMInfo(SDL_SysWMinfo *info); -__attribute__((noreturn)) void SDL_Quit(); +void SDL_Quit(); #ifdef __cplusplus } diff --git a/media-layer/proxy/src/client/client.cpp b/media-layer/proxy/src/client/client.cpp index 88c03005..15f1974b 100644 --- a/media-layer/proxy/src/client/client.cpp +++ b/media-layer/proxy/src/client/client.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "../common/common.h" @@ -37,15 +38,29 @@ void _check_proxy_state() { } } +// Exit Handler +static volatile int exit_requested = 0; +static void exit_handler(__attribute__((unused)) int signal_id) { + // Request Exit + exit_requested = 1; +} + // Main int main(int argc, char *argv[]) { - // Ignore SIGINT, Send Signal To Parent - signal(SIGINT, SIG_IGN); + // Install Signal Handlers + struct sigaction act_sigint; + memset((void *) &act_sigint, 0, sizeof (struct sigaction)); + act_sigint.sa_handler = &exit_handler; + sigaction(SIGINT, &act_sigint, NULL); + struct sigaction act_sigterm; + memset((void *) &act_sigterm, 0, sizeof (struct sigaction)); + act_sigterm.sa_handler = &exit_handler; + sigaction(SIGTERM, &act_sigterm, NULL); // Send Signal On Parent Death To Interrupt Connection Read/Write And Exit prctl(PR_SET_PDEATHSIG, SIGUSR1); struct sigaction sa; - sigemptyset(&sa.sa_mask); + memset((void *) &sa, 0, sizeof (struct sigaction)); sa.sa_flags = SA_NOCLDSTOP; sa.sa_handler = &sigusr1_handler; if (sigaction(SIGUSR1, &sa, NULL) == -1) { @@ -67,7 +82,7 @@ int main(int argc, char *argv[]) { // Loop int running = is_connection_open(); - while (running) { + while (running && !exit_requested) { unsigned char unique_id = read_byte(); if (get_handlers().size() > unique_id && get_handlers()[unique_id] != NULL) { // Run Method @@ -84,6 +99,9 @@ int main(int argc, char *argv[]) { PROXY_ERR("Invalid Method ID: %i", (int) unique_id); } } + if (is_connection_open()) { + close_connection(); + } // Exit PROXY_INFO("Stopped"); diff --git a/media-layer/proxy/src/media-layer-core.c b/media-layer/proxy/src/media-layer-core.c index b6458c63..dfc4cdd6 100644 --- a/media-layer/proxy/src/media-layer-core.c +++ b/media-layer/proxy/src/media-layer-core.c @@ -214,16 +214,21 @@ CALL(9, media_cleanup, void, ()) { if (is_connection_open()) { // Lock Proxy start_proxy_call(); + // Block Until Cleanup Is Complete + flush_write_cache(); + read_byte(); // Close The Connection close_connection(); // Release Proxy end_proxy_call(); } #else - // Close The Connection - close_connection(); // Run media_cleanup(); + // Confirm Cleanup + write_byte(0); + // Close The Connection + close_connection(); #endif } diff --git a/media-layer/proxy/src/server/server.cpp b/media-layer/proxy/src/server/server.cpp index 0de049c8..c4f28249 100644 --- a/media-layer/proxy/src/server/server.cpp +++ b/media-layer/proxy/src/server/server.cpp @@ -84,6 +84,7 @@ static void start_media_layer_proxy_client(int read, int write) { } else { // Parent Process _client_pid = ret; + track_child(_client_pid); } update_client_state(1, 0); } diff --git a/mods/src/compat/compat.c b/mods/src/compat/compat.c index 1f75fffd..50e0e9c8 100644 --- a/mods/src/compat/compat.c +++ b/mods/src/compat/compat.c @@ -116,9 +116,17 @@ static void exit_handler(__attribute__((unused)) int data) { compat_request_exit(); } void init_compat() { - // Install Exit Handler - signal(SIGINT, exit_handler); - signal(SIGTERM, exit_handler); + // Install Signal Handlers + struct sigaction act_sigint; + memset((void *) &act_sigint, 0, sizeof (struct sigaction)); + act_sigint.sa_flags = SA_RESTART; + act_sigint.sa_handler = &exit_handler; + sigaction(SIGINT, &act_sigint, NULL); + struct sigaction act_sigterm; + memset((void *) &act_sigterm, 0, sizeof (struct sigaction)); + act_sigterm.sa_flags = SA_RESTART; + act_sigterm.sa_handler = &exit_handler; + sigaction(SIGTERM, &act_sigterm, NULL); } // Cleanup Temporary Files