2007-08-14 Marcus Brinkmann <marcus@g10code.de>
authorMarcus Brinkmann <mb@g10code.com>
Tue, 14 Aug 2007 15:42:34 +0000 (15:42 +0000)
committerMarcus Brinkmann <mb@g10code.com>
Tue, 14 Aug 2007 15:42:34 +0000 (15:42 +0000)
* src/g4wihelp.c (service_create): Auto start service, install as
local service.
(service_start): Set argv to NULL if argc is zero.
(service_stop): Wait until service is actually stopped.  Implement
the whole logic when to stop and when to wait.
* src/installer.nsi: Print warning about shutting down dirmngr.
Shutdown dirmngr.
* src/inst-dirmngr.nsi: Remove code refactored into service_stop.
Do not pass any arguments when starting the service.  Use
CreateDirectory instead of SetOutPath.
* src/uninst-dirmngr.nsi: Remove code factored into service_stop.
* src/inst-gnupg.nsi, src/inst-gnupg2.nsi, src/inst-gpa.nsi: Use
CreateDirectory instead SetOutPath.

ChangeLog
src/g4wihelp.c
src/inst-dirmngr.nsi
src/inst-gnupg.nsi
src/inst-gnupg2.nsi
src/inst-gpa.nsi
src/installer.nsi
src/uninst-dirmngr.nsi

index 6ca011e..743dc4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2007-08-14  Marcus Brinkmann  <marcus@g10code.de>
 
+       * src/g4wihelp.c (service_create): Auto start service, install as
+       local service.
+       (service_start): Set argv to NULL if argc is zero.
+       (service_stop): Wait until service is actually stopped.  Implement
+       the whole logic when to stop and when to wait.
+       * src/installer.nsi: Print warning about shutting down dirmngr.
+       Shutdown dirmngr.
+       * src/inst-dirmngr.nsi: Remove code refactored into service_stop.
+       Do not pass any arguments when starting the service.  Use
+       CreateDirectory instead of SetOutPath.
+       * src/uninst-dirmngr.nsi: Remove code factored into service_stop.
+       * src/inst-gnupg.nsi, src/inst-gnupg2.nsi, src/inst-gpa.nsi: Use
+       CreateDirectory instead SetOutPath.
+
        * patches/claws-mail-3.0.0-rc2/03-smime-plugin.patch: Change
        license string to "GPL3+" to make Claws load it.
 
