From ec8a81c2063e7721dd1a555995a280398f53ff56 Mon Sep 17 00:00:00 2001 From: gardners Date: Mon, 5 Mar 2012 12:05:12 +1300 Subject: [PATCH] Rhizome now uses serval.conf to get rhizome database size limit. --- commandline.c | 5 ++++- rhizome_database.c | 24 ++++-------------------- serval.h | 1 + 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/commandline.c b/commandline.c index e18d2e35..92f15692 100644 --- a/commandline.c +++ b/commandline.c @@ -277,7 +277,10 @@ int app_server_stop(int argc,char **argv,struct command_line_option *o) switch (errno) { case EINVAL: WHY("This is embarassing, but the operating system says I don't know how to send a signal."); break; case EPERM: WHY("I don't have permission to stop the Serval process. You could try using sudo, or run the stop command as the appropriate user."); break; - case ESRCH: WHY("The process id I have recorded doesn't seem to exist anymore. Did someone kill the process without telling me?"); break; + case ESRCH: WHY("The process id I have recorded doesn't seem to exist anymore. Did someone kill the process without telling me?"); + /* Clean up any lingering mess */ + servalShutdownCleanly(); + break; default: perror("This is reason given by the operating system"); } diff --git a/rhizome_database.c b/rhizome_database.c index d3099c04..52b261ea 100644 --- a/rhizome_database.c +++ b/rhizome_database.c @@ -54,26 +54,10 @@ int rhizome_opendb() exit(1); } - /* Read Rhizome configuration, and write it back out as we understand it. */ - char conf[1024]; - snprintf(conf,1024,"%s/rhizome.conf",rhizome_datastore_path); - FILE *f=fopen(conf,"r"); - if (f) { - char line[1024]; - line[0]=0; fgets(line,1024,f); - while (line[0]) { - if (sscanf(line,"space=%lld",&rhizome_space)==1) { - rhizome_space*=1024; /* Units are kilobytes */ - } - line[0]=0; fgets(line,1024,f); - } - fclose(f); - } - f=fopen(conf,"w"); - if (f) { - fprintf(f,"space=%lld\n",rhizome_space/1024LL); - fclose(f); - } + /* Read Rhizome configuration */ + rhizome_space=1024LL*atof(confValueGet("rhizome_kb","1024")); + fprintf(stderr,"Rhizome will use %lldKB of storage for its database.\n", + rhizome_space/1024LL); /* Create tables if required */ if (sqlite3_exec(rhizome_db,"PRAGMA auto_vacuum=2;",NULL,NULL,NULL)) { diff --git a/serval.h b/serval.h index f087f109..35768e96 100644 --- a/serval.h +++ b/serval.h @@ -306,6 +306,7 @@ extern int hexdigit[16]; extern int sock; void servalShutdownCleanly(); +char *confValueGet(char *var,char *defaultValue); int recvwithttl(int sock,unsigned char *buffer,int bufferlen,int *ttl, struct sockaddr *recvaddr,unsigned int *recvaddrlen); int stowSid(unsigned char *packet,int ofs,char *sid);