From 48137f9665558031b05ae268f2dcc8eae2402551 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 24 Nov 2023 22:16:13 -0500 Subject: [PATCH] Final Tweaks --- launcher/CMakeLists.txt | 2 +- launcher/src/bootstrap.c | 11 +-------- launcher/src/bootstrap.h | 2 -- launcher/src/client/launcher.cpp | 1 + launcher/src/util.c | 39 ++++++++++++++++++++++++++++++ launcher/src/util.h | 14 +++++++++++ libreborn/include/libreborn/exec.h | 5 ---- libreborn/src/util/exec.c | 24 ------------------ 8 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 launcher/src/util.c create mode 100644 launcher/src/util.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index f56f864..99386cf 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1,7 +1,7 @@ project(launcher) # Launcher -add_executable(launcher src/bootstrap.c src/patchelf.cpp src/crash-report.c) +add_executable(launcher src/bootstrap.c src/patchelf.cpp src/util.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 8cc1a2f..b5cc931 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -10,6 +10,7 @@ #include +#include "util.h" #include "bootstrap.h" #include "patchelf.h" #include "crash-report.h" @@ -242,16 +243,6 @@ void pre_bootstrap(int argc, char *argv[]) { } // Copy SDK Into ~/.minecraft-pi -void run_simple_command(const char *const command[], const char *error) { - int status = 0; - char *output = run_command(command, &status, NULL); - if (output != NULL) { - free(output); - } - if (!is_exit_status_success(status)) { - ERR("%s", error); - } -} #define HOME_SUBDIRECTORY_FOR_SDK HOME_SUBDIRECTORY_FOR_GAME_DATA "/sdk" static void copy_sdk(char *binary_directory) { // Ensure SDK Directory diff --git a/launcher/src/bootstrap.h b/launcher/src/bootstrap.h index 27a7950..6afe637 100644 --- a/launcher/src/bootstrap.h +++ b/launcher/src/bootstrap.h @@ -4,8 +4,6 @@ extern "C" { #endif -void run_simple_command(const char *const command[], const char *error); - void pre_bootstrap(int argc, char *argv[]); void bootstrap(int argc, char *argv[]); diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index 2f303dd..55457c7 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -9,6 +9,7 @@ #include +#include "../util.h" #include "../bootstrap.h" #include "launcher.h" #include "cache.h" diff --git a/launcher/src/util.c b/launcher/src/util.c new file mode 100644 index 0000000..abc7b56 --- /dev/null +++ b/launcher/src/util.c @@ -0,0 +1,39 @@ +#include + +#include "util.h" + +// Simpler Version Of run_command() +void run_simple_command(const char *const command[], const char *error) { + int status = 0; + char *output = run_command(command, &status, NULL); + if (output != NULL) { + free(output); + } + if (!is_exit_status_success(status)) { + ERR("%s", error); + } +} + +// Chop Off Last Component +void chop_last_component(char **str) { + size_t length = strlen(*str); + for (size_t i = 0; i < length; i++) { + size_t j = length - i - 1; + if ((*str)[j] == '/') { + (*str)[j] = '\0'; + break; + } + } +} +// Get Binary Directory (Remember To Free) +char *get_binary_directory() { + // Get Path To Current Executable + char *exe = realpath("/proc/self/exe", NULL); + ALLOC_CHECK(exe); + + // Chop Off Last Component + chop_last_component(&exe); + + // Return + return exe; +} diff --git a/launcher/src/util.h b/launcher/src/util.h new file mode 100644 index 0000000..19d4706 --- /dev/null +++ b/launcher/src/util.h @@ -0,0 +1,14 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +void run_simple_command(const char *const command[], const char *error); + +void chop_last_component(char **str); +char *get_binary_directory(); + +#ifdef __cplusplus +} +#endif diff --git a/libreborn/include/libreborn/exec.h b/libreborn/include/libreborn/exec.h index 8921174..a4656ea 100644 --- a/libreborn/include/libreborn/exec.h +++ b/libreborn/include/libreborn/exec.h @@ -26,11 +26,6 @@ void set_and_print_env(const char *name, const char *value); void setup_exec_environment(int is_arm_component); __attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]); -// Chop Off Last Component -void chop_last_component(char **str); -// Get Binary Directory (Remember To Free) -char *get_binary_directory(); - // Debug Tag #define CHILD_PROCESS_TAG "(Child Process) " diff --git a/libreborn/src/util/exec.c b/libreborn/src/util/exec.c index a07d3f8..b3cb2f0 100644 --- a/libreborn/src/util/exec.c +++ b/libreborn/src/util/exec.c @@ -43,30 +43,6 @@ __attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char } } -// Chop Off Last Component -void chop_last_component(char **str) { - size_t length = strlen(*str); - for (size_t i = 0; i < length; i++) { - size_t j = length - i - 1; - if ((*str)[j] == '/') { - (*str)[j] = '\0'; - break; - } - } -} -// Get Binary Directory (Remember To Free) -char *get_binary_directory() { - // Get Path To Current Executable - char *exe = realpath("/proc/self/exe", NULL); - ALLOC_CHECK(exe); - - // Chop Off Last Component - chop_last_component(&exe); - - // Return - return exe; -} - // Run Command And Get Output char *run_command(const char *const command[], int *exit_status, size_t *output_size) { // Store Output