diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-26 16:45:25 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-26 16:45:25 +0100 |
commit | cbc6aaca6dd7ac57a6115b3512a85045e51303dd (patch) | |
tree | 266097ae9558c6b16a8bd399d7dbcf85c4096e09 /tests/service | |
parent | 3395731667cfd707bfdfacf9b10abf67f7691ffd (diff) | |
download | wolfbones-cbc6aaca6dd7ac57a6115b3512a85045e51303dd.tar.gz wolfbones-cbc6aaca6dd7ac57a6115b3512a85045e51303dd.tar.bz2 |
started with service.c, now the messages in testservicemsg.dll are a mess..
Diffstat (limited to 'tests/service')
-rwxr-xr-x | tests/service/create_testservicemsg.pl | 8 | ||||
-rw-r--r-- | tests/service/testservice.c | 148 | ||||
-rw-r--r-- | tests/service/testservicemsg.mc | 9 |
3 files changed, 20 insertions, 145 deletions
diff --git a/tests/service/create_testservicemsg.pl b/tests/service/create_testservicemsg.pl index ab0bf3c..033cda8 100755 --- a/tests/service/create_testservicemsg.pl +++ b/tests/service/create_testservicemsg.pl @@ -71,6 +71,14 @@ Daemon ;. MessageId = 0x3 +SymbolicName = WOLF_CATEGORY_SERVICE +Language = English +test service +;Language = German +;Service +. + +MessageId = 0x4 SymbolicName = WOLF_CATEGORY_TESTSERVICE Language = English test service diff --git a/tests/service/testservice.c b/tests/service/testservice.c index 8159cbd..e229704 100644 --- a/tests/service/testservice.c +++ b/tests/service/testservice.c @@ -12,16 +12,7 @@ #define WOLF_CATEGORY_TESTSERVICE WOLF_LAST_INTERNAL_CATEGORY+1 #define WOLF_MSG_TESTSERVICE_BASE ( WOLF_CATEGORY_TESTSERVICE ) * 1000 -#define WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_INSTALL WOLF_MSG_TESTSERVICE_BASE+1 -#define WOLF_MSG_TESTSERVICE_INSTALLING_SERVICE WOLF_MSG_TESTSERVICE_BASE+2 -#define WOLF_MSG_TESTSERVICE_CANT_GET_PATH_OF_BINARY WOLF_MSG_TESTSERVICE_BASE+3 -#define WOLF_MSG_TESTSERVICE_CANT_CREATE_SERVICE WOLF_MSG_TESTSERVICE_BASE+4 -#define WOLF_MSG_TESTSERVICE_SERVICE_INSTALLED WOLF_MSG_TESTSERVICE_BASE+5 -#define WOLF_MSG_TESTSERVICE_UNINSTALLING_SERVICE WOLF_MSG_TESTSERVICE_BASE+6 -#define WOLF_MSG_TESTSERVICE_SERVICE_UNINSTALLED WOLF_MSG_TESTSERVICE_BASE+7 -#define WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_UNINSTALL WOLF_MSG_TESTSERVICE_BASE+8 -#define WOLF_MSG_TESTSERVICE_CANT_OPEN_SERVICE WOLF_MSG_TESTSERVICE_BASE+9 -#define WOLF_MSG_TESTSERVICE_CANT_DELETE_SERVICE WOLF_MSG_TESTSERVICE_BASE+10 + #define WOLF_MSG_TESTSERVICE_CANT_DISPATCH_SERVICE WOLF_MSG_TESTSERVICE_BASE+11 #define WOLF_MSG_TESTSERVICE_CANT_REGISTER_SERVICE_CTRL_HANDLER WOLF_MSG_TESTSERVICE_BASE+12 #define WOLF_MSG_TESTSERVICE_HANDLING_EVENT WOLF_MSG_TESTSERVICE_BASE+13 @@ -35,139 +26,6 @@ #define SERVICE_NAME "testservice" #define SERVICE_NAME_DESCR "Wolf Test Service" -static wolf_error_t wolf_service_install( LPCTSTR service_name, - LPCTSTR service_name_descr ) { - SC_HANDLE scm; - SC_HANDLE service; - char errbuf[512]; - DWORD res; - TCHAR binary_path[MAX_PATH]; - - wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_INSTALLING_SERVICE, - _( "Installing service '%s'" ), service_name ); - - /* get service control manager with enough rights on the local - * machine to install the service - */ - scm = (SC_HANDLE)OpenSCManager( - NULL, /* local computer */ - SERVICES_ACTIVE_DATABASE, - SC_MANAGER_ALL_ACCESS ); - - if( scm == NULL ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_INSTALL, - _( "Unable to open the service control manager to register service '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - return WOLF_ERR_INTERNAL; - } - - /* Get the full path of the service binary */ - res = GetModuleFileName( - NULL, /* current process */ - binary_path, - MAX_PATH ); - - if( res == MAX_PATH ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_GET_PATH_OF_BINARY, - _( "Unable to get full path of the binary of service '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - CloseServiceHandle( scm ); - return WOLF_ERR_INTERNAL; - } - - /* create the service */ - service = CreateService( - scm, - service_name, - service_name_descr, - SERVICE_ALL_ACCESS, - SERVICE_WIN32_OWN_PROCESS, /* run isolated in its own process */ - SERVICE_DEMAND_START, /* let the user choose the start type */ - SERVICE_ERROR_NORMAL, /* report error and continue boot */ - binary_path, - NULL, /* order group */ - NULL, /* tag in the order group */ - NULL, /* service dependencies */ - NULL, /* Local System Account */ - NULL ); - - if( service == NULL ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_CREATE_SERVICE, - _( "Unable to create service '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - CloseServiceHandle( scm ); - return WOLF_ERR_INTERNAL; - } - - CloseServiceHandle( service ); - CloseServiceHandle( scm ); - - wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_SERVICE_INSTALLED, - _( "Service '%s' installed successfully" ), service_name ); - - return WOLF_OK; -} - -static wolf_error_t wolf_service_remove( LPCTSTR service_name ) { - SC_HANDLE scm; - char errbuf[512]; - SC_HANDLE service; - DWORD res; - - wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_UNINSTALLING_SERVICE, - _( "Unistalling service '%s'" ), service_name ); - - /* get service control manager with enough rights on the local - * machine to uninstall the service - */ - scm = (SC_HANDLE)OpenSCManager( - NULL, /* local computer */ - SERVICES_ACTIVE_DATABASE, - SC_MANAGER_ALL_ACCESS ); - - if( scm == NULL ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_OPEN_SCM_FOR_UNINSTALL, - _( "Unable to open the service control manager to uninstall '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - return WOLF_ERR_INTERNAL; - } - - /* open the service handle and delete the service */ - service = OpenService( scm, service_name, SERVICE_ALL_ACCESS ); - - if( service == NULL ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_OPEN_SERVICE, - _( "Unable to open service '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - CloseServiceHandle( scm ); - return WOLF_ERR_INTERNAL; - } - - res = DeleteService( service ); - if( res == 0 ) { - WOLF_LOG_GET_LAST_ERROR( GetLastError( ), errbuf, 512 ); - wolf_log( WOLF_LOG_ERR, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_CANT_DELETE_SERVICE, - _( "Unable to uninstall service '%s': %s (%d)" ), - service_name, errbuf, GetLastError( ) ); - CloseServiceHandle( service ); - CloseServiceHandle( scm ); - return WOLF_ERR_INTERNAL; - } - - CloseServiceHandle( service ); - CloseServiceHandle( scm ); - - wolf_log( WOLF_LOG_DEBUG, WOLF_CATEGORY_TESTSERVICE, WOLF_MSG_TESTSERVICE_SERVICE_UNINSTALLED, - _( "Service '%s' uninstalled successfully" ), service_name ); - - return WOLF_OK; -} - /* FIXME: should be passed in the event contect as struct */ static SERVICE_STATUS_HANDLE service_status_handle; static SERVICE_STATUS service_status; @@ -294,7 +152,7 @@ void WINAPI wolf_service_main( DWORD argc, LPTSTR *argv ) { * to have a logfile or interaction with the user in any way! */ wolf_log_openlogtoeventlog( NULL, "Application", "testservice", - "C:\\Temp\\testservicemsg.dll", 3, WOLF_LOG_DEBUG ); + "C:\\Temp\\testservicemsg.dll", WOLF_LAST_INTERNAL_CATEGORY+1, WOLF_LOG_DEBUG ); /* register the event callback where we get called by the service * manager and the system @@ -375,7 +233,7 @@ void __cdecl _tmain( int argc, TCHAR *argv[] ) { wolf_log_openlogtostderr( WOLF_LOG_DEBUG ); wolf_log_openlogtofile( "testservice.log", WOLF_LOG_DEBUG ); wolf_log_openlogtoeventlog( NULL, "Application", "testservice", - "C:\\Temp\\testservicemsg.dll", 3, WOLF_LOG_DEBUG ); + "C:\\Temp\\testservicemsg.dll", WOLF_LAST_INTERNAL_CATEGORY+1, WOLF_LOG_DEBUG ); /* called as service, dispatch the main service thread */ if( argc < 2 ) { diff --git a/tests/service/testservicemsg.mc b/tests/service/testservicemsg.mc index f3a12e5..d90e415 100644 --- a/tests/service/testservicemsg.mc +++ b/tests/service/testservicemsg.mc @@ -35,6 +35,15 @@ Daemon ;. MessageId = 0x3 +SymbolicName = WOLF_CATEGORY_SERVICE +Language = English +Service +. +;Language = German +;Service +;. + +MessageId = 0x4 SymbolicName = WOLF_CATEGORY_TESTSERVICE Language = English test service |