[svn] GnuPG - r5445 - in trunk: agent common tests tests/openpgp tools

svn author wk cvs at cvs.gnupg.org
Thu Oct 14 10:32:56 CEST 2010


Author: wk
Date: 2010-10-14 10:32:55 +0200 (Thu, 14 Oct 2010)
New Revision: 5445

Modified:
   trunk/agent/gpg-agent.c
   trunk/common/ChangeLog
   trunk/common/asshelp.c
   trunk/tests/Makefile.am
   trunk/tests/openpgp/Makefile.am
   trunk/tests/openpgp/defs.inc
   trunk/tests/openpgp/gpg-agent.conf.tmpl
   trunk/tools/ChangeLog
   trunk/tools/gpg-connect-agent.c
   trunk/tools/gpgconf-comp.c
   trunk/tools/gpgconf.c
Log:
Some tweaks to the agent startup.


Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/common/ChangeLog	2010-10-14 08:32:55 UTC (rev 5445)
@@ -1,3 +1,9 @@
+2010-10-14  Werner Koch  <wk at g10code.com>
+
+	* asshelp.c (start_new_gpg_agent): Print a notice once the agent
+	has been started.
+	(start_new_dirmngr): Likewise.
+
 2010-10-13  Werner Koch  <wk at g10code.com>
 
 	* miscellaneous.c (parse_version_number, parse_version_string)

Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tools/ChangeLog	2010-10-14 08:32:55 UTC (rev 5445)
@@ -1,3 +1,11 @@
+2010-10-14  Werner Koch  <wk at g10code.com>
+
+	* gpg-connect-agent.c (start_agent): Rewrite using the
+	start_new_gpg_agent function.
+
+	* gpgconf-comp.c (gpg_agent_runtime_change): Use gpg-connect-agent
+	on all platforms.
+
 2010-10-06  Werner Koch  <wk at g10code.com>
 
 	* watchgnupg.c (print_version): Add option --time-only.

Modified: trunk/agent/gpg-agent.c
===================================================================
--- trunk/agent/gpg-agent.c	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/agent/gpg-agent.c	2010-10-14 08:32:55 UTC (rev 5445)
@@ -850,8 +850,31 @@
   /*log_info ("NOTE: this is a development version!\n");*/
 #endif
 
+#ifdef ENABLE_NLS
+  /* gpg-agent usually does not output any messages because it runs in
+     the background.  For log files it is acceptable to have messages
+     always encoded in utf-8.  We switch here to utf-8, so that
+     commands like --help still give native messages.  It is far
+     easier to switch only once instead of for every message and it
+     actually helps when more then one thread is active (avoids an
+     extra copy step). */
+    bind_textdomain_codeset (PACKAGE_GT, "UTF-8");
+#endif
+
+  if (!pipe_server && !is_daemon && !gpgconf_list)
+    {
+     /* We have been called without any options and thus we merely
+        check whether an agent is already running.  We do this right
+        here so that we don't clobber a logfile with this check but
+        print the status directly to stderr. */
+      opt.debug = 0;
+      set_debug ();
+      check_for_running_agent (0, 0);
+      agent_exit (0);
+    }
+
   set_debug ();
-  
+
   if (atexit (cleanup))
     {
       log_error ("atexit failed\n");
@@ -939,27 +962,6 @@
       agent_exit (0);
     }
 
-  /* If this has been called without any options, we merely check
-     whether an agent is already running.  We do this here so that we
-     don't clobber a logfile but print it directly to stderr. */
-  if (!pipe_server && !is_daemon)
-    {
-      log_set_prefix (NULL, JNLIB_LOG_WITH_PREFIX); 
-      check_for_running_agent (0, 0);
-      agent_exit (0);
-    }
-  
-#ifdef ENABLE_NLS
-  /* gpg-agent usually does not output any messages because it runs in
-     the background.  For log files it is acceptable to have messages
-     always encoded in utf-8.  We switch here to utf-8, so that
-     commands like --help still give native messages.  It is far
-     easier to switch only once instead of for every message and it
-     actually helps when more then one thread is active (avoids an
-     extra copy step). */
-    bind_textdomain_codeset (PACKAGE_GT, "UTF-8");
-#endif
-
   /* Now start with logging to a file if this is desired. */
   if (logfile)
     {

Modified: trunk/common/asshelp.c
===================================================================
--- trunk/common/asshelp.c	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/common/asshelp.c	2010-10-14 08:32:55 UTC (rev 5445)
@@ -422,14 +422,19 @@
                       int i;
 
                       if (verbose)
-                        log_info (_("waiting %d seconds for the %s "
-                                    "to come up\n"), 5, "agent" );
+                        log_info (_("waiting %d seconds for the agent "
+                                    "to come up\n"), 5);
                       for (i=0; i < 5; i++)
                         {
                           gnupg_sleep (1);
                           err = assuan_socket_connect (ctx, sockname, 0, 0);
                           if (!err)
-                            break;
+                            {
+                              if (verbose && !debug)
+                                log_info (_("connection to agent"
+                                            " established\n"));
+                              break;
+                            }
                         }
                     }
                 }
@@ -513,7 +518,7 @@
     }
 
   if (debug)
-    log_debug ("connection to agent established\n");
+    log_debug (_("connection to agent established\n"));
 
   err = assuan_transact (ctx, "RESET",
                         NULL, NULL, NULL, NULL, NULL, NULL);
@@ -606,14 +611,19 @@
               int i;
               
               if (verbose)
-                log_info (_("waiting %d seconds for the %s to come up\n"),
-                          5, "dirmngr" );
+                log_info (_("waiting %d seconds for the dirmngr to come up\n"),
+                          5);
               for (i=0; i < 5; i++)
                 {
                   gnupg_sleep (1);
                   err = assuan_socket_connect (ctx, sockname, 0, 0);
                   if (!err)
-                    break;
+                    {
+                      if (verbose && !debug)
+                        log_info (_("connection to the dirmngr"
+                                     " established\n"));
+                      break;
+                    }
                 }
             }
         }
@@ -637,7 +647,7 @@
     }
 
   if (debug)
-    log_debug ("connection to the dirmngr established\n");
+    log_debug (_("connection to the dirmngr established\n"));
 
   *r_ctx = ctx;
   return 0;

Modified: trunk/tests/Makefile.am
===================================================================
--- trunk/tests/Makefile.am	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tests/Makefile.am	2010-10-14 08:32:55 UTC (rev 5445)
@@ -46,7 +46,7 @@
              samplekeys/cert_g10code_test1.pem \
              samplekeys/cert_g10code_theo1.pem
 
-# We used to run $(testscripts) here but tehse asschk scripts ares not
+# We used to run $(testscripts) here but these asschk scripts ares not
 # completely reliable in all enviromnets and thus we better disable
 # them.  The tests are anyway way to minimal.  We will eventually
 # write new tests based on gpg-connect-agent which has a full fledged

Modified: trunk/tests/openpgp/Makefile.am
===================================================================
--- trunk/tests/openpgp/Makefile.am	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tests/openpgp/Makefile.am	2010-10-14 08:32:55 UTC (rev 5445)
@@ -16,15 +16,14 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 # Process this file with automake to create Makefile.in
 
-GPG_IMPORT = ../../g10/gpg2 --homedir . \
+GPG_IMPORT = ../../g10/gpg2 --homedir $(abs_builddir) \
               --quiet --yes --no-permission-warning --import
 
 # Programs required before we can run these tests.
 required_pgms = ../../g10/gpg2 ../../agent/gpg-agent \
                 ../../tools/gpg-connect-agent
 
-TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) GPG_AGENT_INFO= LC_ALL=C \
-		    ../../agent/gpg-agent --quiet --daemon sh
+TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) GPG_AGENT_INFO= LC_ALL=C
 
 TESTS = version.test mds.test \
 	decrypt.test decrypt-dsa.test \
@@ -68,7 +67,6 @@
 prepared.stamp: ./pubring.gpg ./secring.gpg ./plain-1 ./plain-2 ./plain-3 \
 		./pubring.pkr ./secring.skr ./gpg_dearmor $(DATA_FILES)
 	 $(GPG_IMPORT) $(srcdir)/pubdemo.asc	 
-	 cat $(srcdir)/gpg-agent.conf.tmpl > gpg-agent.conf
 	 echo timestamp >./prepared.stamp
 
 # We need to depend on a couple of programs so that the tests don't

Modified: trunk/tests/openpgp/defs.inc
===================================================================
--- trunk/tests/openpgp/defs.inc	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tests/openpgp/defs.inc	2010-10-14 08:32:55 UTC (rev 5445)
@@ -1,6 +1,6 @@
 # Definitions for the OpenPGP test scripts                     -*- sh -*-
 # Copyright 1998,1999,2000,2001,2002,2003,2004,2005,2006,
-#           2007 Free Software Foundation, Inc.
+#           2007, 2010 Free Software Foundation, Inc.
 # This file is free software; as a special exception the author gives
 # unlimited permission to copy and/or distribute it, with or without
 # modifications, as long as this notice is preserved.  This file is
@@ -161,26 +161,27 @@
 
 [ -z "$srcdir" ] && fatal "not called from make"
 
-# Make sure we have a valid option files even with VPATH builds.
-for f in gpg.conf ; do 
-  if [ -f ./$f ]; then
-    :
-  elif [ -f $srcdir/$f.tmpl ]; then
-    cat $srcdir/$f.tmpl >$f
-  fi
-done
-
 # Always work in the current directory.  We set GNUPGHOME only if it
 # has not been set already.  Usually it is set through the Makefile's
 # TESTS_ENVIRONMENT macro.
 if [ -z "$GNUPGHOME" ]; then
-  GNUPGHOME=`pwd`
+  GNUPGHOME=`/bin/pwd`
   export GNUPGHOME
-elif [ "$GNUPGHOME" != `pwd` ]; then
+elif [ "$GNUPGHOME" != `/bin/pwd` ]; then
   echo "$pgmname: GNUPGHOME not set to the cwd" $* >&2
   exit 1
 fi
 
+# Make sure we have a valid option files even with VPATH builds.
+for f in gpg.conf gpg-agent.conf ; do 
+  if [ -f ./$f ]; then
+    :
+  elif [ -f $srcdir/$f.tmpl ]; then
+    cat $srcdir/$f.tmpl >$f
+  fi
+done
+
+# (--no-permission-warning makes only sense on the commandline)
 GPG="../../g10/gpg2 --no-permission-warning "
 
 echo "Test: $pgmname"                  >  ${pgmname}.log

Modified: trunk/tests/openpgp/gpg-agent.conf.tmpl
===================================================================
--- trunk/tests/openpgp/gpg-agent.conf.tmpl	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tests/openpgp/gpg-agent.conf.tmpl	2010-10-14 08:32:55 UTC (rev 5445)
@@ -1,2 +1,3 @@
-no-use-standard-socket
+use-standard-socket
 
+

Modified: trunk/tools/gpg-connect-agent.c
===================================================================
--- trunk/tools/gpg-connect-agent.c	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tools/gpg-connect-agent.c	2010-10-14 08:32:55 UTC (rev 5445)
@@ -2156,131 +2156,28 @@
 static assuan_context_t
 start_agent (void)
 {
-  int rc = 0;
-  char *infostr, *p;
+  gpg_error_t err;
   assuan_context_t ctx;
   session_env_t session_env;
 
-  infostr = getenv ("GPG_AGENT_INFO");
-  if (!infostr || !*infostr)
-    {
-      char *sockname;
-
-      rc = assuan_new (&ctx);
-      if (rc)
-	{
-          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
-	  exit (1);
-	}
-
-      /* Check whether we can connect at the standard socket.  */
-      sockname = make_filename (opt.homedir, "S.gpg-agent", NULL);
-      rc = assuan_socket_connect (ctx, sockname, 0, 0);
-
-#ifdef HAVE_W32_SYSTEM
-      /* If we failed to connect under Windows, we fire up the agent.  */
-      if (gpg_err_code (rc) == GPG_ERR_ASS_CONNECT_FAILED)
-        {
-          const char *agent_program;
-          const char *argv[3];
-          int save_rc = rc;
-          
-          if (opt.verbose)
-            log_info (_("no running gpg-agent - starting one\n"));
-          agent_program = gnupg_module_name (GNUPG_MODULE_NAME_AGENT);
-          
-          argv[0] = "--daemon";
-          argv[1] = "--use-standard-socket"; 
-          argv[2] = NULL;  
-
-          rc = gnupg_spawn_process_detached (agent_program, argv, NULL);
-          if (rc)
-            log_debug ("failed to start agent `%s': %s\n",
-                       agent_program, gpg_strerror (rc));
-          else
-            {
-              /* Give the agent some time to prepare itself. */
-              gnupg_sleep (3);
-              /* Now try again to connect the agent.  */
-	      rc = assuan_new (&ctx);
-	      if (rc)
-		{
-		  log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
-		  exit (1);
-		}
-
-              rc = assuan_socket_connect (ctx, sockname, 0, 0);
-            }
-          if (rc)
-            rc = save_rc;
-        }
-#endif /*HAVE_W32_SYSTEM*/
-      xfree (sockname);
-    }
-  else
-    {
-      int prot;
-      int pid;
-
-      infostr = xstrdup (infostr);
-      if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
-        {
-          log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
-          xfree (infostr);
-          exit (1);
-        }
-      *p++ = 0;
-      pid = atoi (p);
-      while (*p && *p != PATHSEP_C)
-        p++;
-      prot = *p? atoi (p+1) : 0;
-      if (prot != 1)
-        {
-          log_error (_("gpg-agent protocol version %d is not supported\n"),
-                     prot);
-          xfree (infostr);
-          exit (1);
-        }
-
-      rc = assuan_new (&ctx);
-      if (rc)
-	{
-          log_error ("assuan_new failed: %s\n", gpg_strerror (rc));
-	  exit (1);
-	}
-
-      rc = assuan_socket_connect (ctx, infostr, pid, 0);
-      xfree (infostr);
-    }
-
-  if (rc)
-    {
-      log_error ("can't connect to the agent: %s\n", gpg_strerror (rc));
-      exit (1);
-    }
-
-  if (opt.verbose)
-    log_info ("connection to agent established\n");
-
-  rc = assuan_transact (ctx, "RESET", NULL, NULL, NULL, NULL, NULL, NULL);
-  if (rc)
-    {
-      log_error (_("error sending %s command: %s\n"), "RESET", 
-                 gpg_strerror (rc));
-      exit (1);
-    }
-
   session_env = session_env_new ();
   if (!session_env)
     log_fatal ("error allocating session environment block: %s\n",
                strerror (errno));
 
-  rc = send_pinentry_environment (ctx, GPG_ERR_SOURCE_DEFAULT,
-                                  NULL, NULL, session_env);
+  err = start_new_gpg_agent (&ctx,
+                             GPG_ERR_SOURCE_DEFAULT,
+                             opt.homedir,
+                             NULL,
+                             NULL, NULL,
+                             session_env,
+                             !opt.quiet, 0,
+                             NULL, NULL);
+
   session_env_release (session_env);
-  if (rc)
+  if (err)
     {
-      log_error (_("error sending standard options: %s\n"), gpg_strerror (rc));
+      log_error (_("error sending standard options: %s\n"), gpg_strerror (err));
       exit (1);
     }
 

Modified: trunk/tools/gpgconf-comp.c
===================================================================
--- trunk/tools/gpgconf-comp.c	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tools/gpgconf-comp.c	2010-10-14 08:32:55 UTC (rev 5445)
@@ -1032,35 +1032,6 @@
 static void
 gpg_agent_runtime_change (void)
 {
-#ifndef HAVE_W32_SYSTEM
-  char *agent = getenv ("GPG_AGENT_INFO");
-  char *pid_str;
-  unsigned long pid_long;
-  char *tail;
-  pid_t pid;
-
-  if (!agent)
-    return;
-
-  pid_str = strchr (agent, ':');
-  if (!pid_str)
-    return;
-
-  pid_str++;
-  errno = 0;
-  pid_long = strtoul (pid_str, &tail, 0);
-  if (errno || (*tail != ':' && *tail != '\0'))
-    return;
-
-  pid = (pid_t) pid_long;
-
-  /* Check for overflow.  */
-  if (pid_long != (unsigned long) pid)
-    return;
-
-  /* Ignore any errors here.  */
-  kill (pid, SIGHUP);
-#else
   gpg_error_t err;
   const char *pgmname;
   const char *argv[2];
@@ -1077,7 +1048,6 @@
     gc_error (0, 0, "error running `%s%s': %s",
               pgmname, " reloadagent", gpg_strerror (err));
   gnupg_release_process (pid);
-#endif /*!HAVE_W32_SYSTEM*/
 }
 
 

Modified: trunk/tools/gpgconf.c
===================================================================
--- trunk/tools/gpgconf.c	2010-10-13 15:57:08 UTC (rev 5444)
+++ trunk/tools/gpgconf.c	2010-10-14 08:32:55 UTC (rev 5445)
@@ -50,7 +50,6 @@
     aCheckConfig,
     aListDirs,
     aReload
-
   };
 
 
@@ -72,7 +71,7 @@
       N_("list global configuration file") },
     { aCheckConfig,   "check-config", 256,
       N_("check global configuration file") },
-    { aReload,        "reload", 256, "@" },
+    { aReload,        "reload", 256, N_("reload all or a given component")},
 
     { 301, NULL, 0, N_("@\nOptions:\n ") },
     





More information about the Gnupg-commits mailing list