diff --git a/commandline.c b/commandline.c index 3534606a..eea9688f 100644 --- a/commandline.c +++ b/commandline.c @@ -571,11 +571,14 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti break; } #endif - const char *execpath; + const char *execpath, *instancepath; int foregroundP = (argc >= 2 && !strcasecmp(argv[1], "foreground")); - if (cli_arg(argc, argv, o, "instance path", &thisinstancepath, cli_absolute_path, NULL) == -1 + if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1 || cli_arg(argc, argv, o, "exec path", &execpath, cli_absolute_path, NULL) == -1) return -1; + if (instancepath != NULL) + serval_setinstancepath(instancepath); + if (execpath == NULL) { if (jni_env) return WHY("Must supply argument when invoked via JNI"); @@ -682,9 +685,11 @@ int app_server_stop(int argc, const char *const *argv, struct command_line_optio long long timeout; struct timespec delay; - if (cli_arg(argc, argv, o, "instance path", &thisinstancepath, cli_absolute_path, NULL) == -1) + if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1) return WHY("Unable to determine instance path"); - + if (instancepath != NULL) + serval_setinstancepath(instancepath); + instancepath = serval_instancepath(); cli_puts("instancepath"); cli_delim(":"); @@ -746,10 +751,14 @@ int app_server_status(int argc, const char *const *argv, struct command_line_opt { if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); int pid; - - if (cli_arg(argc, argv, o, "instance path", &thisinstancepath, cli_absolute_path, NULL) == -1) + const char *instancepath; + + if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1) return WHY("Unable to determine instance path"); + if (instancepath != NULL) + serval_setinstancepath(instancepath); + pid = server_pid(); cli_puts("instancepath"); diff --git a/conf.c b/conf.c index 6c48983c..4820f2a9 100644 --- a/conf.c +++ b/conf.c @@ -422,7 +422,7 @@ int confWrite() return 0; } -const char *thisinstancepath = NULL; +static char *thisinstancepath = NULL; const char *serval_instancepath() { @@ -434,6 +434,14 @@ const char *serval_instancepath() return instancepath; } +void serval_setinstancepath(const char *instancepath) +{ + if (thisinstancepath == NULL) + free(thisinstancepath); + + thisinstancepath = strdup(instancepath); +} + int form_serval_instance_path(char *buf, size_t bufsiz, const char *path) { if (snprintf(buf, bufsiz, "%s/%s", serval_instancepath(), path) < bufsiz) diff --git a/conf.h b/conf.h index 1a5e4bc7..1a571137 100644 --- a/conf.h +++ b/conf.h @@ -50,4 +50,6 @@ int form_serval_instance_path(char *buf, size_t bufsiz, const char *path); const char *trimbuildpath(const char *s); int mkdirs(const char *path, mode_t mode); int mkdirsn(const char *path, size_t len, mode_t mode); +const char *serval_instancepath(); +void serval_setinstancepath(const char *instancepath); diff --git a/serval.h b/serval.h index 57b4525e..1c623688 100644 --- a/serval.h +++ b/serval.h @@ -837,8 +837,6 @@ int _memabuseCheck(const char *func,const char *file,const int line); #define memabuseCheck() /* */ #endif -const char *thisinstancepath; -const char *serval_instancepath(); int form_serval_instance_path(char * buf, size_t bufsiz, const char *path); int create_serval_instance_dir();