From: Jeffrey Altman Date: Tue, 26 Jul 2011 21:32:28 +0000 (-0400) Subject: Windows: afslogon start service if not started X-Git-Tag: upstream/1.8.0_pre1^2~3468 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=a063ecdc78cf888df2459b32b0082d4767948563;p=packages%2Fo%2Fopenafs.git Windows: afslogon start service if not started If the service is configured for auto start but has yet to start, kick it off just in case. Change-Id: I668961b17472a78ebac6744bf131dcb850d4e4a2 Reviewed-on: http://gerrit.openafs.org/5109 Tested-by: BuildBot Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- diff --git a/src/WINNT/afsd/afslogon.c b/src/WINNT/afsd/afslogon.c index e2c89c05d..c34db835c 100644 --- a/src/WINNT/afsd/afslogon.c +++ b/src/WINNT/afsd/afslogon.c @@ -315,6 +315,28 @@ BOOL IsServiceStartPending (void) return (Status.dwCurrentState == SERVICE_START_PENDING); } +BOOL StartTheService (void) +{ + SC_HANDLE hManager; + DWORD gle = 0; + + if ((hManager = OpenSCManager (NULL, NULL, GENERIC_READ|SERVICE_START)) != NULL) + { + SC_HANDLE hService; + if ((hService = OpenService (hManager, TEXT("TransarcAFSDaemon"), GENERIC_READ|SERVICE_START)) != NULL) + { + StartService (hService, 0, NULL); + gle = GetLastError(); + CloseServiceHandle (hService); + } else + gle = GetLastError(); + + CloseServiceHandle (hManager); + } + DebugEvent("AFS AfsLogon - Service Start Return Code[0x%x]",gle); + return (gle == 0); +} + /* LOOKUPKEYCHAIN: macro to look up the value in the list of keys in order until it's found v:variable to receive value (reference type) t:type @@ -934,8 +956,19 @@ DWORD APIENTRY NPLogonNotify( /* loop until AFS is started. */ if (afsWillAutoStart) { - while (IsServiceRunning() || IsServiceStartPending()) { - DebugEvent("while(autostart) LogonOption[%x], Service AutoStart[%d]", + /* + * If the service is configured for auto start but hasn't started yet, + * give it a shove. + */ + if (!(IsServiceRunning() || IsServiceStartPending())) + StartTheService(); + + while ( IsServiceStartPending() ) { + Sleep(10); + } + + while (IsServiceRunning()) { + DebugEvent("while(autostart) LogonOption[%x], Service AutoStart[%d]", opt.LogonOption,afsWillAutoStart); if (ISADREALM(opt.flags)) {