services: Hold startup lock before calling service_start.

Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sebastian Lackner 2016-08-18 09:30:33 +02:00 committed by Alexandre Julliard
parent 36ccc45db6
commit 4c01feb714
3 changed files with 11 additions and 15 deletions

View File

@ -1071,8 +1071,12 @@ DWORD __cdecl svcctl_StartServiceW(
if (service->service_entry->config.dwStartType == SERVICE_DISABLED) if (service->service_entry->config.dwStartType == SERVICE_DISABLED)
return ERROR_SERVICE_DISABLED; return ERROR_SERVICE_DISABLED;
if (!scmdatabase_lock_startup(service->service_entry->db))
return ERROR_SERVICE_DATABASE_LOCKED;
err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors); err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
scmdatabase_unlock_startup(service->service_entry->db);
return err; return err;
} }
@ -1226,9 +1230,8 @@ DWORD __cdecl svcctl_LockServiceDatabase(
if ((err = validate_scm_handle(hSCManager, SC_MANAGER_LOCK, &manager)) != ERROR_SUCCESS) if ((err = validate_scm_handle(hSCManager, SC_MANAGER_LOCK, &manager)) != ERROR_SUCCESS)
return err; return err;
err = scmdatabase_lock_startup(manager->db); if (!scmdatabase_lock_startup(manager->db))
if (err != ERROR_SUCCESS) return ERROR_SERVICE_DATABASE_LOCKED;
return err;
lock = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock)); lock = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock));
if (!lock) if (!lock)

View File

@ -352,6 +352,7 @@ static void scmdatabase_autostart_services(struct scmdatabase *db)
size = i; size = i;
scmdatabase_unlock(db); scmdatabase_unlock(db);
while (!scmdatabase_lock_startup(db)) Sleep(10);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
@ -364,6 +365,7 @@ static void scmdatabase_autostart_services(struct scmdatabase *db)
release_service(service); release_service(service);
} }
scmdatabase_unlock_startup(db);
HeapFree(GetProcessHeap(), 0, services_list); HeapFree(GetProcessHeap(), 0, services_list);
} }
@ -608,11 +610,9 @@ static DWORD scmdatabase_load_services(struct scmdatabase *db)
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
DWORD scmdatabase_lock_startup(struct scmdatabase *db) BOOL scmdatabase_lock_startup(struct scmdatabase *db)
{ {
if (InterlockedCompareExchange(&db->service_start_lock, TRUE, FALSE)) return !InterlockedCompareExchange(&db->service_start_lock, TRUE, FALSE);
return ERROR_SERVICE_DATABASE_LOCKED;
return ERROR_SUCCESS;
} }
void scmdatabase_unlock_startup(struct scmdatabase *db) void scmdatabase_unlock_startup(struct scmdatabase *db)
@ -904,10 +904,6 @@ DWORD service_start(struct service_entry *service, DWORD service_argc, LPCWSTR *
struct process_entry *process = NULL; struct process_entry *process = NULL;
DWORD err; DWORD err;
err = scmdatabase_lock_startup(service->db);
if (err != ERROR_SUCCESS)
return err;
err = service_start_process(service, &process); err = service_start_process(service, &process);
if (err == ERROR_SUCCESS) if (err == ERROR_SUCCESS)
{ {
@ -928,10 +924,7 @@ DWORD service_start(struct service_entry *service, DWORD service_argc, LPCWSTR *
release_process(process); release_process(process);
} }
scmdatabase_unlock_startup(service->db);
WINE_TRACE("returning %d\n", err); WINE_TRACE("returning %d\n", err);
return err; return err;
} }

View File

@ -72,7 +72,7 @@ struct service_entry *scmdatabase_find_service(struct scmdatabase *db, LPCWSTR n
struct service_entry *scmdatabase_find_service_by_displayname(struct scmdatabase *db, LPCWSTR name); struct service_entry *scmdatabase_find_service_by_displayname(struct scmdatabase *db, LPCWSTR name);
DWORD scmdatabase_add_service(struct scmdatabase *db, struct service_entry *entry); DWORD scmdatabase_add_service(struct scmdatabase *db, struct service_entry *entry);
DWORD scmdatabase_lock_startup(struct scmdatabase *db); BOOL scmdatabase_lock_startup(struct scmdatabase *db);
void scmdatabase_unlock_startup(struct scmdatabase *db); void scmdatabase_unlock_startup(struct scmdatabase *db);
void scmdatabase_lock(struct scmdatabase *db); void scmdatabase_lock(struct scmdatabase *db);