1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

(check_for_running_agent): New.

(main): The default action is now to check for an already running
agent.
(parse_rereadable_options): Set logfile only on reread.
(main): Do not print the "is development version" note.
This commit is contained in:
Werner Koch 2004-09-09 07:27:57 +00:00
parent 45accef52a
commit 0cb56ad4ac
4 changed files with 86 additions and 9 deletions

6
NEWS
View File

@ -5,6 +5,12 @@ Noteworthy changes in version 1.9.11
certificates are validated and only imported if they are fully certificates are validated and only imported if they are fully
valid. valid.
* [gpg-agent] New option --max-cache-ttl.
* [gpg-agent] When used without --daemon or --server, gpg-agent now
check whether a agent is already running and usable.
Noteworthy changes in version 1.9.10 (2004-07-22) Noteworthy changes in version 1.9.10 (2004-07-22)
------------------------------------------------- -------------------------------------------------

4
THANKS
View File

@ -1,5 +1,5 @@
Alexander Belopolsky belopolsky at mac.com
Richard Lefebvre rick at CERCA.UMontreal.CA Richard Lefebvre rick at cerca.umontreal.ca
Andrew J. Schorr aschorr at telemetry-investments.com Andrew J. Schorr aschorr at telemetry-investments.com
Michael Nottebrock michaelnottebrock at gmx.net Michael Nottebrock michaelnottebrock at gmx.net

View File

@ -1,3 +1,11 @@
2004-09-09 Werner Koch <wk@g10code.de>
* gpg-agent.c (check_for_running_agent): New.
(main): The default action is now to check for an already running
agent.
(parse_rereadable_options): Set logfile only on reread.
(main): Do not print the "is development version" note.
2004-08-20 Werner Koch <wk@g10code.de> 2004-08-20 Werner Koch <wk@g10code.de>
* gpg-agent.c: New option --max-cache-ttl. Suggested by Alexander * gpg-agent.c: New option --max-cache-ttl. Suggested by Alexander

View File

@ -178,6 +178,7 @@ static void handle_connections (int listen_fd);
GCRY_THREAD_OPTION_PTH_IMPL; GCRY_THREAD_OPTION_PTH_IMPL;
#endif /*USE_GNU_PTH*/ #endif /*USE_GNU_PTH*/
static void check_for_running_agent (void);
@ -361,8 +362,9 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
case oDebugLevel: debug_level = pargs->r.ret_str; break; case oDebugLevel: debug_level = pargs->r.ret_str; break;
case oLogFile: case oLogFile:
if (!current_logfile || !pargs->r.ret_str if (reread
|| strcmp (current_logfile, pargs->r.ret_str)) && (!current_logfile || !pargs->r.ret_str
|| strcmp (current_logfile, pargs->r.ret_str)))
{ {
log_set_file (pargs->r.ret_str); log_set_file (pargs->r.ret_str);
xfree (current_logfile); xfree (current_logfile);
@ -599,7 +601,9 @@ main (int argc, char **argv )
fprintf (stderr, "%s\n", strusage(15) ); fprintf (stderr, "%s\n", strusage(15) );
} }
#ifdef IS_DEVELOPMENT_VERSION #ifdef IS_DEVELOPMENT_VERSION
log_info ("NOTE: this is a development version!\n"); /* We don't want to print it here because gpg-agent is useful of its
own and quite matured. */
/*log_info ("NOTE: this is a development version!\n");*/
#endif #endif
set_debug (); set_debug ();
@ -669,9 +673,15 @@ main (int argc, char **argv )
agent_exit (0); 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) if (!pipe_server && !is_daemon)
log_info (_("please use the option `--daemon'" {
" to run the program in the background\n")); log_set_prefix (NULL, JNLIB_LOG_WITH_PREFIX);
check_for_running_agent ();
agent_exit (0);
}
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
/* gpg-agent usually does not output any messages because it runs in /* gpg-agent usually does not output any messages because it runs in
@ -705,9 +715,9 @@ main (int argc, char **argv )
start_command_handler (-1, -1); start_command_handler (-1, -1);
} }
else if (!is_daemon) else if (!is_daemon)
; ; /* NOTREACHED */
else else
{ /* regular server mode */ { /* Regular server mode */
int fd; int fd;
pid_t pid; pid_t pid;
int len; int len;
@ -1220,3 +1230,56 @@ handle_connections (int listen_fd)
log_info ("%s %s stopped\n", strusage(11), strusage(13)); log_info ("%s %s stopped\n", strusage(11), strusage(13));
} }
#endif /*USE_GNU_PTH*/ #endif /*USE_GNU_PTH*/
/* Figure out whether an agent is available and running. Prints an
error if not. */
static void
check_for_running_agent ()
{
int rc;
char *infostr, *p;
assuan_context_t ctx;
int prot, pid;
infostr = getenv ("GPG_AGENT_INFO");
if (!infostr || !*infostr)
{
log_error (_("no gpg-agent running in this session\n"));
return;
}
infostr = xstrdup (infostr);
if ( !(p = strchr (infostr, ':')) || p == infostr)
{
log_error (_("malformed GPG_AGENT_INFO environment variable\n"));
xfree (infostr);
return;
}
*p++ = 0;
pid = atoi (p);
while (*p && *p != ':')
p++;
prot = *p? atoi (p+1) : 0;
if (prot != 1)
{
log_error (_("gpg-agent protocol version %d is not supported\n"),
prot);
xfree (infostr);
return;
}
rc = assuan_socket_connect (&ctx, infostr, pid);
xfree (infostr);
if (rc)
{
log_error ("can't connect to the agent: %s\n", assuan_strerror (rc));
return;
}
if (!opt.quiet)
log_info ("gpg-agent running and available\n");
assuan_disconnect (ctx);
}