there is a problem with losing track of the server config when a unit is recompiled for a second time

This commit is contained in:
Udo Schroeter
2021-11-17 11:57:25 +01:00
parent 3749077413
commit a02370ff68
8 changed files with 47 additions and 19 deletions
Binary file not shown.
+11 -7
View File
@@ -77,7 +77,8 @@ string process_html_literal(SharedUnit* su, string content)
string preprocess_shared_unit(SharedUnit* su) string preprocess_shared_unit(SharedUnit* su)
{ {
string content = file_get_contents(su->file_name); string content = file_get_contents(su->file_name);
string pc = "#include \""+context->server_state->config.COMPILER_SYS_PATH +"/src/lib/uce_gen.h\" \n"; printf("(c) compiling with root dir %s\n", context->server->config.COMPILER_SYS_PATH.c_str());
string pc = ("#include \"")+context->server->config.COMPILER_SYS_PATH +"/src/lib/uce_gen.h\" \n";
string token = ""; string token = "";
string html_buffer = ""; string html_buffer = "";
u8 mode = 0; u8 mode = 0;
@@ -144,8 +145,8 @@ void setup_unit_paths(SharedUnit* su, string file_name)
return; return;
su->src_path = dirname(file_name); su->src_path = dirname(file_name);
su->bin_path = context->server_state->config.BIN_DIRECTORY + su->src_path; su->bin_path = context->server->config.BIN_DIRECTORY + su->src_path;
su->pre_path = context->server_state->config.BIN_DIRECTORY + su->src_path; su->pre_path = context->server->config.BIN_DIRECTORY + su->src_path;
su->src_file_name = basename(file_name); su->src_file_name = basename(file_name);
su->bin_file_name = su->src_file_name + ".so"; su->bin_file_name = su->src_file_name + ".so";
@@ -202,7 +203,7 @@ void compile_shared_unit(SharedUnit* su, string file_name)
printf("Config.COMPILE_SCRIPT %s\n", string(su->pre_path + "/" + su->pre_file_name).c_str()); printf("Config.COMPILE_SCRIPT %s\n", string(su->pre_path + "/" + su->pre_file_name).c_str());
su->compiler_messages = trim(shell_exec(context->server_state->config.COMPILE_SCRIPT+" "+ su->compiler_messages = trim(shell_exec(context->server->config.COMPILE_SCRIPT+" "+
shell_escape(su->src_path)+" "+ shell_escape(su->src_path)+" "+
shell_escape(su->bin_path)+" "+ shell_escape(su->bin_path)+" "+
shell_escape(su->file_name)+" "+ shell_escape(su->file_name)+" "+
@@ -223,7 +224,7 @@ void compile_shared_unit(SharedUnit* su, string file_name)
SharedUnit* get_shared_unit(string file_name) SharedUnit* get_shared_unit(string file_name)
{ {
SharedUnit* su = context->server_state->units[file_name]; SharedUnit* su = context->server->units[file_name];
auto mod_time = file_mtime(file_name); auto mod_time = file_mtime(file_name);
bool do_recompile = false; bool do_recompile = false;
if(su && (su->last_compiled < mod_time || mod_time == 0)) if(su && (su->last_compiled < mod_time || mod_time == 0))
@@ -247,13 +248,14 @@ SharedUnit* get_shared_unit(string file_name)
compile_shared_unit(su, file_name); compile_shared_unit(su, file_name);
} }
context->server_state->units[file_name] = su; context->server->units[file_name] = su;
} }
return(su); return(su);
} }
void invoke(string file_name) void compiler_invoke(string file_name)
{ {
printf("(i) invoke %s\n", file_name.c_str());
if(file_name[0] != '/') if(file_name[0] != '/')
{ {
file_name = expand_path(file_name); file_name = expand_path(file_name);
@@ -283,3 +285,5 @@ void invoke(string file_name)
} }
} }
} }
invoke_handler invoke;
+1
View File
@@ -162,5 +162,6 @@ void on_segfault(int sig) {
// print out all the frames to stderr // print out all the frames to stderr
fprintf(stderr, "SEG FAULT: %d:\n", sig); fprintf(stderr, "SEG FAULT: %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO); backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
} }
+4 -2
View File
@@ -58,7 +58,7 @@ struct ServerSettings {
string SOCKET_PATH = "/run/uce.sock"; string SOCKET_PATH = "/run/uce.sock";
string TMP_UPLOAD_PATH = "/tmp/uce/uploads"; string TMP_UPLOAD_PATH = "/tmp/uce/uploads";
string SESSION_PATH = "/tmp/uce/sessions"; string SESSION_PATH = "/tmp/uce/sessions";
string COMPILER_SYS_PATH = ""; string COMPILER_SYS_PATH = ".";
u32 LISTEN_PORT = 9993; u32 LISTEN_PORT = 9993;
u64 SESSION_TIME = 60*60*24*30; u64 SESSION_TIME = 60*60*24*30;
@@ -108,7 +108,7 @@ struct ServerState {
struct Request { struct Request {
ServerState* server_state; ServerState* server;
StringMap params; StringMap params;
StringMap get; StringMap get;
@@ -130,6 +130,8 @@ struct Request {
f64 time_start; f64 time_start;
f64 time_end; f64 time_end;
invoke_handler invoke;
void print(string s) void print(string s)
{ {
out.append(s); out.append(s);
+1
View File
@@ -14,6 +14,7 @@ Request* context;
extern "C" void set_current_request(Request* _request) extern "C" void set_current_request(Request* _request)
{ {
context = _request; context = _request;
invoke = _request->invoke;
signal(SIGSEGV, on_segfault); signal(SIGSEGV, on_segfault);
} }
+5 -5
View File
@@ -120,7 +120,7 @@ StringMap parse_multipart(string q, string boundary, std::vector<UploadedFile>&
{ {
nibble("=\"", field); nibble("=\"", field);
UploadedFile f; UploadedFile f;
f.tmp_name = context->server_state->config.TMP_UPLOAD_PATH + std::to_string(rand()); f.tmp_name = context->server->config.TMP_UPLOAD_PATH + std::to_string(rand());
f.file_name = nibble("\"", field); f.file_name = nibble("\"", field);
string bin = field.substr(4, field.length()-6); string bin = field.substr(4, field.length()-6);
f.size = bin.length(); f.size = bin.length();
@@ -285,19 +285,19 @@ string make_session_id()
StringMap load_session_data(string session_id) StringMap load_session_data(string session_id)
{ {
return(parse_query(file_get_contents(context->server_state->config.SESSION_PATH + "/" + session_id))); return(parse_query(file_get_contents(context->server->config.SESSION_PATH + "/" + session_id)));
} }
void save_session_data(string session_id, StringMap data) void save_session_data(string session_id, StringMap data)
{ {
file_put_contents(context->server_state->config.SESSION_PATH + "/" + session_id, encode_query(data)); file_put_contents(context->server->config.SESSION_PATH + "/" + session_id, encode_query(data));
} }
string session_start(string session_name = "uce-session") string session_start(string session_name = "uce-session")
{ {
if(context->cookies[session_name].length() == 0) if(context->cookies[session_name].length() == 0)
{ {
set_cookie(session_name, make_session_id(), time() + context->server_state->config.SESSION_TIME); set_cookie(session_name, make_session_id(), time() + context->server->config.SESSION_TIME);
} }
context->session_id = context->cookies[session_name]; context->session_id = context->cookies[session_name];
context->session_name = session_name; context->session_name = session_name;
@@ -309,7 +309,7 @@ void session_destroy(string session_name = "uce-session")
{ {
if(context->cookies[session_name].length() > 0) if(context->cookies[session_name].length() > 0)
{ {
set_cookie(session_name, "", time() - context->server_state->config.SESSION_TIME); set_cookie(session_name, "", time() - context->server->config.SESSION_TIME);
context->session.clear(); context->session.clear();
context->session_id = ""; context->session_id = "";
} }
+13 -5
View File
@@ -34,11 +34,13 @@ int handle_complete(FastCGIRequest& request) {
// The event handler can also be a class member function. This // The event handler can also be a class member function. This
// event occurs when the parameters and standard input streams are // event occurs when the parameters and standard input streams are
// both closed, and thus the request is complete. // both closed, and thus the request is complete.
context = &request; // printf("(i) request handle\n");
request.server_state = &server_state;
request.time_start = microtime();
request.header["Content-Type"] = context->server_state->config.CONTENT_TYPE; context = &request;
request.server = &server_state;
request.time_start = microtime();
request.invoke = compiler_invoke;
request.header["Content-Type"] = context->server->config.CONTENT_TYPE;
request.get = parse_query(request.params["QUERY_STRING"]); request.get = parse_query(request.params["QUERY_STRING"]);
if(request.params["HTTP_COOKIE"].length() > 0) if(request.params["HTTP_COOKIE"].length() > 0)
@@ -60,6 +62,7 @@ int handle_complete(FastCGIRequest& request) {
} }
} }
// printf("(i) request ready\n");
invoke(request.params["SCRIPT_FILENAME"]); invoke(request.params["SCRIPT_FILENAME"]);
string headers = string headers =
@@ -92,13 +95,18 @@ int main(int argc, char** argv)
signal(SIGSEGV, on_segfault); signal(SIGSEGV, on_segfault);
srand(time()); srand(time());
invoke = compiler_invoke;
// Set up our request handlers // Set up our request handlers
server.request_handler(&handle_request); server.request_handler(&handle_request);
server.data_handler(&handle_data); server.data_handler(&handle_data);
server.complete_handler(&handle_complete); server.complete_handler(&handle_complete);
if(server_state.config.COMPILER_SYS_PATH == "") //if(server_state.config.COMPILER_SYS_PATH == "")
server_state.config.COMPILER_SYS_PATH = get_cwd(); server_state.config.COMPILER_SYS_PATH = get_cwd();
printf("Compiler base path: %s\n", server_state.config.COMPILER_SYS_PATH.c_str());
server_state.config.BIN_DIRECTORY = server_state.config.BIN_DIRECTORY =
server_state.config.COMPILER_SYS_PATH + "/" + server_state.config.BIN_DIRECTORY; server_state.config.COMPILER_SYS_PATH + "/" + server_state.config.BIN_DIRECTORY;
server_state.config.COMPILE_SCRIPT = server_state.config.COMPILE_SCRIPT =
+12
View File
@@ -0,0 +1,12 @@
RENDER()
{
DTree t;
echo(json_encode(t));
echo(string("PATH: ") + context->server->config.COMPILER_SYS_PATH + "\n");
}