|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
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 WorkerContext * | build_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 } |
Native Pharos runtime entrypoint and orchestration for serve, runtime, website, and ops command flows.
Definition in file pharos_runtime.c.
| #define PATH_SEP '/' |
Definition at line 68 of file pharos_runtime.c.
| #define pharos_access access |
Definition at line 73 of file pharos_runtime.c.
| #define pharos_close_socket close |
Definition at line 71 of file pharos_runtime.c.
| #define pharos_getcwd getcwd |
Definition at line 72 of file pharos_runtime.c.
| #define PHAROS_INVALID_SOCKET -1 |
Definition at line 70 of file pharos_runtime.c.
| #define pharos_mkdir mkdir |
Definition at line 75 of file pharos_runtime.c.
| #define PHAROS_NATIVE_DEFAULT_WORK_QUEUE_CAPACITY 128 |
Definition at line 135 of file pharos_runtime.c.
Referenced by native_default_work_queue_capacity().
| #define PHAROS_NATIVE_DEFAULT_WORKER_COUNT 16 |
Definition at line 130 of file pharos_runtime.c.
Referenced by native_default_worker_count().
| #define PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY 8192 |
Definition at line 134 of file pharos_runtime.c.
Referenced by native_default_work_queue_capacity(), and native_resolved_work_queue_capacity().
| #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().
| #define PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY 32 |
Definition at line 133 of file pharos_runtime.c.
Referenced by native_default_work_queue_capacity(), and native_resolved_work_queue_capacity().
| #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().
| #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().
| #define PHAROS_SOCKET int |
Definition at line 69 of file pharos_runtime.c.
Referenced by register_listener_cleanup(), serve_runtime_stack_native(), serve_single_app(), and serve_static_root().
| #define pharos_stat stat |
Definition at line 74 of file pharos_runtime.c.
| #define pharos_strdup strdup |
Definition at line 77 of file pharos_runtime.c.
Referenced by add_runtime_app_native(), app_runtime_host_profile_native(), executable_dir_from_argv0(), handle_app_or_runtime_request(), handle_native_noindex_command(), load_app_runtime_for_single_app(), resolve_runtime_socket_path_native(), resolve_seed_entrypoint_native(), resolve_value_or_default(), runtime_build_dir_override_native(), and spawn_app_request().
| #define PHAROS_TARGET_ID "source-bootstrap" |
Definition at line 113 of file pharos_runtime.c.
Referenced by handle_native_deploy_check_ops_command(), handle_native_runtime_app_command(), handle_static_root_builtin_request(), and print_version().
| #define pharos_unlink unlink |
Definition at line 76 of file pharos_runtime.c.
Referenced by build_dev_docs_directory_native().
| #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 int(* NativeServeHandlerFn) (const ServeConfig *config) |
Definition at line 242 of file pharos_runtime.c.
|
static |
Definition at line 2555 of file pharos_runtime.c.
References global_shutdown_requested, native_connection_accept_next(), native_connection_close(), native_http_parse_error_body(), native_http_parse_reason_phrase(), native_send_text_response(), and parse_http_request_native().
Referenced by serve_runtime_stack_native(), serve_single_app(), and serve_static_root().
|
static |
Definition at line 1076 of file pharos_runtime.c.
References app_root_has_finalized_artifact_native(), RuntimeStack::apps, ServeConfig::base_path, RuntimeStack::count, effective_app_artifact_dir_native(), finalize_loaded_app_runtime_native(), free_app_runtime(), json_find_string(), load_app_runtime_from_artifact_native(), MAX_APPS, maybe_seed_app_state_native(), path_join(), pharos_strdup, prepare_app_artifact_native(), read_file_text(), runtime_build_dir_override_native(), ServeConfig::state_dir, and ServeConfig::state_path.
Referenced by load_runtime_stack().
|
static |
Definition at line 1300 of file pharos_runtime.c.
References path_exists(), and path_join().
Referenced by add_runtime_app_native().
|
static |
Definition at line 356 of file pharos_runtime.c.
References json_find_string_in_section(), path_join(), pharos_strdup, and read_file_text().
Referenced by resolve_seed_entrypoint_native().
|
static |
Definition at line 3262 of file pharos_runtime.c.
References streq().
Referenced by handle_native_deploy_package_deb_command().
|
static |
Definition at line 744 of file pharos_runtime.c.
References build_artifact_local_app_manifest_json(), build_dev_docs_directory_native(), build_native_app_build_report_json(), build_native_app_index_html(), copy_directory_recursive(), copy_file_binary(), count_substring_occurrences(), effective_app_artifact_dir_native(), effective_app_base_path_native(), effective_app_build_dir_native(), effective_app_debug_native(), effective_app_error_report_path_native(), effective_app_log_format_native(), effective_app_log_path_native(), effective_app_state_path_native(), ensure_directory(), json_extract_array_in_section(), json_find_string(), json_find_string_in_section(), native_website_report_path(), path_exists(), path_is_directory(), path_join(), read_file_text(), remove_directory_recursive(), streq(), and write_text_file().
Referenced by prepare_app_artifact_native().
|
static |
Definition at line 469 of file pharos_runtime.c.
References capture_execv_output_native(), copy_directory_recursive(), dev_docs_directory_index_html_native(), path_dirname(), path_exists(), path_is_directory(), path_join(), pharos_unlink, read_file_text(), remove_directory_recursive(), and write_text_file().
Referenced by build_app_from_root_native().
|
static |
Definition at line 287 of file pharos_runtime.c.
Referenced by emit_website_status_native(), handle_native_website_command(), and resolve_website_root().
|
static |
Definition at line 2580 of file pharos_runtime.c.
References WorkerContext::app, clone_app_runtime_native(), WorkerContext::connection, native_connection_close(), native_connection_init(), and WorkerContext::request.
Referenced by serve_runtime_stack_native(), and serve_single_app().
|
static |
Definition at line 253 of file pharos_runtime.c.
References global_listener_state, and native_listener_cleanup_active().
Referenced by pharos_native_shutdown_signal_handler(), serve_runtime_stack_native(), serve_single_app(), and serve_static_root().
|
static |
Definition at line 249 of file pharos_runtime.c.
References global_listener_state, and native_listener_state_init().
Referenced by serve_runtime_stack_native(), serve_single_app(), and serve_static_root().
|
static |
Definition at line 437 of file pharos_runtime.c.
Referenced by build_dev_docs_directory_native().
|
static |
Definition at line 3393 of file pharos_runtime.c.
Referenced by handle_native_backup_restore_ops_command(), handle_native_deploy_check_ops_command(), and handle_native_drift_check_ops_command().
|
static |
Definition at line 1332 of file pharos_runtime.c.
References read_file_text().
Referenced by handle_native_runtime_command().
|
static |
Definition at line 308 of file pharos_runtime.c.
References build_known_website_native(), build_native_website_status_report_json(), native_website_artifact_dir(), native_website_report_path(), path_exists(), path_join(), and write_text_file().
Referenced by handle_native_website_command().
|
static |
Definition at line 1180 of file pharos_runtime.c.
References current_working_directory(), path_canonicalize(), path_dirname(), path_join(), and pharos_strdup.
Referenced by find_repo_root(), and main().
|
static |
Definition at line 1207 of file pharos_runtime.c.
References current_working_directory(), executable_dir_from_argv0(), path_canonicalize(), path_dirname(), path_exists(), path_join(), and streq().
Referenced by main().
|
static |
Definition at line 2864 of file pharos_runtime.c.
References serve_runtime_stack_native(), serve_single_app(), serve_website_target(), and streq().
Referenced by handle_serve().
|
static |
Release a worker context and every owned request/runtime resource.
| context | Per-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().
|
static |
Definition at line 1797 of file pharos_runtime.c.
References WorkerContext::app, AppRuntime::app_id, AppRuntime::artifact_dir, AppRuntime::base_path, AppRuntime::compiled_entrypoint, WorkerContext::connection, AppRuntime::error_report_path, AppRuntime::host_profile, http_status_code_from_response_native(), http_status_line_from_response_native(), AppRuntime::log_path, HttpRequest::method, native_connection_write(), native_dynamic_runtime_handle_request(), native_request_target_for_mount(), native_send_text_response(), native_serve_static_file(), native_write_access_log(), native_write_error_log(), pharos_strdup, WorkerContext::request, spawn_app_request(), streq(), and HttpRequest::target.
Referenced by process_worker_context_native().
|
static |
Definition at line 3401 of file pharos_runtime.c.
References build_native_backup_report_local_json(), build_native_restore_report_local_json(), emit_native_report_json(), free_app_runtime(), free_serve_config_native(), native_option_value(), prepare_native_app_ops_runtime(), and streq().
Referenced by handle_native_ops_command().
|
static |
Definition at line 3458 of file pharos_runtime.c.
References build_native_app_deploy_check_report_local_json(), emit_native_report_json(), free_app_runtime(), free_serve_config_native(), global_repo_root, PHAROS_TARGET_ID, and prepare_native_app_ops_runtime().
Referenced by handle_native_ops_command().
|
static |
Definition at line 3287 of file pharos_runtime.c.
References apply_deb_package_option_native(), global_repo_root, json_string_dup_native(), path_join(), run_process_capture_native(), and trim_in_place().
Referenced by handle_native_ops_command().
|
static |
Definition at line 3437 of file pharos_runtime.c.
References build_native_app_drift_report_local_json(), emit_native_report_json(), free_app_runtime(), free_serve_config_native(), global_repo_root, and prepare_native_app_ops_runtime().
Referenced by handle_native_ops_command().
|
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().
|
static |
Definition at line 3529 of file pharos_runtime.c.
References handle_native_backup_restore_ops_command(), handle_native_deploy_check_ops_command(), handle_native_deploy_package_deb_command(), handle_native_drift_check_ops_command(), and match_native_ops_command().
Referenced by main().
|
static |
Definition at line 3012 of file pharos_runtime.c.
References ServeConfig::app_dir, AppRuntime::app_id, AppRuntime::base_path, ServeConfig::base_path, build_native_app_build_report_json(), build_native_app_doctor_report_local_json(), build_native_app_runtime_report_json(), AppRuntime::compiled_entrypoint, AppRuntime::debug, AppRuntime::error_report_path, finalize_loaded_app_runtime_native(), find_app_root_for_target(), free_app_runtime(), global_binary_dir, global_repo_root, AppRuntime::host_profile, load_app_runtime_from_artifact_native(), AppRuntime::log_format, AppRuntime::log_path, maybe_seed_app_state_native(), native_app_runtime_report_id(), PHAROS_TARGET_ID, prepare_app_artifact_native(), runtime_build_dir_override_native(), ServeConfig::seed_state, ServeConfig::state_dir, AppRuntime::state_path, ServeConfig::state_path, streq(), ServeConfig::target_id, and write_text_file().
Referenced by handle_native_runtime_command().
|
static |
Definition at line 3132 of file pharos_runtime.c.
References ServeConfig::build_dir, build_native_runtime_build_report_json(), build_native_runtime_status_report_json(), ServeConfig::conf_path, RuntimeStack::count, emit_text_file_to_stdout_native(), free_runtime_stack(), free_serve_config_native(), handle_native_runtime_app_command(), ServeConfig::kind, load_runtime_stack(), native_website_report_path(), parse_serve_config_native(), runtime_apps_dir_native(), runtime_verb_supported_native(), streq(), ServeConfig::target_id, and write_text_file().
Referenced by main().
|
static |
Definition at line 2931 of file pharos_runtime.c.
References build_known_website_native(), emit_website_status_native(), native_known_website_supported(), read_file_text(), streq(), and website_verb_mode_native().
Referenced by main().
|
static |
Definition at line 2882 of file pharos_runtime.c.
References apply_serve_config_defaults_from_conf_native(), find_serve_handler_native(), free_serve_config_native(), ServeConfig::kind, parse_serve_config_native(), print_help(), ServeConfig::root, serve_static_root(), and ServeConfig::target_id.
Referenced by main().
|
static |
Definition at line 2598 of file pharos_runtime.c.
References native_send_text_response(), PHAROS_TARGET_ID, PHAROS_VERSION, and HttpRequest::target.
Referenced by serve_static_root().
|
static |
Definition at line 268 of file pharos_runtime.c.
References pharos_native_shutdown_signal_handler().
Referenced by main().
|
static |
Definition at line 1454 of file pharos_runtime.c.
References ServeConfig::app_dir, ServeConfig::base_path, ServeConfig::build_dir, effective_app_build_dir_native(), finalize_loaded_app_runtime_native(), find_app_root_for_target(), free_app_local_config_native(), free_app_runtime(), global_binary_dir, global_repo_root, json_find_string(), json_find_string_in_section(), load_app_local_config_native(), load_app_runtime_from_artifact_native(), AppLocalConfigNative::manifest_build_artifact_dir, maybe_seed_app_state_native(), path_canonicalize(), path_join(), pharos_strdup, prepare_app_artifact_native(), read_file_text(), shell_status_or_build_native(), ServeConfig::state_dir, ServeConfig::state_path, streq(), and ServeConfig::target_id.
Referenced by serve_single_app().
|
static |
Definition at line 1674 of file pharos_runtime.c.
References add_runtime_app_native(), ServeConfig::base_path, ServeConfig::build_dir, conf_lookup_value(), ServeConfig::conf_path, RuntimeStack::count, current_working_directory(), RuntimeStack::host, ServeConfig::host, json_find_string(), MAX_APPS, path_dirname(), path_exists(), path_is_directory(), path_join(), RuntimeStack::port, ServeConfig::port, read_file_text(), resolve_relative_to(), resolve_runtime_socket_path_native(), resolve_value_or_default(), RuntimeStack::socket_path, ServeConfig::state_dir, ServeConfig::state_path, and streq().
Referenced by handle_native_runtime_command(), and serve_runtime_stack_native().
| int main | ( | int | argc, |
| char ** | argv ) |
Native Pharos CLI entrypoint.
The runtime resolves the repository and binary roots, dispatches command families, and starts the native serving path when requested.
Definition at line 3565 of file pharos_runtime.c.
References exec_runtime_script_native(), executable_dir_from_argv0(), find_repo_root(), global_binary_dir, global_repo_root, handle_native_barcode_command(), handle_native_json_command(), handle_native_noindex_command(), handle_native_ops_command(), handle_native_runtime_command(), handle_native_website_command(), handle_serve(), install_native_signal_handlers(), print_help(), and print_version().
|
static |
Definition at line 3485 of file pharos_runtime.c.
References streq().
Referenced by handle_native_ops_command().
|
static |
Definition at line 1388 of file pharos_runtime.c.
References ServeConfig::base_path, capture_execv_output_env_native(), ServeConfig::conf_path, effective_app_base_path_native(), effective_app_state_path_native(), global_binary_dir, path_exists(), path_join(), resolve_seed_entrypoint_native(), runtime_build_dir_override_native(), ServeConfig::seed_state, ServeConfig::state_dir, and ServeConfig::state_path.
Referenced by add_runtime_app_native(), handle_native_runtime_app_command(), and load_app_runtime_for_single_app().
|
static |
Definition at line 2991 of file pharos_runtime.c.
References streq().
Referenced by handle_native_runtime_app_command().
|
static |
Clamp one size value into an inclusive range.
| value | Candidate value. |
| minimum | Inclusive lower bound. |
| maximum | Inclusive upper bound. |
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().
|
static |
Read the configured positive size value for one runtime key.
| runtime_conf_path | Runtime configuration path. |
| key | Config key to read. |
| value_out | Parsed positive value on success. |
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().
|
static |
Resolve the default queue capacity from physical memory.
Definition at line 2087 of file pharos_runtime.c.
References native_clamp_size_value(), native_detect_physical_memory_bytes(), PHAROS_NATIVE_DEFAULT_WORK_QUEUE_CAPACITY, PHAROS_NATIVE_MAX_WORK_QUEUE_CAPACITY, PHAROS_NATIVE_MIN_WORK_QUEUE_CAPACITY, and PHAROS_NATIVE_WORK_QUEUE_BYTES_PER_SLOT.
Referenced by native_resolved_work_queue_capacity().
|
static |
Resolve the default worker-thread count when config does not override it.
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().
|
static |
Detect total physical memory visible to the current host.
Definition at line 2032 of file pharos_runtime.c.
Referenced by native_default_work_queue_capacity().
|
static |
Definition at line 2539 of file pharos_runtime.c.
Referenced by accept_http_request_native().
|
static |
Definition at line 2522 of file pharos_runtime.c.
Referenced by accept_http_request_native().
|
static |
Definition at line 282 of file pharos_runtime.c.
Referenced by handle_native_website_command(), and resolve_website_root().
|
static |
Definition at line 3252 of file pharos_runtime.c.
References streq().
Referenced by handle_native_backup_restore_ops_command().
|
static |
Parse one positive size_t from config text.
| text | Raw config value text. |
| value_out | Parsed positive value on success. |
Definition at line 1989 of file pharos_runtime.c.
Referenced by native_conf_positive_size_value().
|
static |
Resolve the bounded queued-request capacity for one serve process.
| runtime_conf_path | Runtime configuration path to consult for overrides. |
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().
|
static |
Resolve the fixed worker-thread count for one serve process.
| runtime_conf_path | Runtime configuration path to consult for overrides. |
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().
|
static |
Send the standard overload response for saturated native serving.
| connection | Accepted 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().
|
static |
Destroy worker-pool resources after shutdown and join.
| pool | Worker pool to destroy. |
Definition at line 2392 of file pharos_runtime.c.
References NativeWorkerPool::capacity, NativeWorkerPool::count, free_worker_context_native(), NativeWorkerPool::head, NativeWorkerPool::items, NativeWorkerPool::mutex, NativeWorkerPool::not_empty, and NativeWorkerPool::threads.
Referenced by native_worker_pool_init(), serve_runtime_stack_native(), and serve_single_app().
|
static |
Submit accepted request work to the bounded worker pool.
| pool | Active worker pool. |
| context | Per-request work item to enqueue. |
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().
|
static |
Initialize a bounded worker pool for native request serving.
| pool | Pool state to initialize. |
| worker_count | Fixed number of worker threads to create. |
| capacity | Maximum queued requests. |
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().
|
static |
Join all worker threads created for the pool.
| pool | Active 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().
|
static |
Ask the worker pool to stop after draining queued work.
| pool | Active 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().
|
static |
Run queued request work items until the worker pool shuts down.
| opaque | Active worker pool. |
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().
|
static |
Definition at line 3365 of file pharos_runtime.c.
References free_serve_config_native(), ServeConfig::kind, parse_serve_config_native(), streq(), and ServeConfig::target_id.
Referenced by prepare_native_app_ops_runtime().
|
static |
Definition at line 262 of file pharos_runtime.c.
References cleanup_active_listener(), and global_shutdown_requested.
Referenced by install_native_signal_handlers().
|
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.
| app_root | Filesystem path to the app root. |
| app_id | Application identifier. |
| build_dir_override | Build directory override (may be NULL). |
| state_dir_override | State directory override (may be NULL). |
| state_path_override | State file override (may be NULL). |
| base_path_override | URL base-path override (may be NULL). |
| report_path_out | Receives the build report path (may be NULL). |
| artifact_dir_out | Receives the artifact directory on success. |
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().
|
static |
Definition at line 3201 of file pharos_runtime.c.
References ServeConfig::app_dir, ServeConfig::base_path, ServeConfig::build_dir, effective_app_build_dir_native(), finalize_loaded_app_runtime_native(), find_app_root_for_target(), free_app_runtime(), global_binary_dir, global_repo_root, load_app_runtime_from_artifact_native(), prepare_app_artifact_native(), ServeConfig::state_dir, ServeConfig::state_path, and ServeConfig::target_id.
Referenced by prepare_native_app_ops_runtime().
|
static |
Definition at line 3374 of file pharos_runtime.c.
References free_serve_config_native(), parse_native_app_ops_config(), and prepare_finalized_app_from_config().
Referenced by handle_native_backup_restore_ops_command(), handle_native_deploy_check_ops_command(), and handle_native_drift_check_ops_command().
|
static |
Definition at line 2466 of file pharos_runtime.c.
Referenced by handle_serve(), and main().
|
static |
Definition at line 2462 of file pharos_runtime.c.
References PHAROS_TARGET_ID, and PHAROS_VERSION.
Referenced by main().
|
static |
Execute one accepted request through the active runtime/app handler.
| context | Per-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().
|
static |
Definition at line 257 of file pharos_runtime.c.
References global_listener_state, global_shutdown_requested, native_listener_register_cleanup(), and PHAROS_SOCKET.
Referenced by serve_runtime_stack_native(), serve_single_app(), and serve_static_root().
|
static |
Definition at line 1314 of file pharos_runtime.c.
References conf_lookup_value(), pharos_strdup, resolve_relative_to(), and ServeConfig::socket_path.
Referenced by load_runtime_stack().
|
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().
|
static |
Definition at line 1293 of file pharos_runtime.c.
References pharos_strdup.
Referenced by load_runtime_stack().
|
static |
Definition at line 1654 of file pharos_runtime.c.
References ServeConfig::build_dir, build_known_website_native(), global_repo_root, json_find_string(), native_known_website_supported(), shell_status_or_build_native(), and ServeConfig::target_id.
Referenced by serve_website_target().
|
static |
Definition at line 378 of file pharos_runtime.c.
References app_build_dir_local_native(), ServeConfig::build_dir, global_repo_root, path_join(), and pharos_strdup.
Referenced by add_runtime_app_native(), handle_native_runtime_app_command(), and maybe_seed_app_state_native().
|
static |
Definition at line 2978 of file pharos_runtime.c.
References streq().
Referenced by handle_native_runtime_command().
|
static |
Definition at line 2729 of file pharos_runtime.c.
References accept_http_request_native(), build_worker_context_native(), cleanup_active_listener(), clear_listener_cleanup_registration(), ServeConfig::conf_path, WorkerContext::connection, free_http_request_native(), free_runtime_stack(), free_worker_context_native(), load_runtime_stack(), native_connection_close(), native_connection_init(), native_listener_open(), native_request_path_without_query(), native_resolved_work_queue_capacity(), native_resolved_worker_count(), native_send_text_response(), native_send_worker_pool_overload_response(), native_worker_pool_destroy(), native_worker_pool_enqueue(), native_worker_pool_init(), native_worker_pool_join(), native_worker_pool_request_shutdown(), PHAROS_SOCKET, register_listener_cleanup(), runtime_apps_dir_native(), runtime_apps_fingerprint_native(), runtime_log_banner_native(), runtime_match_app_native(), and HttpRequest::target.
Referenced by find_serve_handler_native().
|
static |
Definition at line 2653 of file pharos_runtime.c.
References accept_http_request_native(), AppRuntime::app_id, build_worker_context_native(), cleanup_active_listener(), clear_listener_cleanup_registration(), ServeConfig::conf_path, WorkerContext::connection, free_app_runtime(), free_http_request_native(), free_worker_context_native(), load_app_runtime_for_single_app(), native_connection_close(), native_connection_init(), native_listener_endpoint(), native_listener_open(), native_resolved_work_queue_capacity(), native_resolved_worker_count(), native_send_text_response(), native_send_worker_pool_overload_response(), native_worker_pool_destroy(), native_worker_pool_enqueue(), native_worker_pool_init(), native_worker_pool_join(), native_worker_pool_request_shutdown(), PHAROS_SOCKET, register_listener_cleanup(), AppRuntime::runtime_conf_path, and ServeConfig::target_id.
Referenced by find_serve_handler_native().
|
static |
Definition at line 2612 of file pharos_runtime.c.
References accept_http_request_native(), cleanup_active_listener(), clear_listener_cleanup_registration(), free_http_request_native(), handle_static_root_builtin_request(), ServeConfig::log_path, HttpRequest::method, native_connection_close(), native_connection_init(), native_listener_endpoint(), native_listener_open(), native_send_text_response(), native_serve_static_file(), PHAROS_SOCKET, register_listener_cleanup(), ServeConfig::root, starts_with(), and HttpRequest::target.
Referenced by handle_serve(), and serve_website_target().
|
static |
Definition at line 2850 of file pharos_runtime.c.
References resolve_website_root(), ServeConfig::root, and serve_static_root().
Referenced by find_serve_handler_native().
|
static |
Definition at line 1581 of file pharos_runtime.c.
References HttpRequest::body, HttpRequest::body_file_path, HttpRequest::body_len, build_native_app_request_argv(), capture_execv_output_split_env_native(), cleanup_native_temp_body_file(), HttpRequest::content_type, HttpRequest::cookie, global_binary_dir, HttpRequest::headers, HttpRequest::is_multipart, HttpRequest::method, PHAROS_APP_REQUEST_ARGV_CAPACITY, pharos_strdup, AppRuntime::runtime_conf_path, HttpRequest::target, and write_native_temp_body_file().
Referenced by handle_app_or_runtime_request().
|
static |
Definition at line 2913 of file pharos_runtime.c.
References streq().
Referenced by handle_native_website_command().
|
static |
Recursively write macOS no-index markers through a directory tree.
| root_path | Directory tree to mark. |
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().
|
static |
Definition at line 245 of file pharos_runtime.c.
Referenced by handle_native_runtime_app_command(), load_app_runtime_for_single_app(), main(), maybe_seed_app_state_native(), prepare_finalized_app_from_config(), and spawn_app_request().
|
static |
Definition at line 247 of file pharos_runtime.c.
Referenced by cleanup_active_listener(), clear_listener_cleanup_registration(), and register_listener_cleanup().
|
static |
Definition at line 244 of file pharos_runtime.c.
Referenced by handle_native_deploy_check_ops_command(), handle_native_deploy_package_deb_command(), handle_native_drift_check_ops_command(), handle_native_runtime_app_command(), load_app_runtime_for_single_app(), main(), prepare_finalized_app_from_config(), resolve_website_root(), and runtime_build_dir_override_native().
|
static |
Definition at line 246 of file pharos_runtime.c.
Referenced by accept_http_request_native(), pharos_native_shutdown_signal_handler(), and register_listener_cleanup().