Windows: afslogon start service if not started
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 26 Jul 2011 21:32:28 +0000 (17:32 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Sun, 31 Jul 2011 17:17:31 +0000 (10:17 -0700)
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 <buildbot@rampaginggeek.com>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/afslogon.c

index e2c89c0..c34db83 100644 (file)
@@ -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)) {