mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Create instance directory in "set" and "node start"
This commit is contained in:
parent
a338c2f0f9
commit
e87e80aee7
@ -216,6 +216,10 @@ int app_server_start(int argc,char **argv,struct command_line_option *o)
|
||||
/* Record instance path for easy access by whole process */
|
||||
thisinstancepath=strdup(instancepath);
|
||||
|
||||
/* Create the instance directory if it does not yet exist */
|
||||
if (create_serval_instance_dir() == -1)
|
||||
return -1;
|
||||
|
||||
/* Now that we know our instance path, we can ask for the default set of
|
||||
network interfaces that we will take interest in. */
|
||||
overlay_interface_args(confValueGet("interfaces",""));
|
||||
@ -242,7 +246,11 @@ int app_server_start(int argc,char **argv,struct command_line_option *o)
|
||||
*/
|
||||
rhizome_datastore_path=strdup(instancepath);
|
||||
rhizome_opendb();
|
||||
char *hlr_file = asprintf("%s/%s", instancepath, "hlr.dat");
|
||||
char *hlr_file;
|
||||
if (asprintf(&hlr_file, "%s/%s", instancepath, "hlr.dat") == -1) {
|
||||
fprintf(stderr,"ERROR: asprintf() failed\n");
|
||||
return -1;
|
||||
}
|
||||
hlr_size=atof(confValueGet("hlr_size","1"))*1048576;
|
||||
if (hlr_size<0) {
|
||||
fprintf(stderr,"HLR Size must be >0MB\n");
|
||||
@ -498,6 +506,9 @@ int app_server_set(int argc,char **argv,struct command_line_option *o)
|
||||
char *var=cli_arg(argc,argv,o,"variable","");
|
||||
char *val=cli_arg(argc,argv,o,"value","");
|
||||
|
||||
if (create_serval_instance_dir() == -1)
|
||||
return -1;
|
||||
|
||||
char conffile[1024];
|
||||
FILE *in;
|
||||
if (!FORM_SERVAL_INSTANCE_PATH(conffile, "serval.conf") ||
|
||||
|
21
dna.c
21
dna.c
@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
char *gatewayspec=NULL;
|
||||
|
||||
@ -303,6 +304,26 @@ int form_serval_instance_path(char *buf, size_t bufsiz, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int create_serval_instance_dir() {
|
||||
const char *instancepath = serval_instancepath();
|
||||
if (mkdir(instancepath, 0700) == -1) {
|
||||
if (errno == EEXIST) {
|
||||
DIR *d = opendir(instancepath);
|
||||
if (!d) {
|
||||
WHYF("Cannot access %s", instancepath);
|
||||
perror("opendir");
|
||||
return -1;
|
||||
}
|
||||
closedir(d);
|
||||
return 0;
|
||||
}
|
||||
WHYF("Cannot mkdir %s", instancepath);
|
||||
perror("mkdir");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void servalShutdownCleanly()
|
||||
{
|
||||
WHY("Shutting down as requested.");
|
||||
|
1
serval.h
1
serval.h
@ -987,6 +987,7 @@ int _memabuseCheck(const char *func,const char *file,const int line);
|
||||
char *thisinstancepath;
|
||||
char *serval_instancepath();
|
||||
int form_serval_instance_path(char * buf, size_t bufsiz, const char *path);
|
||||
int create_serval_instance_dir();
|
||||
|
||||
/* Handy statement for forming a path to an instance file in a char buffer whose declaration
|
||||
* is in scope (so that sizeof(buf) will work). Evaluates to true if the pathname fitted into
|
||||
|
Loading…
x
Reference in New Issue
Block a user