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

Native Pharos runtime entrypoint and orchestration for serve, runtime, website, and ops command flows. More...

#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <grp.h>
#include <strings.h>
#include <arpa/inet.h>
#include <dirent.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include "native_support.h"
#include "native_json_config.h"
#include "native_app_config.h"
#include "native_http_log.h"
#include "native_fs.h"
#include "native_app_runtime_paths.h"
#include "native_artifact_emit.h"
#include "native_runtime_types.h"
#include "native_runtime_reports.h"
#include "native_runtime_load.h"
#include "native_runtime_stack.h"
#include "native_runtime_cleanup.h"
#include "native_app_runtime_finalize.h"
#include "native_serve_config.h"
#include "native_shell_bridge.h"
#include "native_http_request.h"
#include "native_http_response.h"
#include "native_http_access_log.h"
#include "native_static_serve.h"
#include "native_request_path.h"
#include "native_spawn_argv.h"
#include "native_spawn_temp_body.h"
#include "native_process_capture.h"
#include "native_listener.h"
#include "native_connection.h"
#include "native_app_runtime_clone.h"
#include "native_ops_bridge.h"
#include "native_backup_restore.h"
#include "native_json_runtime_ops.h"
#include "native_barcode_runtime_ops.h"
#include "native_dynamic_runtime.h"

Go to the source code of this file.

Data Structures

struct  WorkerContext
 Per-request worker state used while routing either runtime or app traffic. More...
struct  NativeWorkerPool

Macros

#define PATH_SEP   '/'
#define PHAROS_SOCKET   int
#define PHAROS_INVALID_SOCKET   -1
#define pharos_close_socket   close
#define pharos_getcwd   getcwd
#define pharos_access   access
#define pharos_stat   stat
#define pharos_mkdir   mkdir
#define pharos_unlink   unlink
#define pharos_strdup   strdup
#define PHAROS_TARGET_ID   "source-bootstrap"
#define PHAROS_VERSION   "0.7.23"
#define PHAROS_NATIVE_DEFAULT_WORKER_COUNT   16
#define PHAROS_NATIVE_MIN_WORKER_COUNT   1
#define PHAROS_NATIVE_MAX_WORKER_COUNT   256
#define PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY   32
#define PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY   8192
#define PHAROS_NATIVE_DEFAULT_WORK_QUEUE_CAPACITY   128
#define PHAROS_NATIVE_WORK_QUEUE_BYTES_PER_SLOT   (8ULL * 1024ULL * 1024ULL)

Typedefs

typedef int(* NativeServeHandlerFn) (const ServeConfig *config)

Functions

static void free_worker_context_native (WorkerContext *context)
 Release a worker context and every owned request/runtime resource.
static void process_worker_context_native (WorkerContext *context)
 Execute one accepted request through the active runtime/app handler.
static int native_worker_pool_init (NativeWorkerPool *pool, size_t worker_count, size_t capacity)
 Initialize a bounded worker pool for native request serving.
static int native_worker_pool_enqueue (NativeWorkerPool *pool, WorkerContext *context)
 Submit accepted request work to the bounded worker pool.
static void native_worker_pool_request_shutdown (NativeWorkerPool *pool)
 Ask the worker pool to stop after draining queued work.
static void native_worker_pool_join (NativeWorkerPool *pool)
 Join all worker threads created for the pool.
static void native_worker_pool_destroy (NativeWorkerPool *pool)
 Destroy worker-pool resources after shutdown and join.
static void native_send_worker_pool_overload_response (NativeConnection *connection)
 Send the standard overload response for saturated native serving.
static int write_noindex_markers_recursive_native (const char *root_path)
 Recursively write macOS no-index markers through a directory tree.
static size_t native_resolved_worker_count (const char *runtime_conf_path)
 Resolve the fixed worker-thread count for one serve process.
static size_t native_resolved_work_queue_capacity (const char *runtime_conf_path)
 Resolve the bounded queued-request capacity for one serve process.
