Final Tweaks

This commit is contained in:
TheBrokenRail 2023-11-24 22:16:13 -05:00
parent c956151603
commit 48137f9665
8 changed files with 56 additions and 42 deletions

View File

@ -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()

View File

@ -10,6 +10,7 @@
#include <libreborn/libreborn.h>
#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

View File

@ -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[]);

View File

@ -9,6 +9,7 @@
#include <libreborn/libreborn.h>
#include "../util.h"
#include "../bootstrap.h"
#include "launcher.h"
#include "cache.h"

39
launcher/src/util.c Normal file
View File

@ -0,0 +1,39 @@
#include <libreborn/libreborn.h>
#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;
}

14
launcher/src/util.h Normal file
View File

@ -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

View File

@ -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) "

View File

@ -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