fixes-from-andrei-20040427
authorJeffrey Altman <jaltman@mit.edu>
Tue, 27 Apr 2004 19:58:48 +0000 (19:58 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 27 Apr 2004 19:58:48 +0000 (19:58 +0000)
Cleanup the makefile to remove unnecessary defaultlib restrictions

Remove the DST fix added to address Rodney's bug with the timezone being
off by an hour on files one hour after the time change.  Still need to
identify the real cause.

Finally fix once and for all the afsd_service.exe shutdown error.
The ServiceHandler must be declared with the WINAPI calling convention
because it returns a value.

src/WINNT/afsd/NTMakefile
src/WINNT/afsd/afsd_service.c
src/WINNT/afsd/smb.c

index 5bbfd42..52bca39 100644 (file)
@@ -139,7 +139,7 @@ $(INCFILEDIR)\afsd_eventmessages.h:  afsd_eventmessages.mc
 # Flags for linking LOGON DLL'S
 #
 
-LOGONLINKFLAGS = -entry:DllEntryPoint /NODEFAULTLIB:msvcr70d.lib /NODEFAULTLIB:msvcrtd.lib  msvcrt.lib
+LOGONLINKFLAGS = -entry:DllEntryPoint
 
 
 ############################################################################
@@ -328,7 +328,7 @@ $(AFSD_EXEFILE): $(OUT)\afsd.obj $(AFSDOBJS) $(OUT)\afsd.res  $(RXOBJS) $(AFSD_E
 
 # afsd_service.exe
 $(EXEDIR)\afsd_service.exe: $(OUT)\afsd_service.obj $(AFSDOBJS) $(OUT)\afsd_service.res  $(RXOBJS) $(AFSD_EXELIBS)
-       $(EXECONLINK) $(AFSD_SDKLIBS) /NODEFAULTLIB:libc.lib /MAP 
+       $(EXECONLINK) $(AFSD_SDKLIBS) /MAP 
        $(EXEPREP)
 
 # fs.exe
index 0185691..4291b1c 100644 (file)
@@ -146,11 +146,65 @@ afsd_ServiceFlushVolume(DWORD dwlpEventData)
     return dwRet;
 }
 
+
+/* service control handler used in nt4 only for backward compat. */
+VOID WINAPI 
+afsd_ServiceControlHandler(DWORD ctrlCode)
+{
+       HKEY parmKey;
+       DWORD dummyLen, doTrace;
+       long code;
+
+       switch (ctrlCode) {
+               case SERVICE_CONTROL_STOP:
+                       /* Shutdown RPC */
+                       RpcMgmtStopServerListening(NULL);
+
+                       /* Force trace if requested */
+                       code = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                                           AFSConfigKeyName,
+                                           0, KEY_QUERY_VALUE, &parmKey);
+                       if (code != ERROR_SUCCESS)
+                               goto doneTrace;
+
+                       dummyLen = sizeof(doTrace);
+                       code = RegQueryValueEx(parmKey, "TraceOnShutdown",
+                                               NULL, NULL,
+                                               (BYTE *) &doTrace, &dummyLen);
+                       RegCloseKey (parmKey);
+                       if (code != ERROR_SUCCESS)
+                               doTrace = 0;
+                       if (doTrace)
+                               afsd_ForceTrace(FALSE);
+
+doneTrace:
+                       ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
+                       ServiceStatus.dwWin32ExitCode = NO_ERROR;
+                       ServiceStatus.dwCheckPoint = 1;
+                       ServiceStatus.dwWaitHint = 10000;
+                       ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+                       SetServiceStatus(StatusHandle, &ServiceStatus);
+                       SetEvent(WaitToTerminate);
+                       break;
+               case SERVICE_CONTROL_INTERROGATE:
+                       ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+                       ServiceStatus.dwWin32ExitCode = NO_ERROR;
+                       ServiceStatus.dwCheckPoint = 0;
+                       ServiceStatus.dwWaitHint = 0;
+                       ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+                       SetServiceStatus(StatusHandle, &ServiceStatus);
+                       break;
+               /* XXX handle system shutdown */
+               /* XXX handle pause & continue */
+       }
+}
+
+
 /*
 **    Extended ServiceControlHandler that provides Event types
 **    for monitoring Power events, for example.
 */