static void clear_listener_cleanup_registration (void)
static void cleanup_active_listener (void)
static void register_listener_cleanup (const ServeConfig *config, PHAROS_SOCKET server_fd)
static void pharos_native_shutdown_signal_handler (int signum)
static void install_native_signal_handlers (void)
static int native_known_website_supported (const char *target_id)
static int build_known_website_native (const char *target_id, const char *build_dir, char **report_path_out, char **artifact_dir_out)
static int build_app_from_root_native (const char *app_root, const char *build_dir_override, const char *state_dir_override, const char *state_path_override, const char *base_path_override, char **report_path_out, char **artifact_dir_out)
static int build_dev_docs_directory_native (const char *app_root, const char *artifact_dir)
static int app_root_has_finalized_artifact_native (const char *app_root)
static int maybe_seed_app_state_native (const ServeConfig *config, const char *app_root, const char *app_id, int force_seed)
static int emit_website_status_native (const char *verb, const char *target_id, const char *build_dir, char **report_path_out)
static char * app_runtime_host_profile_native (const char *app_root)
static char * runtime_build_dir_override_native (const ServeConfig *config, const char *app_root)
static int prepare_app_artifact_native (const char *app_root, const char *app_id, const char *build_dir_override, const char *state_dir_override, const char *state_path_override, const char *base_path_override, char **report_path_out, char **artifact_dir_out)
 Prepares the artifact directory for an app at startup.
static const char * dev_docs_directory_index_html_native (void)
static int add_runtime_app_native (RuntimeStack *stack, const ServeConfig *config, const char *app_root, const char *app_id_hint)
static char * executable_dir_from_argv0 (const char *argv0)
static char * find_repo_root (const char *argv0)
static char * resolve_value_or_default (const char *value, const char *fallback)
static char * resolve_runtime_socket_path_native (const ServeConfig *config, const char *runtime_conf_path, const char *runtime_conf_dir)
static int emit_text_file_to_stdout_native (const char *file_path)
static char * resolve_seed_entrypoint_native (const char *app_root, const char *target_id, const char *build_dir_override)
static int load_app_runtime_for_single_app (const ServeConfig *config, AppRuntime *app)
static int spawn_app_request (const AppRuntime *app, const HttpRequest *request, char **response, size_t *response_len, char **stderr_text, size_t *stderr_len)
static char * resolve_website_root (const ServeConfig *config)
static int load_runtime_stack (const ServeConfig *config, RuntimeStack *stack)
static void handle_app_or_runtime_request (WorkerContext *context)
static size_t native_clamp_size_value (size_t value, size_t minimum, size_t maximum)
 Clamp one size value into an inclusive range.
static int native_parse_positive_size_value (const char *text, size_t *value_out)
 Parse one positive size_t from config text.
static int native_conf_positive_size_value (const char *runtime_conf_path, const char *key, size_t *value_out)
 Read the configured positive size value for one runtime key.
static unsigned long long native_detect_physical_memory_bytes (void)
 Detect total physical memory visible to the current host.
static size_t native_default_worker_count (void)
 Resolve the default worker-thread count when config does not override it.
static size_t native_default_work_queue_capacity (void)
 Resolve the default queue capacity from physical memory.
static void * native_worker_pool_thread_main (void *opaque)
 Run queued request work items until the worker pool shuts down.
static void print_version (void)
static void print_help (void)
static const char * native_http_parse_reason_phrase (int status_code)
static const char * native_http_parse_error_body (int status_code)
static int accept_http_request_native (int server_fd, NativeConnection *connection, HttpRequest *request)
static WorkerContextbuild_worker_context_native (NativeConnection *connection, HttpRequest *request, const AppRuntime *source_app)
static int handle_static_root_builtin_request (NativeConnection *connection, const HttpRequest *request)
static int serve_static_root (const ServeConfig *config)
static int serve_single_app (const ServeConfig *config)
static int serve_runtime_stack_native (const ServeConfig *config)
static int serve_website_target (const ServeConfig *config)
static NativeServeHandlerFn find_serve_handler_native (const char *kind)
static int handle_serve (int argc, char **argv)
static int website_verb_mode_native (const char *verb)
static int handle_native_website_command (int argc, char **argv)
static int runtime_verb_supported_native (const char *verb)
static const char * native_app_runtime_report_id (const char *verb)
static int handle_native_runtime_app_command (const char *verb, ServeConfig *config)
static int handle_native_runtime_command (int argc, char **argv)
static int prepare_finalized_app_from_config (const ServeConfig *config, char **artifact_dir_out, AppRuntime *app_out)
static char * native_option_value (int argc, char **argv, const char *first_name, const char *second_name)
static int apply_deb_package_option_native (const char *option, const char *value, char **binary_path, char **target_id, char **output_dir)
static int handle_native_deploy_package_deb_command (int argc, char **argv)
static int parse_native_app_ops_config (int argc, char **argv, int skip_args, ServeConfig *config)
static int prepare_native_app_ops_runtime (int argc, char **argv, int skip_args, ServeConfig *config, char **artifact_dir, AppRuntime *app)
static int emit_native_report_json (const char *report_json)
static int handle_native_backup_restore_ops_command (int argc, char **argv)
static int handle_native_drift_check_ops_command (int argc, char **argv)
static int handle_native_deploy_check_ops_command (int argc, char **argv)
static int match_native_ops_command (int argc, char **argv, const char *first, const char *second, const char *third, int min_argc)
static int handle_native_noindex_command (int argc, char **argv)
static int handle_native_ops_command (int argc, char **argv)
int main (int argc, char **argv)
 Native Pharos CLI entrypoint.

