diff options
author | Lubos Lunak <l.lunak@ suse.cz> | 2006-03-14 13:01:58 +0000 |
---|---|---|
committer | Lubos Lunak <l.lunak@ suse.cz> | 2006-03-14 13:01:58 +0000 |
commit | 26ddae222bc650cb34fef2efe29db84886822f2d (patch) | |
tree | 6a696e8f0ea759ffc07da5c0ec59cfb29446ddbb | |
parent | 11f9036b2796fff15b24b446cd566ba850f2f06f (diff) |
Make it possible to connect to a fallback daemon.
-rw-r--r-- | generic/main.c | 16 | ||||
-rw-r--r-- | lib/comm.c | 18 | ||||
-rw-r--r-- | lib/comm.h | 2 | ||||
-rw-r--r-- | tests/.cvsignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rw-r--r-- | tests/test_comm.c | 2 | ||||
-rw-r--r-- | tests/test_fallback.c | 44 |
7 files changed, 81 insertions, 8 deletions
diff --git a/generic/main.c b/generic/main.c index cc34669..365a6d0 100644 --- a/generic/main.c +++ b/generic/main.c @@ -286,17 +286,29 @@ static void processCommand( DapiConnection* conn ) } } -int main() +static char bind_name[ 256 ] = ""; + +static void processArgs( int argc, char* argv[] ) + { + if( argc == 3 && strcmp( argv[ 1 ], "--dapiname" ) == 0 ) + { + strncpy( bind_name, argv[ 2 ], 255 ); + bind_name[ 255 ] = '\0'; + } + } + +int main( int argc, char* argv[] ) { int i; int mainsock; + processArgs( argc, argv ); dpy = XOpenDisplay( NULL ); if( dpy == NULL ) { fprintf( stderr, "Cannot open X connection!\n" ); return 1; } - mainsock = dapi_bindSocket(); + mainsock = dapi_namedBindSocket( bind_name ); if( mainsock < 0 ) return 2; for(;;) @@ -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 ) { @@ -77,10 +82,15 @@ 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 ) { @@ -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? */ diff --git a/tests/.cvsignore b/tests/.cvsignore index aa94b38..f7b5724 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -11,3 +11,4 @@ test_runasuser test_screensaving test_capabilities test_callbacks +test_fallback diff --git a/tests/Makefile.am b/tests/Makefile.am index 897bafb..0a4306e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ bin_PROGRAMS = test_comm test_calls test_runasuser test_screensaving test_mailto test_remotefile test_async \ - test_capabilities test_callbacks + test_capabilities test_callbacks test_fallback test_comm_SOURCES = test_comm.c test_comm_LDADD = ../lib/libdapi.la @@ -37,4 +37,8 @@ test_callbacks_SOURCES = test_callbacks.c test_callbacks_LDADD = ../lib/libdapi.la test_callbacks_LDFLAGS = $(all_libraries) +test_fallback_SOURCES = test_fallback.c +test_fallback_LDADD = ../lib/libdapi.la +test_fallback_LDFLAGS = $(all_libraries) + INCLUDES = $(all_includes) -I$(top_srcdir)/lib diff --git a/tests/test_comm.c b/tests/test_comm.c index edf64ef..2e534be 100644 --- a/tests/test_comm.c +++ b/tests/test_comm.c @@ -2,7 +2,7 @@ #include "comm.h" -int main() +int main( int argc, char* argv[] ) { int command, seq, seq2; int ok; diff --git a/tests/test_fallback.c b/tests/test_fallback.c new file mode 100644 index 0000000..6df684f --- /dev/null +++ b/tests/test_fallback.c @@ -0,0 +1,44 @@ +#include <stdio.h> + +#include "comm.h" +#include "calls.h" + +static void test( DapiConnection* conn, const char* txt ) + { + int ord; + if( !dapi_Init( conn )) + { + printf( "Initialization(%s) failed!\n", txt ); + dapi_close( conn ); + return; + } + ord = dapi_ButtonOrder( conn ); + printf( "Order(%s): %d (%s)\n", txt, ord, ord == 0 ? "Failed" : ord == 1 ? "Ok/Cancel" : "Cancel/Ok" ); + dapi_close( conn ); + } + +/* run daemon with --dapiname fallback to test fallbacks */ +int main() + { + DapiConnection* conn = dapi_connect(); + if( conn != NULL ) + { + printf( "Connected to generic.\n" ); + test( conn, "1" ); + } + else + { + printf( "Connection to generic failed.\n" ); + } + conn = dapi_namedConnect( "fallback" ); + if( conn != NULL ) + { + printf( "Connected to fallback.\n" ); + test( conn, "2" ); + } + else + { + printf( "Connection to fallback failed.\n" ); + } + return 0; + } |