mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
Add debug mode to daemon.
This commit is contained in:
parent
9aaa36a431
commit
3ef81c7977
4 changed files with 54 additions and 15 deletions
|
@ -49,7 +49,7 @@
|
|||
#include "version.h"
|
||||
|
||||
static void usage ( const char *, ... );
|
||||
static int readargs ( int, char ** );
|
||||
static void readargs ( int, char **, int *, int * );
|
||||
static int trylocksock ( void );
|
||||
static int getlock ( const char * );
|
||||
static int getsock ( const char * );
|
||||
|
@ -66,10 +66,10 @@ int
|
|||
main( int argc, char ** argv )
|
||||
{
|
||||
struct event_base * evbase;
|
||||
int nofork, sockfd;
|
||||
int nofork, debug, sockfd;
|
||||
|
||||
setmyname( argv[0] );
|
||||
nofork = readargs( argc, argv );
|
||||
readargs( argc, argv, &nofork, &debug );
|
||||
|
||||
if( !nofork )
|
||||
{
|
||||
|
@ -92,6 +92,7 @@ main( int argc, char ** argv )
|
|||
setupsigs( evbase );
|
||||
torrent_init( evbase );
|
||||
server_init( evbase );
|
||||
server_debug( debug );
|
||||
server_listen( sockfd );
|
||||
|
||||
event_dispatch();
|
||||
|
@ -115,11 +116,12 @@ usage( const char * msg, ... )
|
|||
}
|
||||
|
||||
printf(
|
||||
"usage: %s [-fh]\n"
|
||||
"usage: %s [-dfh]\n"
|
||||
"\n"
|
||||
"Transmission %s (r%d) http://transmission.m0k.org/\n"
|
||||
"A free, lightweight BitTorrent client with a simple, intuitive interface\n"
|
||||
"\n"
|
||||
" -d --debug Print data send and received, implies -f\n"
|
||||
" -f --foreground Run in the foreground and log to stderr\n"
|
||||
" -h --help Display this message and exit\n"
|
||||
"\n"
|
||||
|
@ -128,34 +130,37 @@ usage( const char * msg, ... )
|
|||
exit( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
readargs( int argc, char ** argv )
|
||||
void
|
||||
readargs( int argc, char ** argv, int * nofork, int * debug )
|
||||
{
|
||||
char optstr[] = "fh";
|
||||
char optstr[] = "dfh";
|
||||
struct option longopts[] =
|
||||
{
|
||||
{ "debug", no_argument, NULL, 'd' },
|
||||
{ "foreground", no_argument, NULL, 'f' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
int opt, nofork;
|
||||
int opt;
|
||||
|
||||
nofork = 0;
|
||||
*nofork = 0;
|
||||
*debug = 0;
|
||||
|
||||
while( 0 <= ( opt = getopt_long( argc, argv, optstr, longopts, NULL ) ) )
|
||||
{
|
||||
switch( opt )
|
||||
{
|
||||
case 'd':
|
||||
*debug = 1;
|
||||
/* FALLTHROUGH */
|
||||
case 'f':
|
||||
nofork = 1;
|
||||
*nofork = 1;
|
||||
break;
|
||||
default:
|
||||
usage( NULL );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return nofork;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -84,6 +84,7 @@ INTCMP_FUNC( clientcmp, client, ev )
|
|||
|
||||
static struct event_base * gl_base = NULL;
|
||||
static struct ipc_funcs * gl_tree = NULL;
|
||||
static int gl_debug = 0;
|
||||
static int gl_exiting = 0;
|
||||
static struct allclients gl_clients = RB_INITIALIZER( &gl_clients );
|
||||
|
||||
|
@ -137,6 +138,12 @@ server_init( struct event_base * base )
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
server_debug( int enable )
|
||||
{
|
||||
gl_debug = enable;
|
||||
}
|
||||
|
||||
int
|
||||
server_listen( int fd )
|
||||
{
|
||||
|
@ -233,6 +240,11 @@ newclient( int fd, short event UNUSED, void * arg )
|
|||
old = RB_INSERT( allclients, &gl_clients, client );
|
||||
assert( NULL == old );
|
||||
|
||||
if( gl_debug )
|
||||
{
|
||||
printf( "*** new client %i\n", clfd );
|
||||
}
|
||||
|
||||
bufferevent_enable( clev, EV_READ );
|
||||
buf = ipc_mkvers( &buflen );
|
||||
if( 0 > queuemsg( client, buf, buflen ) )
|
||||
|
@ -286,6 +298,10 @@ byebye( struct bufferevent * ev, short what, void * arg UNUSED )
|
|||
RB_REMOVE( allclients, &gl_clients, client );
|
||||
bufferevent_free( ev );
|
||||
close( client->fd );
|
||||
if( gl_debug )
|
||||
{
|
||||
printf( "*** client %i went bye-bye\n", client->fd );
|
||||
}
|
||||
free( client );
|
||||
}
|
||||
|
||||
|
@ -302,6 +318,13 @@ doread( struct bufferevent * ev, void * arg )
|
|||
buf = EVBUFFER_DATA( EVBUFFER_INPUT( ev ) );
|
||||
len = EVBUFFER_LENGTH( EVBUFFER_INPUT( ev ) );
|
||||
|
||||
if( gl_debug )
|
||||
{
|
||||
printf( "<<< %zu bytes from client %i: ", len, client->fd );
|
||||
fwrite( buf, 1, len, stdout );
|
||||
putc( '\n', stdout );
|
||||
}
|
||||
|
||||
if( IPC_MIN_MSG_LEN > len )
|
||||
{
|
||||
return;
|
||||
|
@ -349,6 +372,13 @@ queuemsg( struct client * client, uint8_t * buf, size_t buflen )
|
|||
return -1;
|
||||
}
|
||||
|
||||
if( gl_debug )
|
||||
{
|
||||
printf( ">>> %zu bytes to client %i: ", buflen, client->fd );
|
||||
fwrite( buf, 1, buflen, stdout );
|
||||
putc( '\n', stdout );
|
||||
}
|
||||
|
||||
if( 0 > bufferevent_write( client->ev, buf, buflen ) )
|
||||
{
|
||||
errnomsg( "failed to buffer %zd bytes of data for write", buflen );
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
struct event_base;
|
||||
|
||||
int server_init( struct event_base * );
|
||||
void server_debug( int );
|
||||
int server_listen( int );
|
||||
|
||||
#endif /* TR_DAEMON_SERVER_H */
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
.Nm transmission-daemon
|
||||
.Fl h
|
||||
.Nm
|
||||
.Op Fl f
|
||||
.Op Fl df
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
|
@ -38,6 +38,9 @@ program cures baldness, obesity and gout.
|
|||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d Fl -debug
|
||||
Print data send and received to and from clients to stdout, also implies
|
||||
.Fl f .
|
||||
.It Fl f Fl -foreground
|
||||
Run in the foreground and print errors to stderr instead of forking
|
||||
and logging errors with syslog.
|
||||
|
|
Loading…
Reference in a new issue