Variables

static char * global_repo_root = NULL
static char * global_binary_dir = NULL
static volatile sig_atomic_t global_shutdown_requested = 0
static NativeListenerState global_listener_state = { -1, NULL }

Detailed Description

Native Pharos runtime entrypoint and orchestration for serve, runtime, website, and ops command flows.

Definition in file pharos_runtime.c.

Macro Definition Documentation

◆ PATH_SEP

#define PATH_SEP   '/'

Definition at line 68 of file pharos_runtime.c.

◆ pharos_access

#define pharos_access   access

Definition at line 73 of file pharos_runtime.c.

◆ pharos_close_socket

#define pharos_close_socket   close

Definition at line 71 of file pharos_runtime.c.

◆ pharos_getcwd

#define pharos_getcwd   getcwd

Definition at line 72 of file pharos_runtime.c.

◆ PHAROS_INVALID_SOCKET

#define PHAROS_INVALID_SOCKET   -1

Definition at line 70 of file pharos_runtime.c.

◆ pharos_mkdir

#define pharos_mkdir   mkdir

Definition at line 75 of file pharos_runtime.c.

◆ PHAROS_NATIVE_DEFAULT_WORK_QUEUE_CAPACITY

#define PHAROS_NATIVE_DEFAULT_WORK_QUEUE_CAPACITY   128

Definition at line 135 of file pharos_runtime.c.

Referenced by native_default_work_queue_capacity().

◆ PHAROS_NATIVE_DEFAULT_WORKER_COUNT

#define PHAROS_NATIVE_DEFAULT_WORKER_COUNT   16

Definition at line 130 of file pharos_runtime.c.

Referenced by native_default_worker_count().

◆ PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY

#define PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY   8192

◆ PHAROS_NATIVE_MAX_WORKER_COUNT

#define PHAROS_NATIVE_MAX_WORKER_COUNT   256

Definition at line 132 of file pharos_runtime.c.

Referenced by native_default_worker_count(), and native_resolved_worker_count().

◆ PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY

#define PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY   32

◆ PHAROS_NATIVE_MIN_WORKER_COUNT

#define PHAROS_NATIVE_MIN_WORKER_COUNT   1

Definition at line 131 of file pharos_runtime.c.

Referenced by native_default_worker_count(), and native_resolved_worker_count().

◆ PHAROS_NATIVE_WORK_QUEUE_BYTES_PER_SLOT

#define PHAROS_NATIVE_WORK_QUEUE_BYTES_PER_SLOT   (8ULL * 1024ULL * 1024ULL)

Definition at line 136 of file pharos_runtime.c.

Referenced by native_default_work_queue_capacity().

◆ PHAROS_SOCKET

#define PHAROS_SOCKET   int

◆ pharos_stat

#define pharos_stat   stat

Definition at line 74 of file pharos_runtime.c.

◆ pharos_strdup

◆ PHAROS_TARGET_ID

#define PHAROS_TARGET_ID   "source-bootstrap"

◆ pharos_unlink

#define pharos_unlink   unlink

Definition at line 76 of file pharos_runtime.c.

Referenced by build_dev_docs_directory_native().

◆ PHAROS_VERSION

#define PHAROS_VERSION   "0.7.23"

Definition at line 117 of file pharos_runtime.c.

Referenced by handle_static_root_builtin_request(), and print_version().

Typedef Documentation

◆ NativeServeHandlerFn

typedef int(* NativeServeHandlerFn) (const ServeConfig *config)

Definition at line 242 of file pharos_runtime.c.

Function Documentation

◆ accept_http_request_native()

◆ add_runtime_app_native()

◆ app_root_has_finalized_artifact_native()

