Commit 84918394 authored by Alexandre Julliard's avatar Alexandre Julliard

advapi32: Convert the service list to a standard list.

parent 974784cd
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "winternl.h" #include "winternl.h"
#include "lmcons.h" #include "lmcons.h"
#include "lmserver.h" #include "lmserver.h"
#include "wine/list.h"
WINE_DEFAULT_DEBUG_CHANNEL(advapi); WINE_DEFAULT_DEBUG_CHANNEL(advapi);
...@@ -58,7 +59,7 @@ typedef struct service_start_info_t ...@@ -58,7 +59,7 @@ typedef struct service_start_info_t
typedef struct service_data_t typedef struct service_data_t
{ {
struct service_data_t *next; struct list entry;
union { union {
LPHANDLER_FUNCTION handler; LPHANDLER_FUNCTION handler;
LPHANDLER_FUNCTION_EX handler_ex; LPHANDLER_FUNCTION_EX handler_ex;
...@@ -86,7 +87,7 @@ static CRITICAL_SECTION_DEBUG service_cs_debug = ...@@ -86,7 +87,7 @@ static CRITICAL_SECTION_DEBUG service_cs_debug =
}; };
static CRITICAL_SECTION service_cs = { &service_cs_debug, -1, 0, 0, 0, 0 }; static CRITICAL_SECTION service_cs = { &service_cs_debug, -1, 0, 0, 0, 0 };
static service_data *service_list; static struct list service_list = LIST_INIT(service_list);
/****************************************************************************** /******************************************************************************
* SC_HANDLEs * SC_HANDLEs
...@@ -764,22 +765,20 @@ static DWORD WINAPI service_control_dispatcher(LPVOID arg) ...@@ -764,22 +765,20 @@ static DWORD WINAPI service_control_dispatcher(LPVOID arg)
static BOOL service_run_threads(void) static BOOL service_run_threads(void)
{ {
service_data *service; service_data *service;
DWORD count = 0, n = 0; DWORD count, n = 0;
HANDLE *handles; HANDLE *handles;
EnterCriticalSection( &service_cs ); EnterCriticalSection( &service_cs );
/* count how many services there are */ count = list_count( &service_list );
for (service = service_list; service; service = service->next)
count++;
TRACE("starting %d pipe listener threads\n", count); TRACE("starting %d pipe listener threads\n", count);
handles = HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE)*count); handles = HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE)*count);
for (n=0, service = service_list; service; service = service->next, n++) LIST_FOR_EACH_ENTRY( service, &service_list, service_data, entry )
handles[n] = CreateThread( NULL, 0, service_control_dispatcher, handles[n++] = CreateThread( NULL, 0, service_control_dispatcher,
service, 0, NULL ); service, 0, NULL );
assert(n==count); assert(n==count);
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
...@@ -816,11 +815,7 @@ BOOL WINAPI StartServiceCtrlDispatcherA( const SERVICE_TABLE_ENTRYA *servent ) ...@@ -816,11 +815,7 @@ BOOL WINAPI StartServiceCtrlDispatcherA( const SERVICE_TABLE_ENTRYA *servent )
MultiByteToWideChar(CP_ACP, 0, name, -1, info->name, len); MultiByteToWideChar(CP_ACP, 0, name, -1, info->name, len);
info->proc.a = servent->lpServiceProc; info->proc.a = servent->lpServiceProc;
info->unicode = FALSE; info->unicode = FALSE;
list_add_head( &service_list, &info->entry );
/* insert into the list */
info->next = service_list;
service_list = info;
servent++; servent++;
} }
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
...@@ -862,11 +857,7 @@ BOOL WINAPI StartServiceCtrlDispatcherW( const SERVICE_TABLE_ENTRYW *servent ) ...@@ -862,11 +857,7 @@ BOOL WINAPI StartServiceCtrlDispatcherW( const SERVICE_TABLE_ENTRYW *servent )
strcpyW(info->name, name); strcpyW(info->name, name);
info->proc.w = servent->lpServiceProc; info->proc.w = servent->lpServiceProc;
info->unicode = TRUE; info->unicode = TRUE;
list_add_head( &service_list, &info->entry );
/* insert into the list */
info->next = service_list;
service_list = info;
servent++; servent++;
} }
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
...@@ -934,16 +925,20 @@ SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW( LPCWSTR lpServiceName, ...@@ -934,16 +925,20 @@ SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW( LPCWSTR lpServiceName,
LPHANDLER_FUNCTION lpfHandler ) LPHANDLER_FUNCTION lpfHandler )
{ {
service_data *service; service_data *service;
SERVICE_STATUS_HANDLE handle = 0;
EnterCriticalSection( &service_cs ); EnterCriticalSection( &service_cs );
for(service = service_list; service; service = service->next) LIST_FOR_EACH_ENTRY( service, &service_list, service_data, entry )
{
if(!strcmpW(lpServiceName, service->name)) if(!strcmpW(lpServiceName, service->name))
{
service->handler.handler = lpfHandler;
handle = (SERVICE_STATUS_HANDLE)service;
break; break;
if (service) }
service->handler.handler = lpfHandler; }
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
return handle;
return (SERVICE_STATUS_HANDLE)service;
} }
/****************************************************************************** /******************************************************************************
...@@ -957,7 +952,7 @@ BOOL WINAPI ...@@ -957,7 +952,7 @@ BOOL WINAPI
SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus ) SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus )
{ {
service_data *service; service_data *service;
BOOL r = TRUE; BOOL r = FALSE;
TRACE("%p %x %x %x %x %x %x %x\n", hService, TRACE("%p %x %x %x %x %x %x %x\n", hService,
lpStatus->dwServiceType, lpStatus->dwCurrentState, lpStatus->dwServiceType, lpStatus->dwCurrentState,
...@@ -966,16 +961,16 @@ SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus ) ...@@ -966,16 +961,16 @@ SetServiceStatus( SERVICE_STATUS_HANDLE hService, LPSERVICE_STATUS lpStatus )
lpStatus->dwWaitHint); lpStatus->dwWaitHint);
EnterCriticalSection( &service_cs ); EnterCriticalSection( &service_cs );
for (service = service_list; service; service = service->next) LIST_FOR_EACH_ENTRY( service, &service_list, service_data, entry )
{
if(service == (service_data*)hService) if(service == (service_data*)hService)
{
memcpy( &service->status, lpStatus, sizeof(SERVICE_STATUS) );
TRACE("Set service status to %d\n",service->status.dwCurrentState);
r = TRUE;
break; break;
if (service) }
{
memcpy( &service->status, lpStatus, sizeof(SERVICE_STATUS) );
TRACE("Set service status to %d\n",service->status.dwCurrentState);
} }
else
r = FALSE;
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
return r; return r;
...@@ -2383,20 +2378,23 @@ SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW( LPCWSTR lpServiceNam ...@@ -2383,20 +2378,23 @@ SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW( LPCWSTR lpServiceNam
LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext ) LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext )
{ {
service_data *service; service_data *service;
SERVICE_STATUS_HANDLE handle = 0;
TRACE("%s %p %p\n", debugstr_w(lpServiceName), lpHandlerProc, lpContext); TRACE("%s %p %p\n", debugstr_w(lpServiceName), lpHandlerProc, lpContext);
EnterCriticalSection( &service_cs ); EnterCriticalSection( &service_cs );
for(service = service_list; service; service = service->next) LIST_FOR_EACH_ENTRY( service, &service_list, service_data, entry )
{
if(!strcmpW(lpServiceName, service->name)) if(!strcmpW(lpServiceName, service->name))
{
service->handler.handler_ex = lpHandlerProc;
service->context = lpContext;
service->extended = TRUE;
handle = (SERVICE_STATUS_HANDLE)service;
break; break;
if (service) }
{
service->handler.handler_ex = lpHandlerProc;
service->context = lpContext;
service->extended = TRUE;
} }
LeaveCriticalSection( &service_cs ); LeaveCriticalSection( &service_cs );
return (SERVICE_STATUS_HANDLE)service; return handle;
} }
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