index 0f9bc2d..6eccc54 100644 (file)
@@ -321,11 +321,13 @@ service_create (HWND hwndParent, int string_size, char *variables,
 
   service = CreateService (sc, service_name, display_name,
                           SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
-                          /* FIXME: As long as we are debugging... */
-                          SERVICE_DEMAND_START /* SERVICE_AUTO_START */,
+                          /* Use SERVICE_DEMAND_START for testing.
+                             FIXME: Currently not configurable by caller.  */
+                          SERVICE_AUTO_START,
                           SERVICE_ERROR_NORMAL, program,
                           NULL, NULL, NULL,
-                          NULL /* FIXME: "NT AUTHORITY\LocalService"? */,
+                          /* FIXME: Currently not configurable by caller.  */
+                          "NT AUTHORITY\\LocalService",
                           NULL);
   if (service == NULL)
     {
@@ -485,7 +487,7 @@ service_start (HWND hwndParent, int string_size, char *variables,
   if (service == NULL)
     return;
 
-  err = StartService (service, argc, argv);
+  err = StartService (service, argc, argc == 0 ? NULL : argv);
   if (err == 0)
     {
       service_error ("StartService");
@@ -508,6 +510,8 @@ service_stop (HWND hwndParent, int string_size, char *variables,
   char service_name[256];
   int err = 0;
   SERVICE_STATUS status;
+  DWORD timeout = 10000;       /* 10 seconds.  */
+  DWORD start_time;
 
   g_hwndParent = hwndParent;
   EXDLL_INIT();
@@ -525,15 +529,51 @@ service_stop (HWND hwndParent, int string_size, char *variables,
   if (service == NULL)
     return;
 
-  err = ControlService (service, SERVICE_CONTROL_STOP, &status);
+  err = QueryServiceStatus (service, &status);
   if (err == 0)
     {
-      service_error ("ControlService");
+      service_error ("QueryService");
       CloseServiceHandle (service);
       return;
     }
-  CloseServiceHandle (service);
 
+  if (status.dwCurrentState != SERVICE_STOPPED
+      && status.dwCurrentState != SERVICE_STOP_PENDING)
+    {
+      err = ControlService (service, SERVICE_CONTROL_STOP, &status);
+      if (err == 0)
+       {
+         service_error ("ControlService");
+         CloseServiceHandle (service);
+         return;
+       }
+    }
+
+  start_time = GetTickCount ();
+  while (status.dwCurrentState != SERVICE_STOPPED)
+    {
+      Sleep (1000);    /* One second.  */
+      if (!QueryServiceStatus (service, &status))
+       {
+         service_error ("QueryService");
+         CloseServiceHandle (service);
+         return;
+       }
+      if (status.dwCurrentState == SERVICE_STOPPED)
+       break;
+
+      if (GetTickCount () - start_time > timeout)
+       {
+         char buf[1024];
+         snprintf (buf, sizeof (buf) - 1,
+                   "time out waiting for service %s to stop\r\n",
+                   service_name);
+         MessageBox (g_hwndParent, buf, 0, MB_OK);
+         setuservariable (INST_R0, "1");
+         return;
+       }
+    }
+  CloseServiceHandle (service);
   setuservariable (INST_R0, "0");
   return;
 }
index 9d2c61a..8ee22ea 100644 (file)
@@ -37,11 +37,6 @@ Section "-dirmngr" SEC_dirmngr
   g4wihelp::service_query "DirMngr"
   StrCpy $DirMngrStatus $R0
 
-  StrCmp $DirMngrStatus "MISSING" dirmngr_stopped
-  # Try to stop the daemon in case it is running.
-  g4wihelp::service_stop "DirMngr"
-dirmngr_stopped:
-
   File "${prefix}/bin/dirmngr.exe"
   File "${prefix}/bin/dirmngr-client.exe"
   File "${prefix}/libexec/dirmngr_ldap.exe"
@@ -51,25 +46,22 @@ dirmngr_stopped:
   # different.  FIXME.
   CreateDirectory "$INSTDIR\cache"
 
-  # FIXME: Error checking.  Also, check if --service really reaches
-  # the service both times.
-
   StrCmp $DirMngrStatus "MISSING" 0 dirmngr_created
     # Create the service.
-    g4wihelp::service_create "DirMngr" "DirMngr" '"$INSTDIR\dirmngr.exe" --service'
-dirmngr_created:
+    g4wihelp::service_create "DirMngr" "DirMngr" \
+                             '"$INSTDIR\dirmngr.exe" --service'
+  dirmngr_created:
 
-  # We only start the dirmngr if it was running before.
-  StrCmp $DirMngrStatus "RUNNING" 0 dirmngr_restarted
   # Start the service.
-  g4wihelp::service_start "DirMngr" "1" "\"$INSTDIR\dirmngr.exe\""
-dirmngr_restarted:
-
+  # FIXME: This does not work.  Luckily, it is also not needed.
+  # g4wihelp::service_start "DirMngr" "2" '"$INSTDIR\dirmngr.exe"' "--service"
+  # This works.
+  g4wihelp::service_start "DirMngr" 0
 
   # If requested, install the configuration files.
   ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" AppData
   StrCmp $0 "" no_config_dirmngr_files
-  SetOutPath "$0\gnupg"
+  CreateDirectory "$0\gnupg"
 
   g4wihelp::config_fetch "dirmngr.conf"
   StrCmp $R0 "" no_config_dirmngr_conf
index 45709b5..df2d830 100644 (file)
@@ -69,7 +69,7 @@ Section "GnuPG" SEC_gnupg
   StrCmp $ConfigGPGConf "" no_config_gpg_conf
     ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" AppData
     StrCmp $0 "" no_config_gpg_conf
-    SetOutPath "$0\gnupg"
+    CreateDirectory "$0\gnupg"
     CopyFiles $ConfigGPGConf "$0\gnupg\gpg.conf"
   no_config_gpg_conf:
 
index 8dc0020..2fb98dd 100644 (file)
@@ -67,7 +67,7 @@ Section /o "GnuPG2" SEC_gnupg2
   # If requested, install the configuration files.
   ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" AppData
   StrCmp $0 "" no_config_gpg_conf_files
-  SetOutPath "$0\gnupg"
+  CreateDirectory "$0\gnupg"
 
   g4wihelp::config_fetch "gpg.conf"
   StrCmp $R0 "" no_config_gpg2_conf
index 34e5f10..2ac816e 100644 (file)
@@ -46,7 +46,7 @@ Section "GPA" SEC_gpa
   # If requested, install the configuration files.
   ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" AppData
   StrCmp $0 "" no_config_gpa_files
-  SetOutPath "$0\gnupg"
+  CreateDirectory "$0\gnupg"
 
   g4wihelp::config_fetch "gpa.conf"
   StrCmp $R0 "" no_config_gpa_conf
index 50d6f3a..d720c91 100644 (file)
@@ -1,5 +1,5 @@
 # installer.nsi - Installer for GnuPG 4 Windows.    -*- coding: latin-1; -*-
-# Copyright (C) 2005 g10 Code GmbH
+# Copyright (C) 2005, 2007 g10 Code GmbH
 # 
 # This file is part of GPG4Win.
 # 
@@ -391,12 +391,16 @@ Function PrintCloseOtherApps
     IfFileExists $INSTDIR\gpa.exe   print_warning
     IfFileExists $INSTDIR\gpgol.dll print_warning
     IfFileExists $INSTDIR\gpgee.dll print_warning
+    IfFileExists $INSTDIR\dirmngr.exe print_warning
     Return
    print_warning:
     MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_CloseOtherApps)"
     IfFileExists $INSTDIR\winpt.exe 0 +3
       MessageBox MB_OK "$(T_ShuttingDownWinPT)"
       ExecWait '"$INSTDIR\winpt.exe" --stop'
+    IfFileExists $INSTDIR\dirmngr.exe 0 +3
+      MessageBox MB_OK "$(T_ShuttingDownDirMngr)"
+      g4wihelp::service_stop "DirMngr"
    leave:
 FunctionEnd
 
@@ -500,6 +504,8 @@ LangString T_CloseOtherApps ${LANG_ENGLISH} \
     will be required then."
 LangString T_ShuttingDownWinPT ${LANG_ENGLISH} \
    "Trying to shutdown a possible running instance of WinPT."
+LangString T_ShuttingDownDirMngr ${LANG_ENGLISH} \
+   "Trying to shutdown a possible running instance of DirMngr."
 
 
 # FIXME: The GetAfterChar function comes from the NSIS wiki.
index b32b543..cd13875 100644 (file)
@@ -1,4 +1,4 @@
-# uninst-dirmngr.nsi - Uninstaller snippet.        -*- coding: latin-1; -*-
+ # uninst-dirmngr.nsi - Uninstaller snippet.        -*- coding: latin-1; -*-
 # Copyright (C) 2007 g10 Code GmbH
 # 
 # This file is part of Gpg4win.
@@ -31,17 +31,10 @@ Section "-un.dirmngr"
   Push "${gpg4win_pkg_dirmngr}"
   Call un.SourceDelete
 !else
-  # We need to stop before delete.
-  Var /GLOBAL DirMngrUninstStatus
-  g4wihelp::service_query "DirMngr"
-  StrCpy $DirMngrUninstStatus $R0
-  StrCmp $DirMngrUninstStatus "MISSING" dirmngr_uninst_deleted
-  StrCmp $DirMngrUninstStatus "RUNNING" 0 dirmngr_uninst_stopped
   # Try to stop the daemon in case it is running.
   g4wihelp::service_stop "DirMngr"
-dirmngr_uninst_stopped:
+
   g4wihelp::service_delete "DirMngr"
-dirmngr_uninst_deleted:
 
   Delete "$INSTDIR\dirmngr.exe"
   Delete "$INSTDIR\dirmngr-client.exe"