[cvs] bogofilter/src datastore_db.c,1.202,1.203
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: David R. <re...@us...> - 2005-04-21 22:36:29
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24757 Modified Files: datastore_db.c Log Message: Refactor dbe_init and checkpath functions. Index: datastore_db.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/datastore_db.c,v retrieving revision 1.202 retrieving revision 1.203 diff -u -d -r1.202 -r1.203 --- datastore_db.c 11 Apr 2005 19:06:33 -0000 1.202 +++ datastore_db.c 21 Apr 2005 22:36:19 -0000 1.203 @@ -276,36 +276,24 @@ return; } -static bool checkpath(const char *path, char *norm) +/* Ensure that only a single database environment is specified */ +static bool check_path(bfpath *bfp) { - if (realpath(path, norm) != NULL) - return true; - else { + const char *t; + char norm_dir[PATH_MAX+1]; /* check normalized directory names */ + static char norm_home[PATH_MAX+1];/* see man realpath(3) for details */ + + if (realpath(t = bfp->dirname, norm_dir) == NULL || + realpath(t = bogohome, norm_home) == NULL) { print_error(__FILE__, __LINE__, "error: cannot normalize path \"%s\": %s", - path, strerror(errno)); - return false; + t, strerror(errno)); + return true; } -} - -/** Initialize data base, configure some lock table sizes - * (which can be overridden in the DB_CONFIG file) - * and lock the file to tell other parts we're initialized and - * do not want recovery to stomp over us. - */ -void *dbe_init(bfpath *bfp) -{ - char norm_dir[PATH_MAX+1]; /* check normalized directory names */ - char norm_home[PATH_MAX+1];/* see man realpath(3) for details */ - dbe_t *env; - - if ( !checkpath(bfp->dirname, norm_dir) || - !checkpath(bogohome, norm_home)) - exit(EX_ERROR); - - if (strcmp(norm_dir, norm_home) != 0) - { + if (strcmp(norm_dir, norm_home) == 0) + return true; + else { fprintf(stderr, "ERROR: only one database _environment_ (directory) can be used at a time.\n" "You CAN use multiple wordlists that are in the same directory.\n\n"); @@ -318,8 +306,21 @@ "Please accept our apologies for the inconvenience.\n"); fprintf(stderr, "\nAborting program\n"); - exit(EX_ERROR); + return false; } +} + +/** Initialize data base, configure some lock table sizes + * (which can be overridden in the DB_CONFIG file) + * and lock the file to tell other parts we're initialized and + * do not want recovery to stomp over us. + */ +void *dbe_init(bfpath *bfp) +{ + dbe_t *env; + + if (!check_path(bfp)) + exit(EX_ERROR); dsm_init(bfp); |