[Gpg4win-commits] r474 - in trunk: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 14 17:42:35 CEST 2007


Author: marcus
Date: 2007-08-14 17:42:34 +0200 (Tue, 14 Aug 2007)
New Revision: 474

Modified:
   trunk/ChangeLog
   trunk/src/g4wihelp.c
   trunk/src/inst-dirmngr.nsi
   trunk/src/inst-gnupg.nsi
   trunk/src/inst-gnupg2.nsi
   trunk/src/inst-gpa.nsi
   trunk/src/installer.nsi
   trunk/src/uninst-dirmngr.nsi
Log:
2007-08-14  Marcus Brinkmann  <marcus at 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.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/ChangeLog	2007-08-14 15:42:34 UTC (rev 474)
@@ -1,5 +1,19 @@
 2007-08-14  Marcus Brinkmann  <marcus at 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.
 

Modified: trunk/src/g4wihelp.c
===================================================================
--- trunk/src/g4wihelp.c	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/g4wihelp.c	2007-08-14 15:42:34 UTC (rev 474)
@@ -321,11 +321,13 @@
 
   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 @@
   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 @@
   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 @@
   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;
     }
+
+  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;
 }

Modified: trunk/src/inst-dirmngr.nsi
===================================================================
--- trunk/src/inst-dirmngr.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/inst-dirmngr.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -37,11 +37,6 @@
   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 @@
   # 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

Modified: trunk/src/inst-gnupg.nsi
===================================================================
--- trunk/src/inst-gnupg.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/inst-gnupg.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -69,7 +69,7 @@
   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:
 

Modified: trunk/src/inst-gnupg2.nsi
===================================================================
--- trunk/src/inst-gnupg2.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/inst-gnupg2.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -67,7 +67,7 @@
   # 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

Modified: trunk/src/inst-gpa.nsi
===================================================================
--- trunk/src/inst-gpa.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/inst-gpa.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -46,7 +46,7 @@
   # 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

Modified: trunk/src/installer.nsi
===================================================================
--- trunk/src/installer.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/installer.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -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 @@
     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 @@
     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.

Modified: trunk/src/uninst-dirmngr.nsi
===================================================================
--- trunk/src/uninst-dirmngr.nsi	2007-08-14 12:41:59 UTC (rev 473)
+++ trunk/src/uninst-dirmngr.nsi	2007-08-14 15:42:34 UTC (rev 474)
@@ -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 @@
   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"



More information about the Gpg4win-commits mailing list