mirror of
https://github.com/kakwa/uts-server
synced 2025-07-04 12:37:08 +02:00
passing the launch working dir to the configuration handler
as many configuration paths can be relative to the execution working directory, this directory is recorded at launch time, and the set_params function does a chdir(<start work dir>); <load conf>; chdir("/") when it's called.
This commit is contained in:
parent
93ead7ee99
commit
6e687f2fe2
5 changed files with 23 additions and 12 deletions
|
@ -128,15 +128,15 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int http_server_start(char *conffile, bool stdout_dbg) {
|
||||
int http_server_start(char *conffile, char * conf_wd, bool stdout_dbg) {
|
||||
struct mg_context *ctx;
|
||||
struct mg_callbacks callbacks;
|
||||
|
||||
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
|
||||
ct->stdout_dbg = stdout_dbg;
|
||||
ct->loglevel = 8;
|
||||
if (!set_params(ct, conffile))
|
||||
return 1;
|
||||
if (!set_params(ct, conffile, conf_wd))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Prepare callbacks structure. We have only one callback, the rest are
|
||||
// NULL.
|
||||
|
@ -146,8 +146,7 @@ int http_server_start(char *conffile, bool stdout_dbg) {
|
|||
ctx = mg_start(&callbacks, NULL, ct->http_options);
|
||||
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
|
||||
|
||||
// Wait until user hits "enter". Server is running in separate thread.
|
||||
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
||||
// Wait until some signals are received
|
||||
while ( g_uts_sig == 0 ){
|
||||
sleep(1);
|
||||
}
|
||||
|
|
|
@ -217,11 +217,13 @@ static CONF *load_config_file(rfc3161_context *ct, const char *filename) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int set_params(rfc3161_context *ct, char *conf_file) {
|
||||
int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd) {
|
||||
int ret = 0;
|
||||
CONF *conf = load_config_file(ct, conf_file);
|
||||
ret = 1;
|
||||
int http_counter = 0;
|
||||
|
||||
chdir(conf_wd);
|
||||
// first pass to set the loglevel as soon as possible
|
||||
for (int i = 0; i < RFC3161_OPTIONS_LEN; i++) {
|
||||
int type = rfc3161_options[i].type;
|
||||
|
@ -277,8 +279,10 @@ int set_params(rfc3161_context *ct, char *conf_file) {
|
|||
ct->ts_ctx = create_tsctx(ct, conf, NULL, NULL);
|
||||
if (ct->ts_ctx == NULL)
|
||||
ret = 0;
|
||||
chdir("/");
|
||||
return ret;
|
||||
|
||||
end:
|
||||
chdir("/");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue