2009-07-28 18:46:53 +04:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <signal.h>
# include <sys/types.h>
/* Local includes */
2009-08-18 00:53:58 +04:00
# include <simpleconfig.h>
2009-07-28 18:46:53 +04:00
# include <server_plugin.h>
# include <debug.h>
extern fence_callbacks_t libvirt_callbacks ; /* should be in a header */
int
main ( int argc , char * * argv )
{
2009-08-18 00:53:58 +04:00
char val [ 80 ] ;
config_object_t * config ;
2009-08-12 21:20:50 +04:00
const plugin_t * p ;
2009-07-28 18:46:53 +04:00
srv_context_t mcast_context ;
srv_context_t libvirt_context ; /*XXX these should be differently
named context types */
2009-08-18 00:53:58 +04:00
int debug_set = 0 ;
int opt ;
2009-07-28 18:46:53 +04:00
2009-08-18 00:53:58 +04:00
config = sc_init ( ) ;
while ( ( opt = getopt ( argc , argv , " f:d: " ) ) ! = EOF ) {
switch ( opt ) {
case ' f ' :
printf ( " Using %s \n " , optarg ) ;
if ( sc_parse ( config , optarg ) ! = 0 ) {
printf ( " Failed to parse %s \n " , optarg ) ;
return - 1 ;
}
break ;
case ' d ' :
dset ( atoi ( optarg ) ) ;
debug_set = 1 ;
break ;
default :
break ;
}
}
if ( ! debug_set ) {
if ( sc_get ( config , " fence_virtd/@debug " ,
val , sizeof ( val ) ) = = 0 )
dset ( atoi ( val ) ) ;
}
sc_dump ( config , stdout ) ;
if ( sc_get ( config , " fence_virtd/@backend " , val , sizeof ( val ) ) ) {
printf ( " Failed to determine backend. \n " ) ;
printf ( " %s \n " , val ) ;
return - 1 ;
}
printf ( " Backend plugin: %s \n " , val ) ;
2009-07-28 18:46:53 +04:00
2009-08-17 17:58:06 +04:00
# ifdef _MODULE
if ( plugin_load ( " ./libvirt.so " ) < 0 ) {
printf ( " Doom \n " ) ;
}
# endif
2009-08-12 21:20:50 +04:00
plugin_dump ( ) ;
2009-07-28 18:46:53 +04:00
2009-08-18 00:53:58 +04:00
p = plugin_find ( val ) ;
2009-08-12 21:20:50 +04:00
if ( ! p ) {
2009-08-18 00:53:58 +04:00
printf ( " Could not find plugin \" %s \n " , val ) ;
2009-08-12 21:20:50 +04:00
}
2009-08-18 00:53:58 +04:00
if ( p - > init ( & libvirt_context , config ) < 0 ) {
printf ( " %s failed to initialize \n " , val ) ;
2009-07-28 18:46:53 +04:00
return 1 ;
}
/* only client we have now is mcast (fence_xvm behavior) */
2009-08-20 20:26:51 +04:00
if ( mcast_init ( & mcast_context , p - > callbacks , config ,
2009-07-28 18:46:53 +04:00
libvirt_context ) < 0 ) {
printf ( " Failed initialization! \n " ) ;
return 1 ;
}
while ( mcast_dispatch ( mcast_context , NULL ) > = 0 ) ;
mcast_shutdown ( mcast_context ) ;
2009-08-12 21:20:50 +04:00
p - > cleanup ( libvirt_context ) ;
2009-07-28 18:46:53 +04:00
return 0 ;
}