diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index f56f8643..99386cff 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 8cc1a2fc..b5cc9313 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 27a7950a..6afe6372 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 2f303dd2..55457c71 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 00000000..abc7b56d --- /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 00000000..19d4706b --- /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 8921174a..a4656ea9 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 a07d3f8e..b3cb2f0c 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