int app_root_has_finalized_artifact_native ( const char * app_root)
static

Definition at line 1300 of file pharos_runtime.c.

References path_exists(), and path_join().

Referenced by add_runtime_app_native().

◆ app_runtime_host_profile_native()

char * app_runtime_host_profile_native ( const char * app_root)
static

◆ apply_deb_package_option_native()

int apply_deb_package_option_native ( const char * option,
const char * value,
char ** binary_path,
char ** target_id,
char ** output_dir )
static

Definition at line 3262 of file pharos_runtime.c.

References streq().

Referenced by handle_native_deploy_package_deb_command().

◆ build_app_from_root_native()

◆ build_dev_docs_directory_native()

int build_dev_docs_directory_native ( const char * app_root,
const char * artifact_dir )
static

◆ build_known_website_native()

int build_known_website_native ( const char * target_id,
const char * build_dir,
char ** report_path_out,
char ** artifact_dir_out )
static

◆ build_worker_context_native()

◆ cleanup_active_listener()

void cleanup_active_listener ( void )
static

◆ clear_listener_cleanup_registration()

void clear_listener_cleanup_registration ( void )
static

◆ dev_docs_directory_index_html_native()

const char * dev_docs_directory_index_html_native ( void )
static

Definition at line 437 of file pharos_runtime.c.

Referenced by build_dev_docs_directory_native().

◆ emit_native_report_json()

int emit_native_report_json ( const char * report_json)
static

◆ emit_text_file_to_stdout_native()

int emit_text_file_to_stdout_native ( const char * file_path)
static

Definition at line 1332 of file pharos_runtime.c.

References read_file_text().

Referenced by handle_native_runtime_command().

◆ emit_website_status_native()

int emit_website_status_native ( const char * verb,
const char * target_id,
const char * build_dir,
char ** report_path_out )
static

◆ executable_dir_from_argv0()

char * executable_dir_from_argv0 ( const char * argv0)
static

◆ find_repo_root()

char * find_repo_root ( const char * argv0)
static

◆ find_serve_handler_native()

NativeServeHandlerFn find_serve_handler_native ( const char * kind)
static

◆ free_worker_context_native()

void free_worker_context_native ( WorkerContext * context)
static

Release a worker context and every owned request/runtime resource.

Parameters
contextPer-request worker state to release.

Definition at line 1954 of file pharos_runtime.c.

References WorkerContext::app, WorkerContext::connection, free_app_runtime(), free_http_request_native(), native_connection_close(), and WorkerContext::request.

Referenced by native_worker_pool_destroy(), process_worker_context_native(), serve_runtime_stack_native(), and serve_single_app().

◆ handle_app_or_runtime_request()

◆ handle_native_backup_restore_ops_command()

◆ handle_native_deploy_check_ops_command()

int handle_native_deploy_check_ops_command ( int argc,
char ** argv )
static

◆ handle_native_deploy_package_deb_command()

int handle_native_deploy_package_deb_command ( int argc,
char ** argv )
static

◆ handle_native_drift_check_ops_command()

int handle_native_drift_check_ops_command ( int argc,
char ** argv )
static

◆ handle_native_noindex_command()

int handle_native_noindex_command ( int argc,
char ** argv )
static

Definition at line 3508 of file pharos_runtime.c.

References path_canonicalize(), pharos_strdup, streq(), and write_noindex_markers_recursive_native().

Referenced by main().

◆ handle_native_ops_command()

◆ handle_native_runtime_app_command()

◆ handle_native_runtime_command()

◆ handle_native_website_command()

int handle_native_website_command ( int argc,
char ** argv )
static

◆ handle_serve()

◆ handle_static_root_builtin_request()

int handle_static_root_builtin_request ( NativeConnection * connection,
const HttpRequest * request )
static

◆ install_native_signal_handlers()

void install_native_signal_handlers ( void )
static

Definition at line 268 of file pharos_runtime.c.

References pharos_native_shutdown_signal_handler().

Referenced by main().

◆ load_app_runtime_for_single_app()

◆ load_runtime_stack()

◆ main()

int main ( int argc,
char ** argv )

◆ match_native_ops_command()

int match_native_ops_command ( int argc,
char ** argv,
const char * first,
const char * second,
const char * third,
int min_argc )
static

Definition at line 3485 of file pharos_runtime.c.

References streq().

Referenced by handle_native_ops_command().

◆ maybe_seed_app_state_native()