-DWORD
+DWORD WINAPI
 afsd_ServiceControlHandlerEx(
               DWORD  ctrlCode,
               DWORD  dwEventType,
@@ -350,6 +404,16 @@ typedef BOOL ( APIENTRY * AfsdInitHook )(void);
 #define AFSD_INIT_HOOK "AfsdInitHook"
 #define AFSD_HOOK_DLL  "afsdhook.dll"
 
+/*
+control serviceex exists only on 2000/xp. These functions will be loaded dynamically.
+*/
+
+typedef SERVICE_STATUS_HANDLE ( * RegisterServiceCtrlHandlerExFunc )(  LPCTSTR , LPHANDLER_FUNCTION_EX , LPVOID );
+typedef SERVICE_STATUS_HANDLE ( * RegisterServiceCtrlHandlerFunc   )(  LPCTSTR ,  LPHANDLER_FUNCTION );
+
+RegisterServiceCtrlHandlerExFunc pRegisterServiceCtrlHandlerEx = NULL;
+RegisterServiceCtrlHandlerFunc   pRegisterServiceCtrlHandler   = NULL; 
+
 void afsd_Main(DWORD argc, LPTSTR *argv)
 {
        long code;
@@ -358,6 +422,7 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
        int jmpret;
 #endif /* JUMP */
     HANDLE hInitHookDll;
+    HANDLE hAdvApi32;
     AfsdInitHook initHook;
 
 #ifdef _DEBUG
@@ -377,10 +442,23 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
         afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate"));
 
 #ifndef NOTSERVICE
-       StatusHandle = RegisterServiceCtrlHandlerEx(argv[0] /* AFS_DAEMON_SERVICE_NAME */,
-                       (LPHANDLER_FUNCTION_EX) afsd_ServiceControlHandlerEx,
-                                                 NULL /* user context */
-                                                 );
+    hAdvApi32 = LoadLibrary("advapi32.dll");
+    if (hAdvApi32 == NULL)
+    {
+        afsi_log("Fatal: cannot load advapi32.dll");
+        return;
+    }
+
+    pRegisterServiceCtrlHandlerEx = (RegisterServiceCtrlHandlerExFunc)GetProcAddress(hAdvApi32, "RegisterServiceCtrlHandlerExA");
+    if (pRegisterServiceCtrlHandlerEx)
+    {
+        afsi_log("running on 2000+ - using RegisterServiceCtrlHandlerEx");
+        StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandlerEx, NULL );
+    }
+    else
+    {
+        StatusHandle = RegisterServiceCtrlHandler(AFS_DAEMON_SERVICE_NAME, afsd_ServiceControlHandler);
+    }
 
        ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
        ServiceStatus.dwServiceSpecificExitCode = 0;
@@ -417,7 +495,8 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
             hookRc = initHook();
         }
         FreeLibrary(hInitHookDll);
-               
+        hInitHookDll = NULL;
+
         if (hookRc == FALSE)
         {
             ServiceStatus.dwCurrentState = SERVICE_STOPPED;
@@ -524,18 +603,12 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
     /* Remove the ExceptionFilter */
     SetUnhandledExceptionFilter(NULL);
 
-    if ( hInitHookDll )
-        FreeLibrary(hInitHookDll);
-
-    Sleep(5000);
-
     ServiceStatus.dwCurrentState = SERVICE_STOPPED;
        ServiceStatus.dwWin32ExitCode = GlobalStatus ? ERROR_EXCEPTION_IN_SERVICE : NO_ERROR;
        ServiceStatus.dwCheckPoint = 0;
        ServiceStatus.dwWaitHint = 0;
        ServiceStatus.dwControlsAccepted = 0;
        SetServiceStatus(StatusHandle, &ServiceStatus);
-
 }
 
 DWORD __stdcall afsdMain_thread(void* notUsed)
index 3512ef5..21122e4 100644 (file)
@@ -530,7 +530,14 @@ smb_CalculateNowTZ()
        local_tm = *(localtime(&t));
 
        days = local_tm.tm_yday - gmt_tm.tm_yday;
-       hours = 24 * days + local_tm.tm_hour - gmt_tm.tm_hour - (local_tm.tm_isdst ? 1 : 0);
+       hours = 24 * days + local_tm.tm_hour - gmt_tm.tm_hour
+#ifdef COMMENT
+        /* There is a problem with DST immediately after the time change
+         * which may continue to exist until the machine is rebooted
+         */
+        - (local_tm.tm_isdst ? 1 : 0)
+#endif /* COMMENT */
+        ;
        minutes = 60 * hours + local_tm.tm_min - gmt_tm.tm_min;
        seconds = 60 * minutes + local_tm.tm_sec - gmt_tm.tm_sec;