X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fntservice.c;h=c36adefcfc41aee18fa14cc1687408b74fabc7c4;hb=c60652e38ac6afd74bd8225e9dae5406f13aaa4f;hp=ed02e68ab1961c8bb5cbbfe23fe36152df3b6371;hpb=0dc75f8ba97cf662f6d89151d85cb0e584ad7f5b;p=vlc diff --git a/modules/control/ntservice.c b/modules/control/ntservice.c index ed02e68ab1..c36adefcfc 100644 --- a/modules/control/ntservice.c +++ b/modules/control/ntservice.c @@ -61,25 +61,25 @@ static void Close ( vlc_object_t * ); "properly configured. Use a comma separated list of interface modules. " \ "(common values are: logger, sap, rc, http)") -vlc_module_begin(); - set_shortname( N_("NT Service")); - set_description( N_("Windows Service interface") ); - set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL ); - add_bool( "ntservice-install", 0, NULL, - INSTALL_TEXT, INSTALL_LONGTEXT, true ); - add_bool( "ntservice-uninstall", 0, NULL, - UNINSTALL_TEXT, UNINSTALL_LONGTEXT, true ); +vlc_module_begin () + set_shortname( N_("NT Service")) + set_description( N_("Windows Service interface") ) + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + add_bool( "ntservice-install", false, NULL, + INSTALL_TEXT, INSTALL_LONGTEXT, true ) + add_bool( "ntservice-uninstall", false, NULL, + UNINSTALL_TEXT, UNINSTALL_LONGTEXT, true ) add_string ( "ntservice-name", VLCSERVICENAME, NULL, - NAME_TEXT, NAME_LONGTEXT, true ); + NAME_TEXT, NAME_LONGTEXT, true ) add_string ( "ntservice-options", NULL, NULL, - OPTIONS_TEXT, OPTIONS_LONGTEXT, true ); + OPTIONS_TEXT, OPTIONS_LONGTEXT, true ) add_string ( "ntservice-extraintf", NULL, NULL, - EXTRAINTF_TEXT, EXTRAINTF_LONGTEXT, true ); + EXTRAINTF_TEXT, EXTRAINTF_LONGTEXT, true ) - set_capability( "interface", 0 ); - set_callbacks( Activate, Close ); -vlc_module_end(); + set_capability( "interface", 0 ) + set_callbacks( Activate, Close ) +vlc_module_end () struct intf_sys_t { @@ -107,9 +107,6 @@ static int Activate( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t*)p_this; - /* Only works on NT/2K/XP */ - if( !IS_WINNT ) return VLC_EGENERIC; - p_intf->pf_run = Run; return VLC_SUCCESS; } @@ -119,6 +116,7 @@ static int Activate( vlc_object_t *p_this ) *****************************************************************************/ void Close( vlc_object_t *p_this ) { + (void)p_this; } /***************************************************************************** @@ -126,27 +124,27 @@ void Close( vlc_object_t *p_this ) *****************************************************************************/ static void Run( intf_thread_t *p_intf ) { - intt_sys_t sys; - intf_thread_t *p_extraintf; + intf_sys_t sys; SERVICE_TABLE_ENTRY dispatchTable[] = { - { VLCSERVICENAME, &ServiceDispatch }, + { (LPTSTR)VLCSERVICENAME, &ServiceDispatch }, { NULL, NULL } }; + int canc = vlc_savecancel(); p_global_intf = p_intf; p_intf->p_sys = &sys; - p_intf->p_sys->psz_service = config_GetPsz( p_intf, "ntservice-name" ); + p_intf->p_sys->psz_service = var_InheritString( p_intf, "ntservice-name" ); p_intf->p_sys->psz_service = p_intf->p_sys->psz_service ? p_intf->p_sys->psz_service : strdup(VLCSERVICENAME); - if( config_GetInt( p_intf, "ntservice-install" ) ) + if( var_InheritBool( p_intf, "ntservice-install" ) ) { NTServiceInstall( p_intf ); return; } - if( config_GetInt( p_intf, "ntservice-uninstall" ) ) + if( var_InheritBool( p_intf, "ntservice-uninstall" ) ) { NTServiceUninstall( p_intf ); return; @@ -159,17 +157,9 @@ static void Run( intf_thread_t *p_intf ) free( p_intf->p_sys->psz_service ); - /* Stop and destroy the interfaces we spawned */ - while( (p_extraintf = vlc_object_find(p_intf, VLC_OBJECT_INTF, FIND_CHILD))) - { - intf_StopThread( p_extraintf ); - vlc_object_detach( p_extraintf ); - vlc_object_release( p_extraintf ); - vlc_object_release( p_extraintf ); - } - /* Make sure we exit (In case other interfaces have been spawned) */ - vlc_object_kill( p_intf->p_libvlc ); + libvlc_Quit( p_intf->p_libvlc ); + vlc_restorecancel( canc ); } /***************************************************************************** @@ -192,21 +182,21 @@ static int NTServiceInstall( intf_thread_t *p_intf ) GetModuleFileName( NULL, psz_pathtmp, MAX_PATH ); sprintf( psz_path, "\"%s\" -I "MODULE_STRING, psz_pathtmp ); - psz_extra = config_GetPsz( p_intf, "ntservice-extraintf" ); - if( psz_extra && *psz_extra ) + psz_extra = var_InheritString( p_intf, "ntservice-extraintf" ); + if( psz_extra ) { strcat( psz_path, " --ntservice-extraintf " ); strcat( psz_path, psz_extra ); + free( psz_extra ); } - free( psz_extra ); - psz_extra = config_GetPsz( p_intf, "ntservice-options" ); + psz_extra = var_InheritString( p_intf, "ntservice-options" ); if( psz_extra && *psz_extra ) { strcat( psz_path, " " ); strcat( psz_path, psz_extra ); + free( psz_extra ); } - free( psz_extra ); SC_HANDLE service = CreateService( handle, p_sys->psz_service, p_sys->psz_service, @@ -280,6 +270,8 @@ static int NTServiceUninstall( intf_thread_t *p_intf ) static void WINAPI ServiceDispatch( DWORD numArgs, char **args ) { + (void)numArgs; + (void)args; intf_thread_t *p_intf = (intf_thread_t *)p_global_intf; intf_sys_t *p_sys = p_intf->p_sys; char *psz_modules, *psz_parser; @@ -301,7 +293,7 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args ) /* * Load background interfaces */ - psz_modules = config_GetPsz( p_intf, "ntservice-extraintf" ); + psz_modules = var_InheritString( p_intf, "ntservice-extraintf" ); psz_parser = psz_modules; while( psz_parser && *psz_parser ) { @@ -313,30 +305,17 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args ) *psz_parser = '\0'; psz_parser++; } - psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") ); - if( psz_temp ) - { - intf_thread_t *p_new_intf; - sprintf( psz_temp, "%s,none", psz_module ); + if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 ) + { /* Try to create the interface */ - p_new_intf = intf_Create( p_intf, psz_temp ); - if( p_new_intf == NULL ) + if( intf_Create( p_intf, psz_temp ) ) { msg_Err( p_intf, "interface \"%s\" initialization failed", psz_temp ); free( psz_temp ); continue; } - - /* Try to run the interface */ - if( intf_RunThread( p_new_intf ) ) - { - vlc_object_detach( p_new_intf ); - vlc_object_release( p_new_intf ); - msg_Err( p_intf, "interface \"%s\" cannot run", psz_temp ); - } - free( psz_temp ); } }