◆ native_app_runtime_report_id()

const char * native_app_runtime_report_id ( const char * verb)
static

Definition at line 2991 of file pharos_runtime.c.

References streq().

Referenced by handle_native_runtime_app_command().

◆ native_clamp_size_value()

size_t native_clamp_size_value ( size_t value,
size_t minimum,
size_t maximum )
static

Clamp one size value into an inclusive range.

Parameters
valueCandidate value.
minimumInclusive lower bound.
maximumInclusive upper bound.
Returns
Clamped size value.

Definition at line 1972 of file pharos_runtime.c.

Referenced by native_default_work_queue_capacity(), native_default_worker_count(), native_resolved_work_queue_capacity(), and native_resolved_worker_count().

◆ native_conf_positive_size_value()

int native_conf_positive_size_value ( const char * runtime_conf_path,
const char * key,
size_t * value_out )
static

Read the configured positive size value for one runtime key.

Parameters
runtime_conf_pathRuntime configuration path.
keyConfig key to read.
value_outParsed positive value on success.
Returns
1 on success, 0 when missing or invalid.

Definition at line 2015 of file pharos_runtime.c.

References conf_lookup_value(), and native_parse_positive_size_value().

Referenced by native_resolved_work_queue_capacity(), and native_resolved_worker_count().

◆ native_default_work_queue_capacity()

size_t native_default_work_queue_capacity ( void )
static

◆ native_default_worker_count()

size_t native_default_worker_count ( void )
static

Resolve the default worker-thread count when config does not override it.

Returns
Positive worker-thread count.

Definition at line 2062 of file pharos_runtime.c.

References native_clamp_size_value(), PHAROS_NATIVE_DEFAULT_WORKER_COUNT, PHAROS_NATIVE_MAX_WORKER_COUNT, and PHAROS_NATIVE_MIN_WORKER_COUNT.

Referenced by native_resolved_worker_count().

◆ native_detect_physical_memory_bytes()

unsigned long long native_detect_physical_memory_bytes ( void )
static

Detect total physical memory visible to the current host.

Returns
Physical memory bytes, or 0 when unavailable.

Definition at line 2032 of file pharos_runtime.c.

Referenced by native_default_work_queue_capacity().

◆ native_http_parse_error_body()

const char * native_http_parse_error_body ( int status_code)
static

Definition at line 2539 of file pharos_runtime.c.

Referenced by accept_http_request_native().

◆ native_http_parse_reason_phrase()

const char * native_http_parse_reason_phrase ( int status_code)
static

Definition at line 2522 of file pharos_runtime.c.

Referenced by accept_http_request_native().

◆ native_known_website_supported()

int native_known_website_supported ( const char * target_id)
static

Definition at line 282 of file pharos_runtime.c.

Referenced by handle_native_website_command(), and resolve_website_root().

◆ native_option_value()

char * native_option_value ( int argc,
char ** argv,
const char * first_name,
const char * second_name )
static

Definition at line 3252 of file pharos_runtime.c.

References streq().

Referenced by handle_native_backup_restore_ops_command().

◆ native_parse_positive_size_value()

int native_parse_positive_size_value ( const char * text,
size_t * value_out )
static

Parse one positive size_t from config text.

Parameters
textRaw config value text.
value_outParsed positive value on success.
Returns
1 on success, 0 on invalid or missing input.

Definition at line 1989 of file pharos_runtime.c.

Referenced by native_conf_positive_size_value().

◆ native_resolved_work_queue_capacity()

size_t native_resolved_work_queue_capacity ( const char * runtime_conf_path)
static

Resolve the bounded queued-request capacity for one serve process.

Parameters
runtime_conf_pathRuntime configuration path to consult for overrides.
Returns
Positive queued-request capacity.

Definition at line 2131 of file pharos_runtime.c.

References native_clamp_size_value(), native_conf_positive_size_value(), native_default_work_queue_capacity(), PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY, and PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY.

Referenced by serve_runtime_stack_native(), and serve_single_app().

◆ native_resolved_worker_count()

size_t native_resolved_worker_count ( const char * runtime_conf_path)
static

Resolve the fixed worker-thread count for one serve process.

Parameters
runtime_conf_pathRuntime configuration path to consult for overrides.
Returns
Positive worker-thread count.

Definition at line 2117 of file pharos_runtime.c.

