From 26ddae222bc650cb34fef2efe29db84886822f2d Mon Sep 17 00:00:00 2001 From: Lubos Lunak Date: Tue, 14 Mar 2006 13:01:58 +0000 Subject: Make it possible to connect to a fallback daemon. --- lib/comm.c | 18 ++++++++++++++---- lib/comm.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/comm.c b/lib/comm.c index b09caff..68400e9 100644 --- a/lib/comm.c +++ b/lib/comm.c @@ -33,22 +33,27 @@ static void getDisplay( char* ret, int max ) *pos = '\0'; } -static void socketName( char* name, int max ) +static void socketName( char* sock_file, const char* name, int max ) { const char* home; char display[ 256 ]; home = getenv( "HOME" ); getDisplay( display, 255 ); - snprintf( name, max - 1, "%s/.dapi-%s", home, display ); + snprintf( sock_file, max - 1, "%s/.dapi-%s%s%s", home, display, name != NULL ? "-" : "", name ); } DapiConnection* dapi_connect() + { + return dapi_namedConnect( "" ); + } + +DapiConnection* dapi_namedConnect( const char* name ) { char sock_file[ 256 ]; int sock; struct sockaddr_un addr; DapiConnection* ret; - socketName( sock_file, 255 ); + socketName( sock_file, name, 255 ); sock = socket( PF_UNIX, SOCK_STREAM, 0 ); if( sock < 0 ) { @@ -76,11 +81,16 @@ DapiConnection* dapi_connect() } int dapi_bindSocket() + { + return dapi_namedBindSocket( "" ); + } + +int dapi_namedBindSocket( const char* name ) { char sock_file[ 256 ]; int sock; struct sockaddr_un addr; - socketName( sock_file, 255 ); + socketName( sock_file, name, 255 ); sock = socket( PF_UNIX, SOCK_STREAM, 0 ); if( sock < 0 ) { diff --git a/lib/comm.h b/lib/comm.h index b69d6af..f4d7759 100644 --- a/lib/comm.h +++ b/lib/comm.h @@ -8,10 +8,12 @@ extern "C" { typedef struct DapiConnection DapiConnection; DapiConnection* dapi_connect( void ); +DapiConnection* dapi_namedConnect( const char* name ); void dapi_close( DapiConnection* conn ); int dapi_socket( DapiConnection* conn ); int dapi_bindSocket( void ); +int dapi_namedBindSocket( const char* name ); DapiConnection* dapi_acceptSocket( int sock ); /* TODO generovat? */ -- cgit v1.2.3