Skip to content

Commit

Permalink
runtimeserver: Add option for exiting when startup library loading fails
Browse files Browse the repository at this point in the history
Refs #62
  • Loading branch information
mhthies committed Dec 17, 2021
1 parent 478d7f2 commit a8fda68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/ov/include/ov_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct struct_ov_options {
int port;
OV_UINT dbSize;
char* libraries[MAX_STARTUP_LIBRARIES];
OV_BOOL librariesRequired;
int libcount;
char* logfile;
char* commandline_options;
Expand Down
8 changes: 8 additions & 0 deletions core/ov/source/ov_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void ov_options_init(ov_options* opts){
opts->servername = NULL;
opts->startup = TRUE;
memset(opts->libraries, 0, sizeof(opts->libraries));
opts->librariesRequired = FALSE;

#if TLSF_HEAP
opts->poolsize = 0;
Expand Down Expand Up @@ -961,6 +962,13 @@ OV_RESULT ov_readArgs(ov_options* opts, int argc, char** argv){
}
else ov_logfile_error("Too many libraries in start command and configfile.\n");
}
/*
* require startup libraries, i.e. exit and fail if loading one of them fails
*/
else if(!strcmp(argv[i], "--require-libs")) {
if(opts->ctx!=ov_runtimeserver) goto HELP;
opts->librariesRequired = TRUE;
}
/*
* exit immideately
*/
Expand Down
12 changes: 10 additions & 2 deletions core/runtimeserver/ov_runtimeserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ static void ov_server_usage(void)
"-i ID, --identify ID Set Ticket Identification for server access\n"
"-p PORT, --port-number PORT Set server port number\n"
"-w LIBRARY, --start-with LIBRARY Start server with library\n"
"--require-libs Exit immediately if loading one of the \n"
" specified libraries fails\n"
"-l LOGFILE, --logfile LOGFILE Set logfile name, you may use stdout"
#if OV_SYSTEM_NT
", stderr\n"
Expand Down Expand Up @@ -194,6 +196,7 @@ int main(int argc, char **argv) {
OV_RESULT result;
OV_ANY tempAny = {{OV_VT_VOID, {0}}, 0, {0,0}};
int exit_status = EXIT_SUCCESS;
OV_BOOL libraryLoadingFailed = FALSE;

ov_options opts;

Expand Down Expand Up @@ -512,6 +515,9 @@ int main(int argc, char **argv) {
else if(Ov_Fail(result)) {
ov_logfile_error("Could'nt create library %s: %s (error code 0x%4.4x).",
opts.libraries[i], ov_result_getresulttext(result), result);
if (opts.librariesRequired) {
libraryLoadingFailed = TRUE;
}
}
i++;
}
Expand All @@ -520,7 +526,7 @@ int main(int argc, char **argv) {
*/
if (!pdb->serverpassword) ov_vendortree_setserverpassword(opts.password);
ov_vendortree_setServerPID();
if(!opts.exit){
if(!opts.exit && !libraryLoadingFailed){
/*
* run server
*/
Expand Down Expand Up @@ -587,7 +593,9 @@ int main(int argc, char **argv) {
ov_vendortree_free();
ov_options_free(&opts);
ov_destroyHeap();
return exit_status;
// Exit with code 1 if either creating stripped KS server failed
// or loading a library failed (and opts.librariesRequired was given)
return exit_status || libraryLoadingFailed;
}

/* ---------------------------------------------------------------------- */
Expand Down

0 comments on commit a8fda68

Please sign in to comment.