/* Generated by zi2c from process_run_linux.zi. */ #include #include "zir_bounds.h" #include "zir_string.h" #include "zir_vec.h" #define ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE 1 #include "process_run_linux.h" #undef ZIRAN_PROCESS_RUN_LINUX_H_PRIVATE #ifndef ZIRAN_HELPER_ZiShrS32 #define ZIRAN_HELPER_ZiShrS32 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__) #define ZiShrS32(a, s, w) __extension__ ({ int32_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); __zi_a < 0 ? ~(~__zi_a >> __zi_s) : __zi_a >> __zi_s; }) #else static inline int32_t ZiShrS32(int32_t a, uint64_t s, int w) { if(s >= (uint64_t)w) abort(); return a < 0 ? ~(~a >> s) : a >> s; } #endif #endif #include "c_string.h" #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ForkRaw_b09b1e28 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ForkRaw_b09b1e28 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_ForkRaw(void) __asm__("_fork"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_ForkRaw(void) __asm__("fork"); #endif static int32_t zir_f_eb6527159f8585fd_ForkRaw(void) { return zir_foreign_zir_f_eb6527159f8585fd_ForkRaw(); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_Pipe2Raw_7c968992 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("_pipe2"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) __asm__("pipe2"); #endif static int32_t zir_f_eb6527159f8585fd_Pipe2Raw(int32_t* fds, int32_t flags) { return zir_foreign_zir_f_eb6527159f8585fd_Pipe2Raw(fds, flags); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_DupRaw_8536fc2b #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_DupRaw_8536fc2b #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_DupRaw(int32_t source, int32_t destination) __asm__("_dup2"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_DupRaw(int32_t source, int32_t destination) __asm__("dup2"); #endif static int32_t zir_f_eb6527159f8585fd_DupRaw(int32_t source, int32_t destination) { return zir_foreign_zir_f_eb6527159f8585fd_DupRaw(source, destination); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_CloseRaw_d6ec0c1e #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_CloseRaw_d6ec0c1e #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_CloseRaw(int32_t fd) __asm__("_close"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_CloseRaw(int32_t fd) __asm__("close"); #endif static int32_t zir_f_eb6527159f8585fd_CloseRaw(int32_t fd) { return zir_foreign_zir_f_eb6527159f8585fd_CloseRaw(fd); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ReadRaw_bf7cf6fc #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ReadRaw_bf7cf6fc #ifdef __APPLE__ ptrdiff_t zir_foreign_zir_f_eb6527159f8585fd_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("_read"); #else ptrdiff_t zir_foreign_zir_f_eb6527159f8585fd_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("read"); #endif static ptrdiff_t zir_f_eb6527159f8585fd_ReadRaw(int32_t fd, uint8_t* output, size_t count) { return zir_foreign_zir_f_eb6527159f8585fd_ReadRaw(fd, output, count); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_WriteRaw_06f26813 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_WriteRaw_06f26813 #ifdef __APPLE__ ptrdiff_t zir_foreign_zir_f_eb6527159f8585fd_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("_write"); #else ptrdiff_t zir_foreign_zir_f_eb6527159f8585fd_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("write"); #endif static ptrdiff_t zir_f_eb6527159f8585fd_WriteRaw(int32_t fd, uint8_t* input, size_t count) { return zir_foreign_zir_f_eb6527159f8585fd_WriteRaw(fd, input, count); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_6d3762f4 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_OpenRaw_6d3762f4 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("_open"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) __asm__("open"); #endif static int32_t zir_f_eb6527159f8585fd_OpenRaw(uint8_t* path, int32_t flags, int32_t mode) { return zir_foreign_zir_f_eb6527159f8585fd_OpenRaw(path, flags, mode); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExecRaw_efd664fc #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExecRaw_efd664fc #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_ExecRaw(uint8_t* path, ProcessArgumentSlot* arguments) __asm__("_execvp"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_ExecRaw(uint8_t* path, ProcessArgumentSlot* arguments) __asm__("execvp"); #endif static int32_t zir_f_eb6527159f8585fd_ExecRaw(uint8_t* path, ProcessArgumentSlot* arguments) { return zir_foreign_zir_f_eb6527159f8585fd_ExecRaw(path, arguments); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExitRaw_da83199a #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ExitRaw_da83199a #ifdef __APPLE__ void zir_foreign_zir_f_eb6527159f8585fd_ExitRaw(int32_t code) __asm__("__exit"); #else void zir_foreign_zir_f_eb6527159f8585fd_ExitRaw(int32_t code) __asm__("_exit"); #endif static void zir_f_eb6527159f8585fd_ExitRaw(int32_t code) { zir_foreign_zir_f_eb6527159f8585fd_ExitRaw(code); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_WaitRaw_0257cbb4 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_WaitRaw_0257cbb4 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_WaitRaw(int32_t pid, int32_t* status, int32_t options) __asm__("_waitpid"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_WaitRaw(int32_t pid, int32_t* status, int32_t options) __asm__("waitpid"); #endif static int32_t zir_f_eb6527159f8585fd_WaitRaw(int32_t pid, int32_t* status, int32_t options) { return zir_foreign_zir_f_eb6527159f8585fd_WaitRaw(pid, status, options); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_KillRaw_34dcae82 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_KillRaw_34dcae82 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_KillRaw(int32_t pid, int32_t signal_number) __asm__("_kill"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_KillRaw(int32_t pid, int32_t signal_number) __asm__("kill"); #endif static int32_t zir_f_eb6527159f8585fd_KillRaw(int32_t pid, int32_t signal_number) { return zir_foreign_zir_f_eb6527159f8585fd_KillRaw(pid, signal_number); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ChangeDirectoryRaw_e9b0efc4 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ChangeDirectoryRaw_e9b0efc4 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_ChangeDirectoryRaw(uint8_t* path) __asm__("_chdir"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_ChangeDirectoryRaw(uint8_t* path) __asm__("chdir"); #endif static int32_t zir_f_eb6527159f8585fd_ChangeDirectoryRaw(uint8_t* path) { return zir_foreign_zir_f_eb6527159f8585fd_ChangeDirectoryRaw(path); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_SetEnvironmentRaw_24354f51 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_SetEnvironmentRaw_24354f51 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_SetEnvironmentRaw(uint8_t* name, uint8_t* value, int32_t overwrite) __asm__("_setenv"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_SetEnvironmentRaw(uint8_t* name, uint8_t* value, int32_t overwrite) __asm__("setenv"); #endif static int32_t zir_f_eb6527159f8585fd_SetEnvironmentRaw(uint8_t* name, uint8_t* value, int32_t overwrite) { return zir_foreign_zir_f_eb6527159f8585fd_SetEnvironmentRaw(name, value, overwrite); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_UnsetEnvironmentRaw_01c4c37c #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_UnsetEnvironmentRaw_01c4c37c #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_UnsetEnvironmentRaw(uint8_t* name) __asm__("_unsetenv"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_UnsetEnvironmentRaw(uint8_t* name) __asm__("unsetenv"); #endif static int32_t zir_f_eb6527159f8585fd_UnsetEnvironmentRaw(uint8_t* name) { return zir_foreign_zir_f_eb6527159f8585fd_UnsetEnvironmentRaw(name); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_SessionRaw_2cda1114 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_SessionRaw_2cda1114 #ifdef __APPLE__ int32_t zir_foreign_zir_f_eb6527159f8585fd_SessionRaw(void) __asm__("_setsid"); #else int32_t zir_foreign_zir_f_eb6527159f8585fd_SessionRaw(void) __asm__("setsid"); #endif static int32_t zir_f_eb6527159f8585fd_SessionRaw(void) { return zir_foreign_zir_f_eb6527159f8585fd_SessionRaw(); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_ErrnoRaw_40ae2072 #ifdef __APPLE__ int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("___errno_location"); #else int32_t* zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(void) __asm__("__errno_location"); #endif static int32_t* zir_f_eb6527159f8585fd_ErrnoRaw(void) { return zir_foreign_zir_f_eb6527159f8585fd_ErrnoRaw(); } #endif #ifndef ZIR_FOREIGN_zir_f_eb6527159f8585fd_SignalRaw_f23e3d88 #define ZIR_FOREIGN_zir_f_eb6527159f8585fd_SignalRaw_f23e3d88 #ifdef __APPLE__ SignalHandler zir_foreign_zir_f_eb6527159f8585fd_SignalRaw(int32_t signal_number, SignalHandler handler) __asm__("_signal"); #else SignalHandler zir_foreign_zir_f_eb6527159f8585fd_SignalRaw(int32_t signal_number, SignalHandler handler) __asm__("signal"); #endif static SignalHandler zir_f_eb6527159f8585fd_SignalRaw(int32_t signal_number, SignalHandler handler) { return zir_foreign_zir_f_eb6527159f8585fd_SignalRaw(signal_number, handler); } #endif #ifndef ZIRAN_MAYBE_UNUSED #if defined(__GNUC__) || defined(__clang__) #define ZIRAN_MAYBE_UNUSED __attribute__((unused)) #else #define ZIRAN_MAYBE_UNUSED #endif #endif static int64_t process_run_linux_Put(Prepared* prepared, String text) ZIRAN_MAYBE_UNUSED; static bool process_run_linux_Prepare(ProcessOptions options, Prepared* prepared) ZIRAN_MAYBE_UNUSED; static uint8_t* process_run_linux_At(Prepared* prepared, int64_t offset) ZIRAN_MAYBE_UNUSED; static void process_run_linux_Child(ProcessOptions options, Prepared* prepared, int32_t status, int32_t capture) ZIRAN_MAYBE_UNUSED; static void process_run_linux_Status(ProcessRun* run, int32_t status) ZIRAN_MAYBE_UNUSED; static int32_t process_run_linux_Start(ProcessOptions options, ProcessRun* run, bool capture) ZIRAN_MAYBE_UNUSED; static void process_run_linux_Terminate(int32_t signal_number) ZIRAN_MAYBE_UNUSED; static bool termination_requested = {0}; static int64_t process_run_linux_Put(Prepared* prepared, String text) { int64_t at = prepared->bytes.count; for (int64_t it_index = 0LL; it_index < (int64_t)(text).length; it_index++) { uint8_t it = (uint8_t)text.data[it_index]; if (it == 0) { return -1LL; } uint8_t value_0 = it; bool value_1 = false; void *value_2 = ZirVecGrow((void *)(prepared->bytes).data, &(prepared->bytes).capacity, (prepared->bytes).count, sizeof(*(prepared->bytes).data)); if (value_2 != NULL) { (prepared->bytes).data = (uint8_t *)value_2; (prepared->bytes).data[(prepared->bytes).count++] = value_0; value_1 = true; } (void)value_1; } uint8_t value_3 = 0; bool value_4 = false; void *value_5 = ZirVecGrow((void *)(prepared->bytes).data, &(prepared->bytes).capacity, (prepared->bytes).count, sizeof(*(prepared->bytes).data)); if (value_5 != NULL) { (prepared->bytes).data = (uint8_t *)value_5; (prepared->bytes).data[(prepared->bytes).count++] = value_3; value_4 = true; } (void)value_4; return at; } static bool process_run_linux_Prepare(ProcessOptions options, Prepared* prepared) { int64_t* value_0 = &(prepared->directory); (*value_0) = -1LL; int64_t* value_1 = &(prepared->input); (*value_1) = -1LL; int64_t* value_2 = &(prepared->output); (*value_2) = -1LL; int64_t* value_3 = &(prepared->error); (*value_3) = -1LL; bool value_4 = (int64_t)(options.arguments).length == 0LL; if (!value_4) { int64_t value_5 = (int64_t)(((String *)options.arguments.data)[SliceIndex(options.arguments, (int64_t)0)]).length; value_4 = (value_5 == 0LL); } if (value_4) { return false; } { Slice value_6 = options.arguments; Slice loop_view_7 = value_6; int64_t loop_count_7 = (int64_t)(loop_view_7).length; int64_t loop_cursor_7 = 0LL; while (loop_cursor_7 < loop_count_7) { int64_t loop_index_7 = loop_cursor_7; String it = ((String *)loop_view_7.data)[loop_index_7]; int64_t at = process_run_linux_Put(prepared, it); if (at < 0LL) { return false; } int64_t value_7 = at; bool value_8 = false; void *value_9 = ZirVecGrow((void *)(prepared->argument_offsets).data, &(prepared->argument_offsets).capacity, (prepared->argument_offsets).count, sizeof(*(prepared->argument_offsets).data)); if (value_9 != NULL) { (prepared->argument_offsets).data = (int64_t *)value_9; (prepared->argument_offsets).data[(prepared->argument_offsets).count++] = value_7; value_8 = true; } (void)value_8; loop_cursor_7 = (int64_t)((uint64_t)loop_cursor_7 + UINT64_C(1)); } } { Slice value_10 = options.environment; Slice loop_view_14 = value_10; int64_t loop_count_14 = (int64_t)(loop_view_14).length; int64_t loop_cursor_14 = 0LL; while (loop_cursor_14 < loop_count_14) { int64_t loop_index_14 = loop_cursor_14; String it = ((String *)loop_view_14.data)[loop_index_14]; int64_t equals = -1LL; int64_t index = 0LL; while (index < (int64_t)(it).length && equals < 0LL) { if ((uint8_t)it.data[index] == 61) { equals = index; } index = (int64_t)((uint64_t)index + UINT64_C(1)); } if (equals == 0LL) { return false; } String value_11 = StringView(NULL, 0); if (equals < 0LL) { value_11 = it; } else { value_11 = StringRange(it, (int64_t)0LL, (int64_t)equals); } String name = value_11; int64_t at = process_run_linux_Put(prepared, name); if (at < 0LL) { return false; } int64_t value_12 = at; bool value_13 = false; void *value_14 = ZirVecGrow((void *)(prepared->names).data, &(prepared->names).capacity, (prepared->names).count, sizeof(*(prepared->names).data)); if (value_14 != NULL) { (prepared->names).data = (int64_t *)value_14; (prepared->names).data[(prepared->names).count++] = value_12; value_13 = true; } (void)value_13; if (equals < 0LL) { int64_t value_15 = -1LL; bool value_16 = false; void *value_17 = ZirVecGrow((void *)(prepared->values).data, &(prepared->values).capacity, (prepared->values).count, sizeof(*(prepared->values).data)); if (value_17 != NULL) { (prepared->values).data = (int64_t *)value_17; (prepared->values).data[(prepared->values).count++] = value_15; value_16 = true; } (void)value_16; } else { int64_t value = process_run_linux_Put(prepared, StringRange(it, (int64_t)((int64_t)((uint64_t)equals + UINT64_C(1))), (int64_t)(int64_t)(it).length)); if (value < 0LL) { return false; } int64_t value_18 = value; bool value_19 = false; void *value_20 = ZirVecGrow((void *)(prepared->values).data, &(prepared->values).capacity, (prepared->values).count, sizeof(*(prepared->values).data)); if (value_20 != NULL) { (prepared->values).data = (int64_t *)value_20; (prepared->values).data[(prepared->values).count++] = value_18; value_19 = true; } (void)value_19; } loop_cursor_14 = (int64_t)((uint64_t)loop_cursor_14 + UINT64_C(1)); } } if ((int64_t)(options.directory).length > 0LL) { int64_t* value_21 = &(prepared->directory); int64_t value_22 = process_run_linux_Put(prepared, options.directory); (*value_21) = value_22; int64_t value_23 = prepared->directory; if (value_23 < 0LL) { return false; } } if ((int64_t)(options.input_path).length > 0LL) { int64_t* value_24 = &(prepared->input); int64_t value_25 = process_run_linux_Put(prepared, options.input_path); (*value_24) = value_25; int64_t value_26 = prepared->input; if (value_26 < 0LL) { return false; } } if ((int64_t)(options.output_path).length > 0LL) { int64_t* value_27 = &(prepared->output); int64_t value_28 = process_run_linux_Put(prepared, options.output_path); (*value_27) = value_28; int64_t value_29 = prepared->output; if (value_29 < 0LL) { return false; } } if ((int64_t)(options.error_path).length > 0LL) { int64_t* value_30 = &(prepared->error); int64_t value_31 = process_run_linux_Put(prepared, options.error_path); (*value_30) = value_31; int64_t value_32 = prepared->error; if (value_32 < 0LL) { return false; } } int64_t index = 0LL; while (true) { int64_t value_33 = prepared->argument_offsets.count; if (!(index < value_33)) { break; } uint8_t* value_34 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, ZIRAN_VEC_INDEX((prepared->argument_offsets).data, (prepared->argument_offsets).count, index))); ProcessArgumentSlot slot = {.value = value_34}; ProcessArgumentSlot value_35 = slot; bool value_36 = false; void *value_37 = ZirVecGrow((void *)(prepared->arguments).data, &(prepared->arguments).capacity, (prepared->arguments).count, sizeof(*(prepared->arguments).data)); if (value_37 != NULL) { (prepared->arguments).data = (ProcessArgumentSlot *)value_37; (prepared->arguments).data[(prepared->arguments).count++] = value_35; value_36 = true; } (void)value_36; index = (int64_t)((uint64_t)index + UINT64_C(1)); } ProcessArgumentSlot end = {.value = (void *)0}; ProcessArgumentSlot value_38 = end; bool value_39 = false; void *value_40 = ZirVecGrow((void *)(prepared->arguments).data, &(prepared->arguments).capacity, (prepared->arguments).count, sizeof(*(prepared->arguments).data)); if (value_40 != NULL) { (prepared->arguments).data = (ProcessArgumentSlot *)value_40; (prepared->arguments).data[(prepared->arguments).count++] = value_38; value_39 = true; } (void)value_39; return true; } static uint8_t* process_run_linux_At(Prepared* prepared, int64_t offset) { return &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } static void process_run_linux_Child(ProcessOptions options, Prepared* prepared, int32_t status, int32_t capture) { bool failed = false; if (options.new_session) { zir_f_eb6527159f8585fd_SessionRaw(); } int64_t value_0 = prepared->input; if (value_0 >= 0LL) { Prepared* value_1 = prepared; int64_t value_2 = prepared->input; uint8_t* value_3 = (void *)0; { Prepared* prepared = value_1; int64_t offset = value_2; value_3 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_3, 0, 0); bool value_5 = fd < 0; if (value_5 || zir_f_eb6527159f8585fd_DupRaw(fd, 0) < 0) { failed = true; } if (fd > 0) { zir_f_eb6527159f8585fd_CloseRaw(fd); } } if (!failed && capture >= 0) { if (zir_f_eb6527159f8585fd_DupRaw(capture, 1) < 0) { failed = true; } } else { bool value_6 = !failed; if (value_6) { int64_t value_7 = prepared->output; value_6 = (value_7 >= 0LL); } if (value_6) { int32_t value_8 = 0; if (options.append_output) { value_8 = 1089; } else { value_8 = 577; } int32_t flags = value_8; Prepared* value_9 = prepared; int64_t value_10 = prepared->output; uint8_t* value_11 = (void *)0; { Prepared* prepared = value_9; int64_t offset = value_10; value_11 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_11, (int32_t)((uint32_t)flags | 524288u), 420); bool value_13 = fd < 0; if (value_13 || zir_f_eb6527159f8585fd_DupRaw(fd, 1) < 0) { failed = true; } } } if (!failed && options.merge_error) { if (zir_f_eb6527159f8585fd_DupRaw(1, 2) < 0) { failed = true; } } else { bool value_14 = !failed; if (value_14) { int64_t value_15 = prepared->error; value_14 = (value_15 >= 0LL); } if (value_14) { Prepared* value_16 = prepared; int64_t value_17 = prepared->error; uint8_t* value_18 = (void *)0; { Prepared* prepared = value_16; int64_t offset = value_17; value_18 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } int32_t fd = zir_f_eb6527159f8585fd_OpenRaw(value_18, 524865, 420); bool value_20 = fd < 0; if (value_20 || zir_f_eb6527159f8585fd_DupRaw(fd, 2) < 0) { failed = true; } } } bool value_21 = !failed; if (value_21) { int64_t value_22 = prepared->directory; value_21 = (value_22 >= 0LL); } bool value_23 = value_21; bool value_24 = value_23; if (value_24) { Prepared* value_25 = prepared; int64_t value_26 = prepared->directory; uint8_t* value_27 = (void *)0; { Prepared* prepared = value_25; int64_t offset = value_26; value_27 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } bool value_29 = zir_f_eb6527159f8585fd_ChangeDirectoryRaw(value_27) != 0; value_24 = value_29; } if (value_24) { failed = true; } int64_t index = 0LL; while (true) { bool value_30 = !failed; if (value_30) { int64_t value_31 = prepared->names.count; value_30 = (index < value_31); } if (!value_30) { break; } Prepared* value_32 = prepared; int64_t value_33 = ZIRAN_VEC_INDEX((prepared->names).data, (prepared->names).count, index); uint8_t* value_34 = (void *)0; { Prepared* prepared = value_32; int64_t offset = value_33; value_34 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } uint8_t* name = value_34; int64_t value_36 = ZIRAN_VEC_INDEX((prepared->values).data, (prepared->values).count, index); if (value_36 < 0LL) { zir_f_eb6527159f8585fd_UnsetEnvironmentRaw(name); } else { uint8_t* value_37 = name; Prepared* value_38 = prepared; int64_t value_39 = ZIRAN_VEC_INDEX((prepared->values).data, (prepared->values).count, index); uint8_t* value_40 = (void *)0; { Prepared* prepared = value_38; int64_t offset = value_39; value_40 = &(ZIRAN_VEC_INDEX((prepared->bytes).data, (prepared->bytes).count, offset)); } if (zir_f_eb6527159f8585fd_SetEnvironmentRaw(value_37, value_40, 1) != 0) { failed = true; } } index = (int64_t)((uint64_t)index + UINT64_C(1)); } if (!failed) { zir_f_eb6527159f8585fd_ExecRaw((ZIRAN_VEC_INDEX((prepared->arguments).data, (prepared->arguments).count, 0)).value, &(ZIRAN_VEC_INDEX((prepared->arguments).data, (prepared->arguments).count, 0))); } int32_t* value_42 = zir_f_eb6527159f8585fd_ErrnoRaw(); int32_t error = *(value_42); zir_f_eb6527159f8585fd_WriteRaw(status, (uint8_t*)(&(error)), 4); zir_f_eb6527159f8585fd_ExitRaw(127); } static void process_run_linux_Status(ProcessRun* run, int32_t status) { bool* value_0 = &(run->finished); (*value_0) = true; if (((int32_t)((uint32_t)status & 127u)) != 0) { int32_t* value_1 = &(run->code); (*value_1) = (int32_t)(128u + ((uint32_t)status & 127u)); } else { int32_t* value_2 = &(run->code); (*value_2) = (int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u); } } static int32_t process_run_linux_Start(ProcessOptions options, ProcessRun* run, bool capture) { int32_t* value_0 = &(run->pid); (*value_0) = 0; int32_t* value_1 = &(run->code); (*value_1) = 127; bool* value_2 = &(run->started); (*value_2) = false; bool* value_3 = &(run->finished); (*value_3) = false; Prepared prepared = {0}; bool value_4 = process_run_linux_Prepare(options, &(prepared)); if (!value_4) { int32_t value_5 = -1; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_5; } int32_t status[2] = {0}; if (zir_f_eb6527159f8585fd_Pipe2Raw(&(status[0]), 524288) != 0) { int32_t value_6 = -1; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_6; } int32_t output[2] = {-1, -1}; if (capture && zir_f_eb6527159f8585fd_Pipe2Raw(&(output[0]), 524288) != 0) { zir_f_eb6527159f8585fd_CloseRaw((status)[0]); zir_f_eb6527159f8585fd_CloseRaw((status)[1]); int32_t value_7 = -1; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_7; } int32_t pid = zir_f_eb6527159f8585fd_ForkRaw(); if (pid == 0) { zir_f_eb6527159f8585fd_CloseRaw((status)[0]); if (capture) { zir_f_eb6527159f8585fd_CloseRaw((output)[0]); } process_run_linux_Child(options, &(prepared), (status)[1], (output)[1]); } zir_f_eb6527159f8585fd_CloseRaw((status)[1]); if (capture) { zir_f_eb6527159f8585fd_CloseRaw((output)[1]); } if (pid < 0) { zir_f_eb6527159f8585fd_CloseRaw((status)[0]); if (capture) { zir_f_eb6527159f8585fd_CloseRaw((output)[0]); } int32_t value_8 = -1; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_8; } int32_t* value_9 = &(run->pid); (*value_9) = pid; int32_t error = 0; int64_t count = -1LL; while (count < 0LL) { ptrdiff_t value_10 = zir_f_eb6527159f8585fd_ReadRaw((status)[0], (uint8_t*)(&(error)), 4); count = (int64_t)(value_10); bool value_11 = count < 0LL; if (value_11) { int32_t* value_12 = zir_f_eb6527159f8585fd_ErrnoRaw(); value_11 = (*(value_12) != 4); } if (value_11) { count = 0LL; } } zir_f_eb6527159f8585fd_CloseRaw((status)[0]); if (count > 0LL) { int32_t child_status = 0; while (true) { bool value_13 = zir_f_eb6527159f8585fd_WaitRaw(pid, &(child_status), 0) < 0; bool value_14 = value_13; if (value_14) { int32_t* value_15 = zir_f_eb6527159f8585fd_ErrnoRaw(); value_14 = (*(value_15) == 4); } if (!value_14) { break; } } bool* value_16 = &(run->finished); (*value_16) = true; int32_t* value_17 = &(run->code); (*value_17) = 127; if (capture) { zir_f_eb6527159f8585fd_CloseRaw((output)[0]); } int32_t value_18 = -1; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_18; } bool* value_19 = &(run->started); (*value_19) = true; int32_t value_20 = 0; if (capture) { value_20 = (output)[0]; } else { value_20 = 0; } int32_t value_21 = value_20; free((prepared).bytes.data); (prepared).bytes.data = NULL; (prepared).bytes.capacity = 0; (prepared).bytes.count = 0; free((prepared).arguments.data); (prepared).arguments.data = NULL; (prepared).arguments.capacity = 0; (prepared).arguments.count = 0; free((prepared).argument_offsets.data); (prepared).argument_offsets.data = NULL; (prepared).argument_offsets.capacity = 0; (prepared).argument_offsets.count = 0; free((prepared).names.data); (prepared).names.data = NULL; (prepared).names.capacity = 0; (prepared).names.count = 0; free((prepared).values.data); (prepared).values.data = NULL; (prepared).values.capacity = 0; (prepared).values.count = 0; return value_21; } bool process_run_linux_StartProcess(ProcessOptions options, ProcessRun* run) { bool value_0 = process_run_linux_Start(options, run, false) >= 0; return value_0 && run->started; } bool process_run_linux_PollProcess(ProcessRun* run) { if (run->finished || !run->started) { return true; } int32_t status = 0; int32_t done = zir_f_eb6527159f8585fd_WaitRaw(run->pid, &(status), 1); if (done == run->pid) { ProcessRun* value_0 = run; int32_t value_1 = status; { ProcessRun* run = value_0; int32_t status = value_1; bool* value_3 = &(run->finished); (*value_3) = true; if (((int32_t)((uint32_t)status & 127u)) != 0) { int32_t* value_4 = &(run->code); (*value_4) = (int32_t)(128u + ((uint32_t)status & 127u)); } else { int32_t* value_5 = &(run->code); (*value_5) = (int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u); } } } bool value_6 = done < 0; if (value_6) { int32_t* value_7 = zir_f_eb6527159f8585fd_ErrnoRaw(); value_6 = (*(value_7) != 4); } if (value_6) { bool* value_8 = &(run->finished); (*value_8) = true; } return run->finished; } bool process_run_linux_WaitProcess(ProcessRun* run) { if (run->finished || !run->started) { return run->started; } int32_t status = 0; while (true) { int32_t done = zir_f_eb6527159f8585fd_WaitRaw(run->pid, &(status), 0); if (done == run->pid) { ProcessRun* value_0 = run; int32_t value_1 = status; { ProcessRun* run = value_0; int32_t status = value_1; bool* value_3 = &(run->finished); (*value_3) = true; if (((int32_t)((uint32_t)status & 127u)) != 0) { int32_t* value_4 = &(run->code); (*value_4) = (int32_t)(128u + ((uint32_t)status & 127u)); } else { int32_t* value_5 = &(run->code); (*value_5) = (int32_t)((uint32_t)((ZiShrS32(status, (uint64_t)(8), 32))) & 255u); } } return true; } bool value_6 = done < 0; if (value_6) { int32_t* value_7 = zir_f_eb6527159f8585fd_ErrnoRaw(); value_6 = (*(value_7) != 4); } if (value_6) { bool* value_8 = &(run->finished); (*value_8) = true; return false; } } return false; } bool process_run_linux_SignalProcess(ProcessRun* run, int32_t signal_number, bool whole_group) { if (!run->started || run->finished || run->pid <= 0) { return false; } int32_t value_0 = 0; if (whole_group) { value_0 = (int32_t)(0u - (uint32_t)(run->pid)); } else { value_0 = run->pid; } int32_t target = value_0; return zir_f_eb6527159f8585fd_KillRaw(target, signal_number) == 0; } bool process_run_linux_RunProcess(ProcessOptions options, ProcessRun* run) { bool capture = options.capture_output; int32_t fd = process_run_linux_Start(options, run, capture); if (fd < 0 || !run->started) { return false; } if (capture) { uint8_t chunk[65536] = {0}; while (true) { ptrdiff_t value_0 = zir_f_eb6527159f8585fd_ReadRaw(fd, &(chunk[0]), 65536); int64_t count = (int64_t)(value_0); bool value_1 = count < 0LL; if (value_1) { int32_t* value_2 = zir_f_eb6527159f8585fd_ErrnoRaw(); value_1 = (*(value_2) == 4); } if (value_1) { continue; } if (count <= 0LL) { break; } int64_t index = 0LL; while (index < count) { uint8_t value_3 = ZIRAN_INDEX(chunk, 65536, index); bool value_4 = false; void *value_5 = ZirVecGrow((void *)(run->output).data, &(run->output).capacity, (run->output).count, sizeof(*(run->output).data)); if (value_5 != NULL) { (run->output).data = (uint8_t *)value_5; (run->output).data[(run->output).count++] = value_3; value_4 = true; } (void)value_4; index = (int64_t)((uint64_t)index + UINT64_C(1)); } } zir_f_eb6527159f8585fd_CloseRaw(fd); } return process_run_linux_WaitProcess(run); } static void process_run_linux_Terminate(int32_t signal_number) { (void)signal_number; termination_requested = true; } void process_run_linux_CatchTermination(void) { termination_requested = false; zir_f_eb6527159f8585fd_SignalRaw(15, process_run_linux_Terminate); zir_f_eb6527159f8585fd_SignalRaw(2, process_run_linux_Terminate); } bool process_run_linux_TerminationRequested(void) { return termination_requested; }