Commit 31ec065b authored by Alexander Yaworsky's avatar Alexander Yaworsky Committed by Alexandre Julliard

Restructured code of StartServiceCtrlDispatcherA/W.

parent 34cffce6
...@@ -218,6 +218,30 @@ static BOOL read_scm_lock_data( LPWSTR buffer ) ...@@ -218,6 +218,30 @@ static BOOL read_scm_lock_data( LPWSTR buffer )
} }
/****************************************************************************** /******************************************************************************
* open_seb_shmem
*
* helper function for StartServiceCtrlDispatcherA/W
*/
static struct SEB* open_seb_shmem( LPWSTR service_name, HANDLE* hServiceShmem )
{
WCHAR object_name[ MAX_PATH ];
HANDLE hmem;
struct SEB *ret;
snprintfW( object_name, MAX_PATH, szServiceShmemNameFmtW, service_name );
hmem = OpenFileMappingW( FILE_MAP_ALL_ACCESS, FALSE, object_name );
if( NULL == hmem )
return NULL;
ret = MapViewOfFile( hmem, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( NULL == ret )
CloseHandle( hmem );
else
*hServiceShmem = hmem;
return ret;
}
/******************************************************************************
* build_arg_vectors * build_arg_vectors
* *
* helper function for StartServiceCtrlDispatcherA/W * helper function for StartServiceCtrlDispatcherA/W
...@@ -253,13 +277,13 @@ StartServiceCtrlDispatcherA( LPSERVICE_TABLE_ENTRYA servent ) ...@@ -253,13 +277,13 @@ StartServiceCtrlDispatcherA( LPSERVICE_TABLE_ENTRYA servent )
{ {
LPSERVICE_MAIN_FUNCTIONA fpMain; LPSERVICE_MAIN_FUNCTIONA fpMain;
WCHAR service_name[ MAX_SERVICE_NAME ]; WCHAR service_name[ MAX_SERVICE_NAME ];
WCHAR object_name[ MAX_PATH ];
HANDLE hServiceShmem = NULL; HANDLE hServiceShmem = NULL;
struct SEB *seb = NULL; struct SEB *seb = NULL;
DWORD dwNumServiceArgs ; DWORD dwNumServiceArgs = 0;
LPWSTR *lpArgVecW = NULL; LPWSTR *lpArgVecW = NULL;
LPSTR *lpArgVecA; LPSTR *lpArgVecA = NULL;
unsigned int i; unsigned int i;
BOOL ret = FALSE;
TRACE("(%p)\n", servent); TRACE("(%p)\n", servent);
...@@ -271,30 +295,17 @@ StartServiceCtrlDispatcherA( LPSERVICE_TABLE_ENTRYA servent ) ...@@ -271,30 +295,17 @@ StartServiceCtrlDispatcherA( LPSERVICE_TABLE_ENTRYA servent )
submitted against revision 1.45 and so preserved here. submitted against revision 1.45 and so preserved here.
*/ */
FIXME("should fail with ERROR_FAILED_SERVICE_CONTROLLER_CONNECT\n"); FIXME("should fail with ERROR_FAILED_SERVICE_CONTROLLER_CONNECT\n");
dwNumServiceArgs = 0;
lpArgVecA = NULL;
goto run_service; goto run_service;
} }
snprintfW( object_name, MAX_PATH, szServiceShmemNameFmtW, service_name ); seb = open_seb_shmem( service_name, &hServiceShmem );
hServiceShmem = OpenFileMappingW( FILE_MAP_ALL_ACCESS, FALSE, object_name );
if( NULL == hServiceShmem )
return FALSE;
seb = MapViewOfFile( hServiceShmem, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( NULL == seb ) if( NULL == seb )
{
CloseHandle( hServiceShmem );
return FALSE; return FALSE;
}
lpArgVecW = build_arg_vectors( seb ); lpArgVecW = build_arg_vectors( seb );
if( NULL == lpArgVecW ) if( NULL == lpArgVecW )
{ goto done;
UnmapViewOfFile( seb );
CloseHandle( hServiceShmem );
return FALSE;
}
lpArgVecW[0] = service_name; lpArgVecW[0] = service_name;
dwNumServiceArgs = seb->argc + 1; dwNumServiceArgs = seb->argc + 1;
...@@ -316,6 +327,7 @@ run_service: ...@@ -316,6 +327,7 @@ run_service:
servent++; servent++;
} }
done:
if(dwNumServiceArgs) if(dwNumServiceArgs)
{ {
/* free arg strings */ /* free arg strings */
...@@ -327,7 +339,7 @@ run_service: ...@@ -327,7 +339,7 @@ run_service:
if( lpArgVecW ) HeapFree( GetProcessHeap(), 0, lpArgVecW ); if( lpArgVecW ) HeapFree( GetProcessHeap(), 0, lpArgVecW );
if( seb ) UnmapViewOfFile( seb ); if( seb ) UnmapViewOfFile( seb );
if( hServiceShmem ) CloseHandle( hServiceShmem ); if( hServiceShmem ) CloseHandle( hServiceShmem );
return TRUE; return ret;
} }
/****************************************************************************** /******************************************************************************
...@@ -341,8 +353,7 @@ StartServiceCtrlDispatcherW( LPSERVICE_TABLE_ENTRYW servent ) ...@@ -341,8 +353,7 @@ StartServiceCtrlDispatcherW( LPSERVICE_TABLE_ENTRYW servent )
{ {
LPSERVICE_MAIN_FUNCTIONW fpMain; LPSERVICE_MAIN_FUNCTIONW fpMain;
WCHAR service_name[ MAX_SERVICE_NAME ]; WCHAR service_name[ MAX_SERVICE_NAME ];
WCHAR object_name[ MAX_PATH ]; HANDLE hServiceShmem = NULL;
HANDLE hServiceShmem;
struct SEB *seb; struct SEB *seb;
DWORD dwNumServiceArgs ; DWORD dwNumServiceArgs ;
LPWSTR *lpServiceArgVectors ; LPWSTR *lpServiceArgVectors ;
...@@ -352,17 +363,9 @@ StartServiceCtrlDispatcherW( LPSERVICE_TABLE_ENTRYW servent ) ...@@ -352,17 +363,9 @@ StartServiceCtrlDispatcherW( LPSERVICE_TABLE_ENTRYW servent )
if( ! read_scm_lock_data( service_name ) ) if( ! read_scm_lock_data( service_name ) )
return FALSE; return FALSE;
snprintfW( object_name, MAX_PATH, szServiceShmemNameFmtW, service_name ); seb = open_seb_shmem( service_name, &hServiceShmem );
hServiceShmem = OpenFileMappingW( FILE_MAP_ALL_ACCESS, FALSE, object_name );
if( NULL == hServiceShmem )
return FALSE;
seb = MapViewOfFile( hServiceShmem, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( NULL == seb ) if( NULL == seb )
{
CloseHandle( hServiceShmem );
return FALSE; return FALSE;
}
lpServiceArgVectors = build_arg_vectors( seb ); lpServiceArgVectors = build_arg_vectors( seb );
if( NULL == lpServiceArgVectors ) if( NULL == lpServiceArgVectors )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment