mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
assuan: Reorganize waiting for socket.
* common/asshelp.c (wait_for_sock): New function, collecting codepaths from... (start_new_gpg_agent) here and... (start_new_dirmngr) here. -- This has no functional change, but makes it easier to make this function more efficient. GnuPG-bug-id: 3490 Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net> (cherry picked from commit 0471ff9d3bf8d6b9a359f3c426d70d0935066907)
This commit is contained in:
parent
0709f358cd
commit
a22a55b994
@ -307,6 +307,32 @@ unlock_spawning (lock_spawn_t *lock, const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
static gpg_error_t
|
||||
wait_for_sock (int secs, const char *name, const char *sockname, int verbose, assuan_context_t ctx, int *did_success_msg)
|
||||
{
|
||||
int i;
|
||||
gpg_error_t err = 0;
|
||||
for (i=0; i < secs; i++)
|
||||
{
|
||||
if (verbose)
|
||||
log_info (_("waiting for the %s to come up ... (%ds)\n"),
|
||||
name, secs - i);
|
||||
gnupg_sleep (1);
|
||||
err = assuan_socket_connect (ctx, sockname, 0, 0);
|
||||
if (!err)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
log_info (_("connection to %s established\n"),
|
||||
name);
|
||||
*did_success_msg = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Try to connect to the agent via socket or start it if it is not
|
||||
running and AUTOSTART is set. Handle the server's initial
|
||||
greeting. Returns a new assuan context at R_CTX or an error
|
||||
@ -433,25 +459,8 @@ start_new_gpg_agent (assuan_context_t *r_ctx,
|
||||
log_error ("failed to start agent '%s': %s\n",
|
||||
agent_program, gpg_strerror (err));
|
||||
else
|
||||
{
|
||||
for (i=0; i < SECS_TO_WAIT_FOR_AGENT; i++)
|
||||
{
|
||||
if (verbose)
|
||||
log_info (_("waiting for the agent to come up ... (%ds)\n"),
|
||||
SECS_TO_WAIT_FOR_AGENT - i);
|
||||
gnupg_sleep (1);
|
||||
err = assuan_socket_connect (ctx, sockname, 0, 0);
|
||||
if (!err)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
log_info (_("connection to agent established\n"));
|
||||
did_success_msg = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
err = wait_for_sock (SECS_TO_WAIT_FOR_AGENT, "agent",
|
||||
sockname, verbose, ctx, &did_success_msg);
|
||||
}
|
||||
|
||||
unlock_spawning (&lock, "agent");
|
||||
@ -584,29 +593,8 @@ start_new_dirmngr (assuan_context_t *r_ctx,
|
||||
log_error ("failed to start the dirmngr '%s': %s\n",
|
||||
dirmngr_program, gpg_strerror (err));
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < SECS_TO_WAIT_FOR_DIRMNGR; i++)
|
||||
{
|
||||
if (verbose)
|
||||
log_info (_("waiting for the dirmngr "
|
||||
"to come up ... (%ds)\n"),
|
||||
SECS_TO_WAIT_FOR_DIRMNGR - i);
|
||||
gnupg_sleep (1);
|
||||
err = assuan_socket_connect (ctx, sockname, 0, 0);
|
||||
if (!err)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
log_info (_("connection to the dirmngr"
|
||||
" established\n"));
|
||||
did_success_msg = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
err = wait_for_sock (SECS_TO_WAIT_FOR_DIRMNGR, "dirmngr",
|
||||
sockname, verbose, ctx, &did_success_msg);
|
||||
}
|
||||
|
||||
unlock_spawning (&lock, "dirmngr");
|
||||
|
Loading…
x
Reference in New Issue
Block a user