Add a --debug flag for DEBUG builds
If you compile with: DEBUG=true rake build then all the commands get a --debug flag as an option which will make the server dump crazy amounts of data to stderr.
This commit is contained in:
4
Rakefile
4
Rakefile
@@ -1,8 +1,6 @@
|
||||
require 'rake_utils/debian'
|
||||
include RakeUtils::DSL
|
||||
|
||||
DEBUG = true
|
||||
|
||||
ALL_SOURCES =FileList['src/*']
|
||||
SOURCES = ALL_SOURCES.select { |c| c =~ /\.c$/ }
|
||||
OBJECTS = SOURCES.pathmap( "%{^src,build}X.o" )
|
||||
@@ -14,7 +12,7 @@ LIBCHECK = "/usr/lib/libcheck.a"
|
||||
|
||||
TEST_MODULES = Dir["tests/check_*.c"].map { |n| n[12..-3] }
|
||||
|
||||
if DEBUG
|
||||
if ENV['DEBUG']
|
||||
LDFLAGS << ["-g"]
|
||||
CCFLAGS << ["-g -DDEBUG"]
|
||||
end
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static inline char char_with_bit_set(int num) { return 1<<(num%8); }
|
||||
|
||||
|
@@ -180,6 +180,9 @@ void read_serve_param( int c, char **ip_addr, char **ip_port, char **file, char
|
||||
case 's':
|
||||
*sock = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
set_debug(1);
|
||||
break;
|
||||
default:
|
||||
exit_err( serve_help_text );
|
||||
break;
|
||||
@@ -206,6 +209,9 @@ void read_readwrite_param( int c, char **ip_addr, char **ip_port, char **from, c
|
||||
case 'S':
|
||||
*size = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
set_debug(1);
|
||||
break;
|
||||
default:
|
||||
exit_err( read_help_text );
|
||||
break;
|
||||
@@ -222,6 +228,9 @@ void read_sock_param( int c, char **sock, char *help_text )
|
||||
case 's':
|
||||
*sock = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
set_debug(1);
|
||||
break;
|
||||
default:
|
||||
exit_err( help_text );
|
||||
break;
|
||||
@@ -249,6 +258,9 @@ void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port )
|
||||
case 'p':
|
||||
*ip_port = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
set_debug(1);
|
||||
break;
|
||||
default:
|
||||
exit_err( mirror_help_text );
|
||||
break;
|
||||
@@ -500,6 +512,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN); /* calls to splice() unhelpfully throw this */
|
||||
error_init();
|
||||
set_debug(0);
|
||||
|
||||
if (argc < 2) {
|
||||
exit_err( help_help_text );
|
||||
|
@@ -32,12 +32,24 @@
|
||||
#define GETOPT_FROM GETOPT_ARG( OPT_FROM, 'F' )
|
||||
#define GETOPT_SIZE GETOPT_ARG( OPT_SIZE, 'S' )
|
||||
|
||||
#ifdef DEBUG
|
||||
# define OPT_DEBUG "debug"
|
||||
# define GETOPT_DEBUG GETOPT_FLAG( OPT_DEBUG, 'd' )
|
||||
# define DEBUG_LINE \
|
||||
"\t--" OPT_DEBUG ",-d\tOutput debug information.\n"
|
||||
#else
|
||||
# define GETOPT_DEBUG {0}
|
||||
# define DEBUG_LINE ""
|
||||
#endif
|
||||
|
||||
|
||||
static struct option serve_options[] = {
|
||||
GETOPT_HELP,
|
||||
GETOPT_ADDR,
|
||||
GETOPT_PORT,
|
||||
GETOPT_FILE,
|
||||
GETOPT_SOCK,
|
||||
GETOPT_DEBUG,
|
||||
{0}
|
||||
};
|
||||
static char serve_short_options[] = "hl:p:f:s:";
|
||||
@@ -48,7 +60,8 @@ static char serve_help_text[] =
|
||||
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to serve on.\n"
|
||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to serve on.\n"
|
||||
"\t--" OPT_FILE ",-f <FILE>\tThe file to serve.\n"
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket to open.\n";
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket to open.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
static struct option read_options[] = {
|
||||
GETOPT_HELP,
|
||||
@@ -56,6 +69,7 @@ static struct option read_options[] = {
|
||||
GETOPT_PORT,
|
||||
GETOPT_FROM,
|
||||
GETOPT_SIZE,
|
||||
GETOPT_DEBUG,
|
||||
{0}
|
||||
};
|
||||
static char read_short_options[] = "hl:p:F:S:";
|
||||
@@ -66,7 +80,8 @@ static char read_help_text[] =
|
||||
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to read from.\n"
|
||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to read from.\n"
|
||||
"\t--" OPT_FROM ",-F <OFFSET>\tByte offset to read from.\n"
|
||||
"\t--" OPT_SIZE ",-S <SIZE>\tBytes to read.\n";
|
||||
"\t--" OPT_SIZE ",-S <SIZE>\tBytes to read.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
|
||||
static struct option *write_options = read_options;
|
||||
@@ -78,11 +93,13 @@ static char write_help_text[] =
|
||||
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to write to.\n"
|
||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to write to.\n"
|
||||
"\t--" OPT_FROM ",-F <OFFSET>\tByte offset to write from.\n"
|
||||
"\t--" OPT_SIZE ",-S <SIZE>\tBytes to write.\n";
|
||||
"\t--" OPT_SIZE ",-S <SIZE>\tBytes to write.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
struct option acl_options[] = {
|
||||
GETOPT_HELP,
|
||||
GETOPT_SOCK,
|
||||
GETOPT_DEBUG,
|
||||
{0}
|
||||
};
|
||||
static char acl_short_options[] = "hs:";
|
||||
@@ -90,13 +107,15 @@ static char acl_help_text[] =
|
||||
"Usage: flexnbd " CMD_ACL " <options> [<acl address>+]\n\n"
|
||||
"Set the access control list for a server with control socket SOCK.\n\n"
|
||||
"\t--" OPT_HELP ",-h\tThis text.\n"
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket.\n";
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
struct option mirror_options[] = {
|
||||
GETOPT_HELP,
|
||||
GETOPT_SOCK,
|
||||
GETOPT_ADDR,
|
||||
GETOPT_PORT,
|
||||
GETOPT_DEBUG,
|
||||
{0}
|
||||
};
|
||||
static char mirror_short_options[] = "hs:l:p:";
|
||||
@@ -106,12 +125,14 @@ static char mirror_help_text[] =
|
||||
"\t--" OPT_HELP ",-h\tThis text.\n"
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket.\n"
|
||||
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to mirror to.\n"
|
||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to mirror to.\n";
|
||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to mirror to.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
|
||||
struct option status_options[] = {
|
||||
GETOPT_HELP,
|
||||
GETOPT_SOCK,
|
||||
GETOPT_DEBUG,
|
||||
{0}
|
||||
};
|
||||
static char status_short_options[] = "hs:";
|
||||
@@ -119,7 +140,8 @@ static char status_help_text[] =
|
||||
"Usage: flexnbd " CMD_STATUS " <options>\n\n"
|
||||
"Get the status for a server with control socket SOCK.\n\n"
|
||||
"\t--" OPT_HELP ",-h\tThis text.\n"
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket.\n";
|
||||
"\t--" OPT_SOCK ",-s <SOCK>\tPath to the control socket.\n"
|
||||
DEBUG_LINE;
|
||||
|
||||
static char help_help_text[] =
|
||||
"Usage: flexnbd <cmd> [cmd options]\n\n"
|
||||
|
21
src/util.c
21
src/util.c
@@ -10,6 +10,7 @@
|
||||
#include "util.h"
|
||||
|
||||
static pthread_t main_thread;
|
||||
static int global_debug;
|
||||
|
||||
void error_init()
|
||||
{
|
||||
@@ -59,3 +60,23 @@ void* xmalloc(size_t size)
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
void set_debug(int value) {
|
||||
global_debug = value;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
# include <sys/times.h>
|
||||
# include <stdarg.h>
|
||||
|
||||
void debug(const char *msg, ...) {
|
||||
va_list argp;
|
||||
|
||||
if ( global_debug ) {
|
||||
fprintf(stderr, "%08x %4d: ", (int) pthread_self(), (int) clock() );
|
||||
fprintf(stderr, msg, argp);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -12,12 +12,9 @@ void* xrealloc(void* ptr, size_t size);
|
||||
|
||||
void* xmalloc(size_t size);
|
||||
|
||||
#ifndef DEBUG
|
||||
# define debug(msg, ...)
|
||||
#else
|
||||
# include <sys/times.h>
|
||||
# define debug(msg, ...) fprintf(stderr, "%08x %4d: " msg "\n" , \
|
||||
(int) pthread_self(), (int) clock(), ##__VA_ARGS__)
|
||||
void set_debug(int value);
|
||||
#ifdef DEBUG
|
||||
void debug(const char*msg, ...);
|
||||
#endif
|
||||
|
||||
#define CLIENT_ERROR(msg, ...) \
|
||||
|
Reference in New Issue
Block a user