Ensure that all output is flushed immediately.
authorMahlon E. Smith <mahlon@martini.nu>
Mon, 07 Nov 2011 10:43:06 -0800
changeset 16 e6a640ad2cc2
parent 15 2706fc514dea
child 17 bd746609ba46
Ensure that all output is flushed immediately. Fix free() bug for non-matching rules. When creating the rules cdb, make the tmpfile in the cwd instead of /tmp. Make regular expression matches case insensitive.
Makefile
db.c
process.c
util.c
--- a/Makefile	Sat Nov 05 12:52:29 2011 -0700
+++ b/Makefile	Mon Nov 07 10:43:06 2011 -0800
@@ -93,7 +93,7 @@
 	ctags *.h *.c
 
 clobber: clean
-	rm -f parser.c volta.cdb ChangeLog tags
+	rm -f parser.c volta.db ChangeLog tags
 
 clean:
 	-rm -f volta *_graph.* *.o *.prof*
--- a/db.c	Sat Nov 05 12:52:29 2011 -0700
+++ b/db.c	Mon Nov 07 10:43:06 2011 -0800
@@ -88,7 +88,7 @@
 
 	/* open temporary file */
 	debug( 0, LOC, "Creating/updating database (%s) using rules in \"%s\"\n", v.dbname, txt );
-	sprintf( tmpfile, "/tmp/volta-db-%d.tmp", getpid() );
+	sprintf( tmpfile, "volta-db-%d.tmp", getpid() );
 	if ( (tmp_fd = open( tmpfile,
 						 O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH )) == -1 ) {
 		debug( 0, LOC, "Error writing temporary file: %s\n", strerror(errno) );
@@ -131,7 +131,7 @@
 
 	/* move cdb into place */
 	if ( (rename( tmpfile, v.dbname )) == -1 ) {
-		debug( 1, LOC, "Unable to move temp cdb into place: %s", strerror(errno) );
+		debug( 0, LOC, "Unable to move temp cdb into place: %s", strerror(errno) );
 		return( 1 );
 	}
 
@@ -182,7 +182,7 @@
 		free( val );
 		if ( rule != NULL ) {
 			if ( check_rule( rule, p_request ) == 0 ) {
-				finish_parsed( rule );
+				finish_parsed( rule ), rule = NULL;
 			}
 			else {
 				break;
--- a/process.c	Sat Nov 05 12:52:29 2011 -0700
+++ b/process.c	Mon Nov 07 10:43:06 2011 -0800
@@ -108,6 +108,7 @@
 	printf( "%s", rule->path ? rule->path : request->path );
 
 	printf("\n");
+	fflush( stdout );
 	return;
 }
 
@@ -134,7 +135,7 @@
 	}
 
 	/* compile the regexp */
-	if ( (re_rv = regcomp( &re, rule->path_re, REG_EXTENDED | REG_NOSUB )) != 0 ) {
+	if ( (re_rv = regcomp( &re, rule->path_re, REG_EXTENDED | REG_NOSUB | REG_ICASE )) != 0 ) {
 		regerror( re_rv, &re, re_err, 128 );
 		debug( 4, LOC, "Invalid regex: \"%s\": %s\n", rule->path_re, re_err );
 		regfree( &re );
--- a/util.c	Sat Nov 05 12:52:29 2011 -0700
+++ b/util.c	Mon Nov 07 10:43:06 2011 -0800
@@ -75,6 +75,7 @@
 			 PROG, timestamp, getpid(), level, file, line );
 	vfprintf( stderr, fmt, args );
 	va_end( args );
+	fflush( stderr );
 
 	return;
 }
@@ -88,6 +89,7 @@
 {
 	if ( v.debugmode >= 5 ) return;
 	fprintf( stdout, "%s", str );
+	fflush( stdout );
 	return;
 }
 
@@ -164,6 +166,7 @@
 				v.timer.lines+1, (line_realloc == NULL ? strerror(errno) : "Line too large") );
 		free( line ), line = NULL;
 		printf( "\n" );
+		fflush( stdout );
 	}
 	else {
 		line = line_realloc;