Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
Loading...
Searching...
No Matches
native_shell_bridge.c
Go to the documentation of this file.
1
/**
2
* @file
3
* @brief Invokes Pharos shell runtime, build, and status command surfaces for native callers.
4
*/
5
6
#include "
native_shell_bridge.h
"
7
8
#include "
native_process_capture.h
"
9
#include "
native_support.h
"
10
11
#include <stdio.h>
12
#include <stdlib.h>
13
#include <string.h>
14
15
#ifndef _WIN32
16
#include <unistd.h>
17
#endif
18
19
static
char
*
runtime_script_path_native
(
const
char
*repo_root) {
20
return
path_join
(repo_root,
"scripts/pharos_runtime.sh"
);
21
}
22
23
#ifndef _WIN32
24
#ifndef __wasm__
25
int
exec_runtime_script_native
(
const
char
*repo_root,
int
argc,
char
**argv) {
26
char
*script =
runtime_script_path_native
(repo_root);
27
char
**child_argv = (
char
**)calloc((
size_t
)argc + 1,
sizeof
(
char
*));
28
int
index;
29
if
(script == NULL || child_argv == NULL) {
30
free(script);
31
free(child_argv);
32
return
69;
33
}
34
child_argv[0] = script;
35
for
(index = 1; index < argc; index++) {
36
child_argv[index] = argv[index];
37
}
38
child_argv[argc] = NULL;
39
execv(script, child_argv);
40
perror(
"execv"
);
41
free(child_argv);
42
free(script);
43
return
69;
44
}
45
#else
46
int
exec_runtime_script_native
(
const
char
*repo_root,
int
argc,
char
**argv) {
47
(void)repo_root;
48
(void)argc;
49
(void)argv;
50
return
78;
51
}
52
#endif
53
#else
54
int
exec_runtime_script_native
(
const
char
*repo_root,
int
argc,
char
**argv) {
55
char
*script =
runtime_script_path_native
(repo_root);
56
char
command[16384];
57
int
offset = 0;
58
int
index;
59
if
(script == NULL) {
60
return
69;
61
}
62
offset += snprintf(command + offset,
sizeof
(command) - (
size_t
)offset,
"\"%s\""
, script);
63
for
(index = 1; index < argc && offset < (int)
sizeof
(command) - 4; index++) {
64
offset += snprintf(command + offset,
sizeof
(command) - (
size_t
)offset,
" \"%s\""
, argv[index]);
65
}
66
free(script);
67
return
system(command);
68
}
69
#endif
70
71
int
shell_runtime_command_capture_native
(
const
char
*repo_root,
int
argc,
char
*
const
argv[],
char
**output) {
72
char
*script =
runtime_script_path_native
(repo_root);
73
char
**argv_list;
74
int
index;
75
int
code;
76
if
(script == NULL) {
77
return
69;
78
}
79
argv_list = (
char
**)calloc((
size_t
)argc + 2,
sizeof
(
char
*));
80
if
(argv_list == NULL) {
81
free(script);
82
return
69;
83
}
84
argv_list[0] = script;
85
for
(index = 0; index < argc; index++) {
86
argv_list[index + 1] = argv[index];
87
}
88
argv_list[argc + 1] = NULL;
89
{
90
const
char
*env_keys[1] = {
"PHAROS_DISABLE_NATIVE_DELEGATION"
};
91
const
char
*env_values[1] = {
"1"
};
92
code =
capture_execv_output_env_native
(argv_list, env_keys, env_values, 1, output, NULL);
93
}
94
free(argv_list);
95
free(script);
96
return
code;
97
}
98
99
int
shell_status_or_build_native
(
const
char
*repo_root,
const
ServeConfig
*config,
int
use_build,
char
**output) {
100
char
*argv_list[31];
101
int
argc = 0;
102
argv_list[argc++] = use_build ?
"build"
:
"status"
;
103
argv_list[argc++] = config->
kind
;
104
argv_list[argc++] = config->
target_id
;
105
if
(config->
conf_path
!= NULL) {
106
argv_list[argc++] =
"--conf"
;
107
argv_list[argc++] = config->
conf_path
;
108
}
109
if
(config->
app_dir
!= NULL) {
110
argv_list[argc++] =
"--app-dir"
;
111
argv_list[argc++] = config->
app_dir
;
112
}
113
if
(config->
build_dir
!= NULL) {
114
argv_list[argc++] =
"--build-dir"
;
115
argv_list[argc++] = config->
build_dir
;
116
}
117
if
(config->
state_dir
!= NULL) {
118
argv_list[argc++] =
"--state-dir"
;
119
argv_list[argc++] = config->
state_dir
;
120
}
121
if
(config->
state_path
!= NULL) {
122
argv_list[argc++] =
"--state-path"
;
123
argv_list[argc++] = config->
state_path
;
124
}
125
if
(config->
base_path
!= NULL) {
126
argv_list[argc++] =
"--base-path"
;
127
argv_list[argc++] = config->
base_path
;
128
}
129
if
(config->
log_path
!= NULL) {
130
argv_list[argc++] =
"--log-path"
;
131
argv_list[argc++] = config->
log_path
;
132
}
133
if
(config->
debug
!= NULL) {
134
argv_list[argc++] =
"--debug"
;
135
argv_list[argc++] = config->
debug
;
136
}
137
argv_list[argc++] =
"--text"
;
138
argv_list[argc] = NULL;
139
return
shell_runtime_command_capture_native
(repo_root, argc, argv_list, output);
140
}
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.
Definition
native_process_capture.c:277
native_process_capture.h
Declares child-process capture helpers.
runtime_script_path_native
static char * runtime_script_path_native(const char *repo_root)
Definition
native_shell_bridge.c:19
exec_runtime_script_native
int exec_runtime_script_native(const char *repo_root, int argc, char **argv)
Executes the shared Pharos runtime script with the supplied arguments.
Definition
native_shell_bridge.c:25
shell_status_or_build_native
int shell_status_or_build_native(const char *repo_root, const ServeConfig *config, int use_build, char **output)
Runs the shell-side status or build flow for one native serve target.
Definition
native_shell_bridge.c:99
shell_runtime_command_capture_native
int shell_runtime_command_capture_native(const char *repo_root, int argc, char *const argv[], char **output)
Executes a runtime shell command and captures its combined output.
Definition
native_shell_bridge.c:71
native_shell_bridge.h
Declares bridge helpers for invoking Pharos shell command surfaces.
path_join
char * path_join(const char *left, const char *right)
Joins two path segments using the native path separator.
Definition
native_support.c:115
native_support.h
Declares shared low-level support helpers used across the Pharos native runtime.
ServeConfig
Parsed native serve configuration used to bootstrap the runtime listener.
Definition
native_runtime_types.h:16
ServeConfig::state_path
char * state_path
Definition
native_runtime_types.h:23
ServeConfig::log_path
char * log_path
Definition
native_runtime_types.h:25
ServeConfig::build_dir
char * build_dir
Definition
native_runtime_types.h:21
ServeConfig::app_dir
char * app_dir
Definition
native_runtime_types.h:20
ServeConfig::base_path
char * base_path
Definition
native_runtime_types.h:24
ServeConfig::conf_path
char * conf_path
Definition
native_runtime_types.h:19
ServeConfig::kind
char * kind
Definition
native_runtime_types.h:17
ServeConfig::debug
char * debug
Definition
native_runtime_types.h:26
ServeConfig::state_dir
char * state_dir
Definition
native_runtime_types.h:22
ServeConfig::target_id
char * target_id
Definition
native_runtime_types.h:18
src
native_runtime
c
native_shell_bridge.c
Generated by
1.17.0