2021-06-17 17:32:24 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2022-03-14 19:09:25 -04:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
2022-05-15 13:51:28 -04:00
|
|
|
#include <signal.h>
|
2021-06-17 17:32:24 -04:00
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2022-03-14 19:09:25 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-07-20 02:58:14 -04:00
|
|
|
// Set Environmental Variable
|
|
|
|
void set_and_print_env(const char *name, const char *value);
|
|
|
|
|
2021-06-17 17:32:24 -04:00
|
|
|
// Safe execvpe()
|
2024-05-12 03:19:01 -04:00
|
|
|
#define MCPI_LD_VARIABLE_PREFIX "_MCPI_"
|
|
|
|
#define MCPI_ORIGINAL_LD_VARIABLE_PREFIX MCPI_LD_VARIABLE_PREFIX "ORIGINAL_"
|
|
|
|
#define MCPI_ORIGINAL_LD_VARIABLES_PRESERVED_ENV MCPI_ORIGINAL_LD_VARIABLE_PREFIX "PRESERVED"
|
2022-07-20 02:58:14 -04:00
|
|
|
#define for_each_special_environmental_variable(handle) \
|
|
|
|
handle("LD_LIBRARY_PATH"); \
|
2024-05-12 03:19:01 -04:00
|
|
|
handle("LD_PRELOAD")
|
2022-07-20 02:58:14 -04:00
|
|
|
void setup_exec_environment(int is_arm_component);
|
2022-03-14 19:09:25 -04:00
|
|
|
__attribute__((noreturn)) void safe_execvpe(const char *const argv[], const char *const envp[]);
|
2022-03-09 18:47:31 -05:00
|
|
|
|
2022-09-22 17:43:21 -04:00
|
|
|
// Debug Tag
|
|
|
|
#define CHILD_PROCESS_TAG "(Child Process) "
|
|
|
|
|
2022-03-14 19:09:25 -04:00
|
|
|
// Run Command And Get Output
|
2023-11-11 00:44:26 -05:00
|
|
|
char *run_command(const char *const command[], int *exit_status, size_t *output_size);
|
2022-05-15 13:51:28 -04:00
|
|
|
#define is_exit_status_success(status) (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
|
|
|
|
|
|
|
// Get Exit Status String
|
|
|
|
void get_exit_status_string(int status, char **out);
|
2022-03-14 19:09:25 -04:00
|
|
|
|
2022-05-13 22:36:12 -04:00
|
|
|
// Track Children
|
|
|
|
void track_child(pid_t pid);
|
|
|
|
void untrack_child(pid_t pid);
|
|
|
|
void murder_children();
|
|
|
|
|
2022-03-14 19:09:25 -04:00
|
|
|
#ifdef __cplusplus
|
2022-03-09 18:47:31 -05:00
|
|
|
}
|
2022-03-14 19:09:25 -04:00
|
|
|
#endif
|