db.c
changeset 16 e6a640ad2cc2
parent 15 2706fc514dea
child 17 bd746609ba46
equal deleted inserted replaced
15:2706fc514dea 16:e6a640ad2cc2
    86 	int  linenum = 0, parsed = 0;
    86 	int  linenum = 0, parsed = 0;
    87 	struct db_input *dbline;
    87 	struct db_input *dbline;
    88 
    88 
    89 	/* open temporary file */
    89 	/* open temporary file */
    90 	debug( 0, LOC, "Creating/updating database (%s) using rules in \"%s\"\n", v.dbname, txt );
    90 	debug( 0, LOC, "Creating/updating database (%s) using rules in \"%s\"\n", v.dbname, txt );
    91 	sprintf( tmpfile, "/tmp/volta-db-%d.tmp", getpid() );
    91 	sprintf( tmpfile, "volta-db-%d.tmp", getpid() );
    92 	if ( (tmp_fd = open( tmpfile,
    92 	if ( (tmp_fd = open( tmpfile,
    93 						 O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH )) == -1 ) {
    93 						 O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH )) == -1 ) {
    94 		debug( 0, LOC, "Error writing temporary file: %s\n", strerror(errno) );
    94 		debug( 0, LOC, "Error writing temporary file: %s\n", strerror(errno) );
    95 		return( 1 );
    95 		return( 1 );
    96 	}
    96 	}
   129 	cdb_make_finish( &cdbm );
   129 	cdb_make_finish( &cdbm );
   130 	close( tmp_fd );
   130 	close( tmp_fd );
   131 
   131 
   132 	/* move cdb into place */
   132 	/* move cdb into place */
   133 	if ( (rename( tmpfile, v.dbname )) == -1 ) {
   133 	if ( (rename( tmpfile, v.dbname )) == -1 ) {
   134 		debug( 1, LOC, "Unable to move temp cdb into place: %s", strerror(errno) );
   134 		debug( 0, LOC, "Unable to move temp cdb into place: %s", strerror(errno) );
   135 		return( 1 );
   135 		return( 1 );
   136 	}
   136 	}
   137 
   137 
   138 	debug( 0, LOC, "Added %d rules to %s.\n", parsed, v.dbname );
   138 	debug( 0, LOC, "Added %d rules to %s.\n", parsed, v.dbname );
   139 	return( 0 );
   139 	return( 0 );
   180 		debug( 4, LOC, "DB match for key '%s': %s\n", key, val );
   180 		debug( 4, LOC, "DB match for key '%s': %s\n", key, val );
   181 		rule = parse_rule( val );
   181 		rule = parse_rule( val );
   182 		free( val );
   182 		free( val );
   183 		if ( rule != NULL ) {
   183 		if ( rule != NULL ) {
   184 			if ( check_rule( rule, p_request ) == 0 ) {
   184 			if ( check_rule( rule, p_request ) == 0 ) {
   185 				finish_parsed( rule );
   185 				finish_parsed( rule ), rule = NULL;
   186 			}
   186 			}
   187 			else {
   187 			else {
   188 				break;
   188 				break;
   189 			}
   189 			}
   190 		}
   190 		}