Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_process_capture.c File Reference

Runs child processes and captures their output, optionally with injected environment values. More...

#include "native_process_capture.h"
#include "native_support.h"
#include <poll.h>
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

Go to the source code of this file.

Functions

static int append_pipe_to_buffer (int fd, Buffer *buffer, int *open_flag)
static char * build_child_env_assignment_native (const char *key, const char *value)
static void free_child_env_native (char **child_env, size_t base_count, size_t child_count)
static char ** build_child_env_native (const char *env_keys[], const char *env_values[], size_t env_count, size_t *base_count_out, size_t *child_count_out)
int capture_execv_output_split_env_native (char *const argv[], const char *env_keys[], const char *env_values[], size_t env_count, char **stdout_output, size_t *stdout_len, char **stderr_output, size_t *stderr_len)
 Executes a process with injected environment values and captures stdout and stderr separately.
int capture_execv_output_env_native (char *const argv[], const char *env_keys[], const char *env_values[], size_t env_count, char **output, size_t *output_len)
 Executes a process with injected environment values and captures its output.
int capture_execv_output_native (char *const argv[], char **output, size_t *output_len)
 Executes a process and captures its combined output.
int run_process_capture_native (char *const argv[], char **output)
 Executes a process and captures its combined output text.

Variables

char ** environ

Detailed Description

Runs child processes and captures their output, optionally with injected environment values.

Definition in file native_process_capture.c.

Function Documentation

◆ append_pipe_to_buffer()

int append_pipe_to_buffer ( int fd,
Buffer * buffer,
int * open_flag )
static

Definition at line 22 of file native_process_capture.c.

References buffer_append().

Referenced by capture_execv_output_split_env_native().

◆ build_child_env_assignment_native()

char * build_child_env_assignment_native ( const char * key,
const char * value )
static

Definition at line 39 of file native_process_capture.c.

Referenced by build_child_env_native().

◆ build_child_env_native()

char ** build_child_env_native ( const char * env_keys[],
const char * env_values[],
size_t env_count,
size_t * base_count_out,
size_t * child_count_out )
static

◆ capture_execv_output_env_native()

int capture_execv_output_env_native ( char *const argv[],
const char * env_keys[],
const char * env_values[],
size_t env_count,
char ** output,
size_t * output_len )

Executes a process with injected environment values and captures its output.

Parameters
argvNull-terminated argv array for the child process.
env_keysEnvironment variable names to set.
env_valuesEnvironment variable values paired with env_keys.
env_countNumber of environment pairs to apply.
outputDestination for the allocated output buffer.
output_lenOptional destination for the output length.
Returns
Process exit status, or a non-zero launcher status on failure.

Definition at line 277 of file native_process_capture.c.

References buffer_append(), buffer_free(), buffer_init(), capture_execv_output_split_env_native(), Buffer::data, and Buffer::len.

Referenced by capture_execv_output_native(), maybe_seed_app_state_native(), and shell_runtime_command_capture_native().

◆ capture_execv_output_native()

int capture_execv_output_native ( char *const argv[],
char ** output,
size_t * output_len )

Executes a process and captures its combined output.

Parameters
argvNull-terminated argv array for the child process.
outputDestination for the allocated output buffer.
output_lenOptional destination for the output length.
Returns
Process exit status, or a non-zero launcher status on failure.

Definition at line 313 of file native_process_capture.c.

References capture_execv_output_env_native().

Referenced by build_dev_docs_directory_native(), capture_checksum_output_runtime(), and run_process_capture_native().

◆ capture_execv_output_split_env_native()

int capture_execv_output_split_env_native ( char *const argv[],
const char * env_keys[],
const char * env_values[],
size_t env_count,
char ** stdout_output,
size_t * stdout_len,
char ** stderr_output,
size_t * stderr_len )

Executes a process with injected environment values and captures stdout and stderr separately.

Parameters
argvNull-terminated argv array for the child process.
env_keysEnvironment variable names to set.
env_valuesEnvironment variable values paired with env_keys.
env_countNumber of environment pairs to apply.
stdout_outputDestination for the allocated stdout buffer.
stdout_lenOptional destination for the stdout length.
stderr_outputDestination for the allocated stderr buffer.
stderr_lenOptional destination for the stderr length.
Returns
Process exit status, or a non-zero launcher status on failure.

Definition at line 121 of file native_process_capture.c.

References append_pipe_to_buffer(), buffer_free(), buffer_init(), build_child_env_native(), Buffer::data, environ, free_child_env_native(), and Buffer::len.

Referenced by capture_execv_output_env_native(), and spawn_app_request().

◆ free_child_env_native()

void free_child_env_native ( char ** child_env,
size_t base_count,
size_t child_count )
static

Definition at line 58 of file native_process_capture.c.

Referenced by capture_execv_output_split_env_native().

◆ run_process_capture_native()

int run_process_capture_native ( char *const argv[],
char ** output )

Executes a process and captures its combined output text.

Parameters
argvNull-terminated argv array for the child process.
outputDestination for the allocated output buffer.
Returns
Process exit status, or a non-zero launcher status on failure.

Definition at line 317 of file native_process_capture.c.

References capture_execv_output_native().

Referenced by handle_native_deploy_package_deb_command(), native_capture_trimmed(), and native_capture_trimmed().

Variable Documentation

◆ environ

char** environ
extern