Remove carnal knowledge of conf.c from serval.h and commandline.c by providing a function to set the instance path override.

This commit is contained in:
Daniel O'Connor 2012-07-29 18:58:41 +09:30
parent c241d3630c
commit 09d0fecf28
4 changed files with 26 additions and 9 deletions

View File

@ -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 <exec path> 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");

10
conf.c
View File

@ -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)

2
conf.h
View File

@ -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);

View File

@ -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();