References native_clamp_size_value(), native_conf_positive_size_value(), native_default_worker_count(), PHAROS_NATIVE_MAX_WORKER_COUNT, and PHAROS_NATIVE_MIN_WORKER_COUNT.

Referenced by serve_runtime_stack_native(), and serve_single_app().

◆ native_send_worker_pool_overload_response()

void native_send_worker_pool_overload_response ( NativeConnection * connection)
static

Send the standard overload response for saturated native serving.

Parameters
connectionAccepted client connection.

Definition at line 2161 of file pharos_runtime.c.

References native_send_text_response().

Referenced by serve_runtime_stack_native(), and serve_single_app().

◆ native_worker_pool_destroy()

void native_worker_pool_destroy ( NativeWorkerPool * pool)
static

◆ native_worker_pool_enqueue()

int native_worker_pool_enqueue ( NativeWorkerPool * pool,
WorkerContext * context )
static

Submit accepted request work to the bounded worker pool.

Parameters
poolActive worker pool.
contextPer-request work item to enqueue.
Returns
0 on success, 1 when saturated or shutting down, non-zero on internal failure.

Definition at line 2305 of file pharos_runtime.c.

References NativeWorkerPool::capacity, NativeWorkerPool::count, NativeWorkerPool::items, NativeWorkerPool::mutex, NativeWorkerPool::not_empty, NativeWorkerPool::shutting_down, and NativeWorkerPool::tail.

Referenced by serve_runtime_stack_native(), and serve_single_app().

◆ native_worker_pool_init()

int native_worker_pool_init ( NativeWorkerPool * pool,
size_t worker_count,
size_t capacity )
static

Initialize a bounded worker pool for native request serving.

Parameters
poolPool state to initialize.
worker_countFixed number of worker threads to create.
capacityMaximum queued requests.
Returns
0 on success, non-zero on failure.

Definition at line 2233 of file pharos_runtime.c.

References NativeWorkerPool::capacity, NativeWorkerPool::items, NativeWorkerPool::mutex, native_worker_pool_destroy(), native_worker_pool_join(), native_worker_pool_request_shutdown(), native_worker_pool_thread_main(), NativeWorkerPool::not_empty, NativeWorkerPool::threads, and NativeWorkerPool::worker_count.

Referenced by serve_runtime_stack_native(), and serve_single_app().

◆ native_worker_pool_join()

void native_worker_pool_join ( NativeWorkerPool * pool)
static

Join all worker threads created for the pool.

Parameters
poolActive worker pool.

Definition at line 2367 of file pharos_runtime.c.

References NativeWorkerPool::threads, and NativeWorkerPool::worker_count.

Referenced by native_worker_pool_init(), serve_runtime_stack_native(), and serve_single_app().

◆ native_worker_pool_request_shutdown()

void native_worker_pool_request_shutdown ( NativeWorkerPool * pool)
static

Ask the worker pool to stop after draining queued work.

Parameters
poolActive worker pool.

Definition at line 2343 of file pharos_runtime.c.

References NativeWorkerPool::mutex, NativeWorkerPool::not_empty, and NativeWorkerPool::shutting_down.

Referenced by native_worker_pool_init(), serve_runtime_stack_native(), and serve_single_app().

◆ native_worker_pool_thread_main()

void * native_worker_pool_thread_main ( void * opaque)
static

Run queued request work items until the worker pool shuts down.

Parameters
opaqueActive worker pool.
Returns
Unused thread return pointer.

Definition at line 2201 of file pharos_runtime.c.

References NativeWorkerPool::capacity, NativeWorkerPool::count, NativeWorkerPool::head, NativeWorkerPool::items, NativeWorkerPool::mutex, NativeWorkerPool::not_empty, process_worker_context_native(), and NativeWorkerPool::shutting_down.

Referenced by native_worker_pool_init().

◆ parse_native_app_ops_config()

int parse_native_app_ops_config ( int argc,
char ** argv,
int skip_args,
ServeConfig * config )
static

◆ pharos_native_shutdown_signal_handler()

void pharos_native_shutdown_signal_handler ( int signum)
static

◆ prepare_app_artifact_native()

int prepare_app_artifact_native ( const char * app_root,
const char * app_id,
const char * build_dir_override,
const char * state_dir_override,
const char * state_path_override,
const char * base_path_override,
char ** report_path_out,
char ** artifact_dir_out )
static

Prepares the artifact directory for an app at startup.

