Author: breser
Date: Wed Jun 4 16:53:50 2014
New Revision: 1600331
URL: http://svn.apache.org/r1600331
Log:
Properly close down the connection to gpg-agent.
This avoids a spurious "Connection reset by peer" log message from gpg-agent.
* subversion/libsvn_subr/gpg_agent.c
(bye_gpg_agent): New function.
(find_running_gpg_agent, password_get_gpg_agent, password_set_gpg_agent):
Replace the close() calls with calls to bye_gpg_agent().
Modified:
subversion/trunk/subversion/libsvn_subr/gpg_agent.c
Modified: subversion/trunk/subversion/libsvn_subr/gpg_agent.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/gpg_agent.c?rev=1600331&r1=1600330&r2=1600331&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/gpg_agent.c (original)
+++ subversion/trunk/subversion/libsvn_subr/gpg_agent.c Wed Jun 4 16:53:50 2014
@@ -157,6 +157,17 @@ send_option(int sd, char *buf, size_t n,
return (strncmp(buf, "OK", 2) == 0);
}
+/* Send the BYE command and disconnect from the gpg-agent. Doing this avoids
+ * gpg-agent emitting a "Connection reset by peer" log message with some
+ * versions of gpg-agent. */
+static void
+bye_gpg_agent(int sd)
+{
+ /* don't bother to check the result of the write, it either worked or it
+ * didn't, but either way we're closing. */
+ write(sd, "BYE\n", 4);
+ close(sd);
+}
/* Locate a running GPG Agent, and return an open file descriptor
* for communication with the agent in *NEW_SD. If no running agent
@@ -200,7 +211,7 @@ find_running_gpg_agent(int *new_sd, apr_
if (connect(sd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
}
@@ -211,13 +222,13 @@ find_running_gpg_agent(int *new_sd, apr_
buffer = apr_palloc(pool, BUFFER_SIZE);
if (!receive_from_gpg_agent(sd, buffer, BUFFER_SIZE))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
if (strncmp(buffer, "OK", 2) != 0)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
@@ -227,19 +238,19 @@ find_running_gpg_agent(int *new_sd, apr_
request = "GETINFO socket_name\n";
if (write(sd, request, strlen(request)) == -1)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
if (!receive_from_gpg_agent(sd, buffer, BUFFER_SIZE))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
if (strncmp(buffer, "D", 1) == 0)
p = &buffer[2];
if (!p)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
ep = strchr(p, '\n');
@@ -247,18 +258,18 @@ find_running_gpg_agent(int *new_sd, apr_
*ep = '\0';
if (strcmp(socket_name, p) != 0)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
/* The agent will terminate its response with "OK". */
if (!receive_from_gpg_agent(sd, buffer, BUFFER_SIZE))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
if (strncmp(buffer, "OK", 2) != 0)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
@@ -306,7 +317,7 @@ password_get_gpg_agent(svn_boolean_t *do
{
if (!send_option(sd, buffer, BUFFER_SIZE, "ttyname", tty_name, pool))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
}
@@ -317,7 +328,7 @@ password_get_gpg_agent(svn_boolean_t *do
{
if (!send_option(sd, buffer, BUFFER_SIZE, "ttytype", tty_type, pool))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
}
@@ -334,7 +345,7 @@ password_get_gpg_agent(svn_boolean_t *do
{
if (!send_option(sd, buffer, BUFFER_SIZE, "lc-ctype", lc_ctype, pool))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
}
@@ -345,7 +356,7 @@ password_get_gpg_agent(svn_boolean_t *do
{
if (!send_option(sd, buffer, BUFFER_SIZE, "display", display, pool))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
}
@@ -369,16 +380,16 @@ password_get_gpg_agent(svn_boolean_t *do
if (write(sd, request, strlen(request)) == -1)
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
if (!receive_from_gpg_agent(sd, buffer, BUFFER_SIZE))
{
- close(sd);
+ bye_gpg_agent(sd);
return SVN_NO_ERROR;
}
- close(sd);
+ bye_gpg_agent(sd);
if (strncmp(buffer, "ERR", 3) == 0)
return SVN_NO_ERROR;
@@ -425,7 +436,7 @@ password_set_gpg_agent(svn_boolean_t *do
if (sd == -1)
return SVN_NO_ERROR;
- close(sd);
+ bye_gpg_agent(sd);
*done = TRUE;
return SVN_NO_ERROR;