X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Fntservice.c;h=1791a29f351945a7f54ad6c84b63ebd3b128e339;hb=be84b46a573e5717204c0ac8d1a012a6c1140265;hp=99c1f57b4a83443ef094d24f37f813c4baf1e82f;hpb=990f8218f442a756ae8d2521bfcdb250b6c9c5e6;p=vlc diff --git a/modules/control/ntservice.c b/modules/control/ntservice.c old mode 100755 new mode 100644 index 99c1f57b4a..1791a29f35 --- a/modules/control/ntservice.c +++ b/modules/control/ntservice.c @@ -1,7 +1,7 @@ /***************************************************************************** * ntservice.c: Windows NT/2K/XP service interface ***************************************************************************** - * Copyright (C) 2004 VideoLAN + * Copyright (C) 2004 the VideoLAN team * $Id$ * * Authors: Gildas Bazin @@ -18,15 +18,19 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include #define VLCSERVICENAME "VLC media player" @@ -38,41 +42,44 @@ static void Close ( vlc_object_t * ); #define INSTALL_TEXT N_( "Install Windows Service" ) #define INSTALL_LONGTEXT N_( \ - "If enabled the interface will install the Service and exit." ) + "Install the Service and exit." ) #define UNINSTALL_TEXT N_( "Uninstall Windows Service" ) #define UNINSTALL_LONGTEXT N_( \ - "If enabled the interface will uninstall the Service and exit." ) + "Uninstall the Service and exit." ) #define NAME_TEXT N_( "Display name of the Service" ) #define NAME_LONGTEXT N_( \ - "This allows you to change the display name of the Service." ) + "Change the display name of the Service." ) #define OPTIONS_TEXT N_("Configuration options") #define OPTIONS_LONGTEXT N_( \ - "This option allows you to specify configuration options that will be " \ + "Configuration options that will be " \ "used by the Service (eg. --foo=bar --no-foobar). It should be specified "\ "at install time so the Service is properly configured.") #define EXTRAINTF_TEXT N_("Extra interface modules") #define EXTRAINTF_LONGTEXT N_( \ - "This option allows you to select additional interfaces spawned by the " \ + "Additional interfaces spawned by the " \ "Service. It should be specified at install time so the Service is " \ "properly configured. Use a comma separated list of interface modules. " \ "(common values are: logger, sap, rc, http)") -vlc_module_begin(); - set_description( _("Windows Service interface") ); +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, VLC_TRUE ); + INSTALL_TEXT, INSTALL_LONGTEXT, true ); add_bool( "ntservice-uninstall", 0, NULL, - UNINSTALL_TEXT, UNINSTALL_LONGTEXT, VLC_TRUE ); + UNINSTALL_TEXT, UNINSTALL_LONGTEXT, true ); add_string ( "ntservice-name", VLCSERVICENAME, NULL, - NAME_TEXT, NAME_LONGTEXT, VLC_TRUE ); + NAME_TEXT, NAME_LONGTEXT, true ); add_string ( "ntservice-options", NULL, NULL, - OPTIONS_TEXT, OPTIONS_LONGTEXT, VLC_TRUE ); + OPTIONS_TEXT, OPTIONS_LONGTEXT, true ); add_string ( "ntservice-extraintf", NULL, NULL, - EXTRAINTF_TEXT, EXTRAINTF_LONGTEXT, VLC_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 { @@ -100,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; } @@ -112,6 +116,7 @@ static int Activate( vlc_object_t *p_this ) *****************************************************************************/ void Close( vlc_object_t *p_this ) { + (void)p_this; } /***************************************************************************** @@ -119,6 +124,7 @@ void Close( vlc_object_t *p_this ) *****************************************************************************/ static void Run( intf_thread_t *p_intf ) { + intf_sys_t sys; intf_thread_t *p_extraintf; SERVICE_TABLE_ENTRY dispatchTable[] = { @@ -126,8 +132,9 @@ static void Run( intf_thread_t *p_intf ) { NULL, NULL } }; + int canc = vlc_savecancel(); p_global_intf = p_intf; - p_intf->p_sys = alloca( sizeof( intf_sys_t ) ); + p_intf->p_sys = &sys; p_intf->p_sys->psz_service = config_GetPsz( p_intf, "ntservice-name" ); p_intf->p_sys->psz_service = p_intf->p_sys->psz_service ? p_intf->p_sys->psz_service : strdup(VLCSERVICENAME); @@ -146,22 +153,14 @@ static void Run( intf_thread_t *p_intf ) if( StartServiceCtrlDispatcher( dispatchTable ) == 0 ) { - msg_Err( p_intf, "StartServiceCtrlDispatcher failed" ); + msg_Err( p_intf, "StartServiceCtrlDispatcher failed" ); /* str review */ } 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 ); - intf_Destroy( p_extraintf ); - } - /* Make sure we exit (In case other interfaces have been spawned) */ - p_intf->p_vlc->b_die = VLC_TRUE; + vlc_object_kill( p_intf->p_libvlc ); + vlc_restorecancel( canc ); } /***************************************************************************** @@ -174,7 +173,8 @@ static int NTServiceInstall( intf_thread_t *p_intf ) SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); if( handle == NULL ) { - msg_Err( p_intf, "could not connect to SCM database" ); + msg_Err( p_intf, + "could not connect to Services Control Manager database" ); return VLC_EGENERIC; } @@ -189,7 +189,7 @@ static int NTServiceInstall( intf_thread_t *p_intf ) strcat( psz_path, " --ntservice-extraintf " ); strcat( psz_path, psz_extra ); } - if( psz_extra ) free( psz_extra ); + free( psz_extra ); psz_extra = config_GetPsz( p_intf, "ntservice-options" ); if( psz_extra && *psz_extra ) @@ -197,7 +197,7 @@ static int NTServiceInstall( intf_thread_t *p_intf ) strcat( psz_path, " " ); strcat( psz_path, psz_extra ); } - if( psz_extra ) free( psz_extra ); + free( psz_extra ); SC_HANDLE service = CreateService( handle, p_sys->psz_service, p_sys->psz_service, @@ -238,7 +238,8 @@ static int NTServiceUninstall( intf_thread_t *p_intf ) SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); if( handle == NULL ) { - msg_Err( p_intf, "could not connect to SCM database" ); + msg_Err( p_intf, + "could not connect to Services Control Manager database" ); return VLC_EGENERIC; } @@ -270,6 +271,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; @@ -303,11 +306,10 @@ 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 ) + + if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 ) { intf_thread_t *p_new_intf; - sprintf( psz_temp, "%s,none", psz_module ); /* Try to create the interface */ p_new_intf = intf_Create( p_intf, psz_temp ); @@ -320,21 +322,17 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args ) } /* Try to run the interface */ - p_new_intf->b_block = VLC_FALSE; if( intf_RunThread( p_new_intf ) ) { vlc_object_detach( p_new_intf ); - intf_Destroy( p_new_intf ); + vlc_object_release( p_new_intf ); msg_Err( p_intf, "interface \"%s\" cannot run", psz_temp ); } free( psz_temp ); } } - if( psz_modules ) - { - free( psz_modules ); - } + free( psz_modules ); /* Initialization complete - report running status */ p_sys->status.dwCurrentState = SERVICE_RUNNING;