Both dynamic-app and static-pages profiles now use the native artifact builder. Static pages are served directly from the finalized artifact and no longer require a shell-built app-local request host during native runtime preparation.

Parameters
app_rootFilesystem path to the app root.
app_idApplication identifier.
build_dir_overrideBuild directory override (may be NULL).
state_dir_overrideState directory override (may be NULL).
state_path_overrideState file override (may be NULL).
base_path_overrideURL base-path override (may be NULL).
report_path_outReceives the build report path (may be NULL).
artifact_dir_outReceives the artifact directory on success.
Returns
0 on success, non-zero on failure.

Definition at line 406 of file pharos_runtime.c.

References build_app_from_root_native(), and effective_app_build_dir_native().

Referenced by add_runtime_app_native(), handle_native_runtime_app_command(), load_app_runtime_for_single_app(), and prepare_finalized_app_from_config().

◆ prepare_finalized_app_from_config()

◆ prepare_native_app_ops_runtime()

int prepare_native_app_ops_runtime ( int argc,
char ** argv,
int skip_args,
ServeConfig * config,
char ** artifact_dir,
AppRuntime * app )
static

◆ print_help()

void print_help ( void )
static

Definition at line 2466 of file pharos_runtime.c.

Referenced by handle_serve(), and main().

◆ print_version()

void print_version ( void )
static

Definition at line 2462 of file pharos_runtime.c.

References PHAROS_TARGET_ID, and PHAROS_VERSION.

Referenced by main().

◆ process_worker_context_native()

void process_worker_context_native ( WorkerContext * context)
static

Execute one accepted request through the active runtime/app handler.

Parameters
contextPer-request worker state to process.

Definition at line 2148 of file pharos_runtime.c.

References free_worker_context_native(), and handle_app_or_runtime_request().

Referenced by native_worker_pool_thread_main().

◆ register_listener_cleanup()

void register_listener_cleanup ( const ServeConfig * config,
PHAROS_SOCKET server_fd )
static

◆ resolve_runtime_socket_path_native()

char * resolve_runtime_socket_path_native ( const ServeConfig * config,
const char * runtime_conf_path,
const char * runtime_conf_dir )
static

◆ resolve_seed_entrypoint_native()

char * resolve_seed_entrypoint_native ( const char * app_root,
const char * target_id,
const char * build_dir_override )
static

Static-pages apps are now built and served directly from their finalized artifacts in the native runtime path and do not require seed-entrypoint compatibility hosts because they have no app-owned mutable runtime state.

Definition at line 1346 of file pharos_runtime.c.

References app_runtime_host_profile_native(), json_find_string_in_section(), path_join(), pharos_strdup, read_file_text(), and streq().

Referenced by maybe_seed_app_state_native().

◆ resolve_value_or_default()

char * resolve_value_or_default ( const char * value,
const char * fallback )
static

Definition at line 1293 of file pharos_runtime.c.

References pharos_strdup.

Referenced by load_runtime_stack().

◆ resolve_website_root()

◆ runtime_build_dir_override_native()

char * runtime_build_dir_override_native ( const ServeConfig * config,
const char * app_root )
static

◆ runtime_verb_supported_native()

int runtime_verb_supported_native ( const char * verb)
static

Definition at line 2978 of file pharos_runtime.c.

References streq().

Referenced by handle_native_runtime_command().

◆ serve_runtime_stack_native()

◆ serve_single_app()

◆ serve_static_root()

◆ serve_website_target()

int serve_website_target ( const ServeConfig * config)
static

◆ spawn_app_request()

◆ website_verb_mode_native()

int website_verb_mode_native ( const char * verb)
static

Definition at line 2913 of file pharos_runtime.c.

References streq().

Referenced by handle_native_website_command().

◆ write_noindex_markers_recursive_native()

int write_noindex_markers_recursive_native ( const char * root_path)
static

Recursively write macOS no-index markers through a directory tree.

Parameters
root_pathDirectory tree to mark.
Returns
0 on success, non-zero on failure.

Definition at line 2414 of file pharos_runtime.c.

References path_is_directory(), path_join(), streq(), write_noindex_markers_recursive_native(), and write_text_file().

Referenced by handle_native_noindex_command(), and write_noindex_markers_recursive_native().

Variable Documentation

◆ global_binary_dir

◆ global_listener_state

NativeListenerState global_listener_state = { -1, NULL }
static

◆ global_repo_root

◆ global_shutdown_requested

volatile sig_atomic_t global_shutdown_requested = 0
static