1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 10:15:45 +00:00

Add command-line option to use an alternate location for the socket file.

This commit is contained in:
Josh Elsasser 2007-05-24 03:59:53 +00:00
parent 8d61b3e49e
commit 0f9748ad01
2 changed files with 26 additions and 9 deletions

View file

@ -49,8 +49,8 @@
#include "version.h" #include "version.h"
static void usage ( const char *, ... ); static void usage ( const char *, ... );
static void readargs ( int, char **, int *, int * ); static void readargs ( int, char **, int *, int *, char ** );
static int trylocksock ( void ); static int trylocksock ( const char * );
static int getlock ( const char * ); static int getlock ( const char * );
static int getsock ( const char * ); static int getsock ( const char * );
static void exitcleanup ( void ); static void exitcleanup ( void );
@ -67,9 +67,10 @@ main( int argc, char ** argv )
{ {
struct event_base * evbase; struct event_base * evbase;
int nofork, debug, sockfd; int nofork, debug, sockfd;
char * sockpath;
setmyname( argv[0] ); setmyname( argv[0] );
readargs( argc, argv, &nofork, &debug ); readargs( argc, argv, &nofork, &debug, &sockpath );
if( !nofork ) if( !nofork )
{ {
@ -82,7 +83,7 @@ main( int argc, char ** argv )
} }
atexit( exitcleanup ); atexit( exitcleanup );
sockfd = trylocksock(); sockfd = trylocksock( sockpath );
if( 0 > sockfd ) if( 0 > sockfd )
{ {
exit( 1 ); exit( 1 );
@ -124,6 +125,7 @@ usage( const char * msg, ... )
" -d --debug Print data send and received, implies -f\n" " -d --debug Print data send and received, implies -f\n"
" -f --foreground Run in the foreground and log to stderr\n" " -f --foreground Run in the foreground and log to stderr\n"
" -h --help Display this message and exit\n" " -h --help Display this message and exit\n"
" -s --socket <path> Place the socket file at <path>\n"
"\n" "\n"
"To add torrents or set options, use the transmission-remote program.\n", "To add torrents or set options, use the transmission-remote program.\n",
getmyname(), VERSION_STRING, VERSION_REVISION ); getmyname(), VERSION_STRING, VERSION_REVISION );
@ -131,20 +133,22 @@ usage( const char * msg, ... )
} }
void void
readargs( int argc, char ** argv, int * nofork, int * debug ) readargs( int argc, char ** argv, int * nofork, int * debug, char ** sock )
{ {
char optstr[] = "dfh"; char optstr[] = "dfhs:";
struct option longopts[] = struct option longopts[] =
{ {
{ "debug", no_argument, NULL, 'd' }, { "debug", no_argument, NULL, 'd' },
{ "foreground", no_argument, NULL, 'f' }, { "foreground", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "socket", required_argument, NULL, 's' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
int opt; int opt;
*nofork = 0; *nofork = 0;
*debug = 0; *debug = 0;
*sock = NULL;
while( 0 <= ( opt = getopt_long( argc, argv, optstr, longopts, NULL ) ) ) while( 0 <= ( opt = getopt_long( argc, argv, optstr, longopts, NULL ) ) )
{ {
@ -156,6 +160,9 @@ readargs( int argc, char ** argv, int * nofork, int * debug )
case 'f': case 'f':
*nofork = 1; *nofork = 1;
break; break;
case 's':
*sock = optarg;
break;
default: default:
usage( NULL ); usage( NULL );
break; break;
@ -164,7 +171,7 @@ readargs( int argc, char ** argv, int * nofork, int * debug )
} }
int int
trylocksock( void ) trylocksock( const char * sockpath )
{ {
char path[MAXPATHLEN]; char path[MAXPATHLEN];
int fd; int fd;
@ -185,8 +192,15 @@ trylocksock( void )
gl_lockfd = fd; gl_lockfd = fd;
strlcpy( gl_lockpath, path, sizeof gl_lockpath ); strlcpy( gl_lockpath, path, sizeof gl_lockpath );
confpath( path, sizeof path, CONF_FILE_SOCKET, 0 ); if( NULL == sockpath )
fd = getsock( path ); {
confpath( path, sizeof path, CONF_FILE_SOCKET, 0 );
fd = getsock( path );
}
else
{
fd = getsock( sockpath );
}
if( 0 > fd ) if( 0 > fd )
{ {
return -1; return -1;

View file

@ -27,10 +27,13 @@
.Nm transmission-daemon .Nm transmission-daemon
.Nd a bittorrent client .Nd a bittorrent client
.Sh SYNOPSIS .Sh SYNOPSIS
.Bk -words
.Nm transmission-daemon .Nm transmission-daemon
.Fl h .Fl h
.Nm .Nm
.Op Fl df .Op Fl df
.Op Fl s Ar socket-file
.Ek
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm