Better Exit Code Messages
This commit is contained in:
parent
cb4560a602
commit
cf1faf4835
@ -98,7 +98,7 @@ static void run_command_and_set_env(const char *env_name, const char *command[])
|
|||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
// Check Return Code
|
// Check Return Code
|
||||||
if (return_code != 0) {
|
if (!is_exit_status_success(return_code)) {
|
||||||
INFO("Launch Interrupted");
|
INFO("Launch Interrupted");
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -161,19 +161,16 @@ void setup_crash_report() {
|
|||||||
untrack_child(ret);
|
untrack_child(ret);
|
||||||
|
|
||||||
// Check If Is Crash
|
// Check If Is Crash
|
||||||
int is_crash = WIFEXITED(status) ? WEXITSTATUS(status) != 0 : 1;
|
int is_crash = !is_exit_status_success(status);
|
||||||
|
|
||||||
// Log Exit Code To log If Crash
|
// Log Exit Code To log If Crash
|
||||||
if (is_crash) {
|
if (is_crash) {
|
||||||
// Create Exit Code Log Line
|
// Create Exit Code Log Line
|
||||||
|
char *exit_status = NULL;
|
||||||
|
get_exit_status_string(status, &exit_status);
|
||||||
char *exit_code_line = NULL;
|
char *exit_code_line = NULL;
|
||||||
if (WIFEXITED(status)) {
|
safe_asprintf(&exit_code_line, "[CRASH]: Terminated%s\n", exit_status);
|
||||||
safe_asprintf(&exit_code_line, "[CRASH]: Terminated: Exit Code: %i\n", WEXITSTATUS(status));
|
free(exit_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
|
// Print Exit Code Log Line
|
||||||
fprintf(stderr, "%s", exit_code_line);
|
fprintf(stderr, "%s", exit_code_line);
|
||||||
|
@ -103,8 +103,11 @@ void patch_mcpi_elf_dependencies(const char *linker) {
|
|||||||
} else {
|
} else {
|
||||||
return_code = patch_mcpi_elf_dependencies_with_extra_patchelf_args("--set-interpreter", linker);
|
return_code = patch_mcpi_elf_dependencies_with_extra_patchelf_args("--set-interpreter", linker);
|
||||||
}
|
}
|
||||||
if (return_code != 0) {
|
if (!is_exit_status_success(return_code)) {
|
||||||
ERR("patchelf Failed: Exit Code: %i", return_code);
|
char *exit_status_line = NULL;
|
||||||
|
get_exit_status_string(return_code, &exit_status_line);
|
||||||
|
ERR("patchelf Failed%s", exit_status_line);
|
||||||
|
free(exit_status_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix Permissions
|
// Fix Permissions
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
@ -28,7 +28,11 @@ char *get_binary_directory();
|
|||||||
__attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const argv[], const char *const envp[]);
|
__attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const argv[], const char *const envp[]);
|
||||||
|
|
||||||
// Run Command And Get Output
|
// Run Command And Get Output
|
||||||
char *run_command(const char *const command[], int *return_code);
|
char *run_command(const char *const command[], int *exit_status);
|
||||||
|
#define is_exit_status_success(status) (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||||
|
|
||||||
|
// Get Exit Status String
|
||||||
|
void get_exit_status_string(int status, char **out);
|
||||||
|
|
||||||
// Track Children
|
// Track Children
|
||||||
void track_child(pid_t pid);
|
void track_child(pid_t pid);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include <libreborn/exec.h>
|
#include <libreborn/exec.h>
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ __attribute__((noreturn)) void safe_execvpe_relative_to_binary(const char *const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run Command And Get Output
|
// Run Command And Get Output
|
||||||
char *run_command(const char *const command[], int *return_code) {
|
char *run_command(const char *const command[], int *exit_status) {
|
||||||
// Store Output
|
// Store Output
|
||||||
int output_pipe[2];
|
int output_pipe[2];
|
||||||
safe_pipe2(output_pipe, 0);
|
safe_pipe2(output_pipe, 0);
|
||||||
@ -99,8 +98,8 @@ char *run_command(const char *const command[], int *return_code) {
|
|||||||
int status;
|
int status;
|
||||||
waitpid(ret, &status, 0);
|
waitpid(ret, &status, 0);
|
||||||
untrack_child(ret);
|
untrack_child(ret);
|
||||||
if (return_code != NULL) {
|
if (exit_status != NULL) {
|
||||||
*return_code = WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
|
*exit_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
@ -108,6 +107,19 @@ char *run_command(const char *const command[], int *return_code) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Exit Status String
|
||||||
|
void get_exit_status_string(int status, char **out) {
|
||||||
|
if (out != NULL) {
|
||||||
|
*out =NULL;
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
safe_asprintf(out, ": Exit Code: %i", WEXITSTATUS(status));
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
safe_asprintf(out, ": Signal: %i%s", WTERMSIG(status), WCOREDUMP(status) ? " (Core Dumped)" : "");
|
||||||
|
} else {
|
||||||
|
safe_asprintf(out, ": Terminated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Track Children
|
// Track Children
|
||||||
#define MAX_CHILDREN 128
|
#define MAX_CHILDREN 128
|
||||||
|
@ -26,13 +26,9 @@ void _check_proxy_state() {
|
|||||||
// Check Client State
|
// Check Client State
|
||||||
if (!_client_is_alive) {
|
if (!_client_is_alive) {
|
||||||
void_write_cache(); // Child Is Dead, No Reason To Send A Dead Process Data
|
void_write_cache(); // Child Is Dead, No Reason To Send A Dead Process Data
|
||||||
if (WIFEXITED(_client_status)) {
|
char *exit_status = NULL;
|
||||||
PROXY_ERR("Client Terminated: Exit Code: %i", WEXITSTATUS(_client_status));
|
get_exit_status_string(_client_status, &exit_status);
|
||||||
} else if (WIFSIGNALED(_client_status)) {
|
PROXY_ERR("Client Terminated%s", exit_status);
|
||||||
PROXY_ERR("Client Terminated: Signal: %i%s", WTERMSIG(_client_status), WCOREDUMP(_client_status) ? " (Core Dumped)" : "");
|
|
||||||
} else {
|
|
||||||
PROXY_ERR("Client Terminated");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ static void *chat_thread(__attribute__((unused)) void *nop) {
|
|||||||
// Handle Message
|
// Handle Message
|
||||||
if (output != NULL) {
|
if (output != NULL) {
|
||||||
// Check Return Code
|
// Check Return Code
|
||||||
if (return_code == 0) {
|
if (is_exit_status_success(return_code)) {
|
||||||
// Remove Ending Newline
|
// Remove Ending Newline
|
||||||
int length = strlen(output);
|
int length = strlen(output);
|
||||||
if (output[length - 1] == '\n') {
|
if (output[length - 1] == '\n') {
|
||||||
|
@ -25,7 +25,7 @@ static char *run_command_proper(const char *command[], bool allow_empty) {
|
|||||||
// Handle Message
|
// Handle Message
|
||||||
if (output != NULL) {
|
if (output != NULL) {
|
||||||
// Check Return Code
|
// Check Return Code
|
||||||
if (return_code == 0) {
|
if (is_exit_status_success(return_code)) {
|
||||||
// Remove Ending Newline
|
// Remove Ending Newline
|
||||||
int length = strlen(output);
|
int length = strlen(output);
|
||||||
if (output[length - 1] == '\n') {
|
if (output[length - 1] == '\n') {
|
||||||
@ -42,7 +42,7 @@ static char *run_command_proper(const char *command[], bool allow_empty) {
|
|||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
// Return
|
// Return
|
||||||
return return_code != 0 ? NULL : run_command_proper(command, allow_empty);
|
return !is_exit_status_success(return_code) ? NULL : run_command_proper(command, allow_empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track Create World State
|
// Track Create World State
|
||||||
|
Loading…
Reference in New Issue
Block a user