Create instance directory in "set" and "node start"

This commit is contained in:
Andrew Bettison 2012-03-29 15:03:17 +10:30
parent a338c2f0f9
commit e87e80aee7
4 changed files with 34 additions and 2 deletions

View File

@ -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
View File

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

View File

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

View File

@ -97,7 +97,6 @@ int recvwithttl(int sock,unsigned char *buffer,int bufferlen,int *ttl,
int server(char *backing_file,int size,int foregroundMode)
{
/* Get backing store for HLR */
getBackingStore(backing_file,size);