Permalink
Browse files

Use a global verbose flag rather than a define

So it can be set at runtime by exporting an environment variable
(HTTPFS_VERBOSE=1); this allows to the release executable to dump logs too.
  • Loading branch information...
1 parent 737f171 commit 543e7bbe59739468b2c8d0214f140b16872c8dcb @cyrus-and committed Nov 15, 2012
Showing with 24 additions and 23 deletions.
  1. +2 −0 src/lib/debug.c
  2. +8 −15 src/lib/debug.h
  3. +2 −4 src/lib/generators.c
  4. +1 −3 src/lib/httpfs.c
  5. +1 −1 src/lib/templates/template.php
  6. +10 −0 src/main.c
View
@@ -1,6 +1,8 @@
#include <ctype.h>
#include "net.h"
+int HTTPFS_VERBOSE = 0;
+
void httpfs_dump_raw_data( struct raw_data *raw_data )
{
int i;
View
@@ -1,35 +1,28 @@
#ifndef _HTTPFS_DEBUG_H
#define _HTTPFS_DEBUG_H
-#ifndef NDEBUG
-
#include <stdio.h>
#include "net.h"
#define DEBUG_PREFIX ">>> "
#define LOG( string ) \
- do fprintf( stderr , DEBUG_PREFIX "%s\n" , string ); \
+ do if ( HTTPFS_VERBOSE ) fprintf( stderr , DEBUG_PREFIX "%s\n" , string ); \
while ( 0 )
#define LOGF( format , ... ) \
- do fprintf( stderr , DEBUG_PREFIX format "\n" , ##__VA_ARGS__ ); \
+ do if ( HTTPFS_VERBOSE ) fprintf( stderr , DEBUG_PREFIX format "\n" , ##__VA_ARGS__ ); \
while ( 0 )
#define DUMP_RAW_DATA( label , raw_data ) \
- do { fprintf( stderr , DEBUG_PREFIX "%s%lu byte: " , \
- label , raw_data.size ); \
- httpfs_dump_raw_data( &raw_data ); } \
+ do if ( HTTPFS_VERBOSE ) { \
+ fprintf( stderr , DEBUG_PREFIX "%s%lu byte: " , \
+ label , raw_data.size ); \
+ httpfs_dump_raw_data( &raw_data ); } \
while ( 0 )
-void httpfs_dump_raw_data( struct raw_data *raw_data );
-
-#else /* not DEBUG */
+extern int HTTPFS_VERBOSE;
-#define LOG( string ) do ; while ( 0 )
-#define LOGF( format , ... ) do ; while ( 0 )
-#define DUMP_RAW_DATA( label , raw_data ) do ; while ( 0 )
-
-#endif
+void httpfs_dump_raw_data( struct raw_data *raw_data );
#endif
@@ -48,10 +48,8 @@ void httpfs_generate_php()
*p , ( int )( p - HTTPFS_STATUS_NAMES ) );
}
-#ifndef NDEBUG
- /* debug mode */
- printf( "\ndefine( 'DEBUG' , TRUE );\n\n" );
-#endif
+ /* verbose mode */
+ if ( HTTPFS_VERBOSE ) printf( "\ndefine( 'VERBOSE' , TRUE );\n\n" );
printf( "\n?>" );
View
@@ -68,9 +68,7 @@ int httpfs_fuse_start( struct httpfs *httpfs ,
argc = 0;
argv[ argc++ ] = "httpfs";
argv[ argc++ ] = "-s"; /* single thread */
-#ifndef NDEBUG
- argv[ argc++ ] = "-d"; /* debug and core dump */
-#endif
+ if ( HTTPFS_VERBOSE ) argv[ argc++ ] = "-d"; /* debug and core dump */
argv[ argc++ ] = mount_point;
/* start loop */
@@ -1,7 +1,7 @@
<?php
error_reporting( 0 );
-if ( DEBUG ) set_error_handler( 'store_error' );
+if ( VERBOSE ) set_error_handler( 'store_error' );
/* UTILITY */
View
@@ -20,8 +20,18 @@ static void info()
fprintf( stderr , "httpfs " HTTPFS_VERSION "\n" );
}
+static void set_verbose_mode()
+{
+ char *env;
+
+ env = getenv( "HTTPFS_VERBOSE" );
+ if ( env && strcmp( env , "1" ) == 0 ) HTTPFS_VERBOSE = 1;
+}
+
int main( int argc , char *argv[] )
{
+ set_verbose_mode();
+
if ( argc == 2 && strcmp( argv[ 1 ] , "--version" ) == 0 )
{
info();

0 comments on commit 543e7bb

Please sign in to comment.