Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better error handling for broken gpg-agent connections

  • Loading branch information...
commit 068d31452ef77dbe456b0669ed5274a74112d870 1 parent c7113cd
@vodik authored
Showing with 9 additions and 11 deletions.
  1. +1 −1  clique
  2. +5 −2 envoy.c
  3. +1 −1  gpg-protocol.h
  4. +2 −7 gpg-protocol.rl
2  clique
@@ -1 +1 @@
-Subproject commit 455fa29f13b8ddb7e63e37c70dc2ad1fd47175a9
+Subproject commit 94fd237eb7cb59d7972cbea886d5c0da9e4ba6ae
View
7 envoy.c
@@ -163,7 +163,10 @@ static void source_env(struct agent_data_t *data)
{
if (data->type == AGENT_GPG_AGENT) {
_cleanup_gpg_ struct gpg_t *agent = gpg_agent_connection(data->gpg);
- gpg_update_tty(agent);
+ if (!agent)
+ warn("failed to connect to GPG_AUTH_SOCK");
+ else
+ gpg_update_tty(agent);
}
setenv("SSH_AUTH_SOCK", data->sock, true);
@@ -173,7 +176,7 @@ static int unlock(const struct agent_data_t *data, char *password)
{
_cleanup_gpg_ struct gpg_t *agent = gpg_agent_connection(data->gpg);
if (!agent)
- err(EXIT_FAILURE, "failed to open connection to gpg-agent");
+ err(EXIT_FAILURE, "failed to connect to GPG_AUTH_SOCK");
if (!password)
read_password(&password);
View
2  gpg-protocol.h
@@ -41,6 +41,6 @@ struct fingerprint_t *gpg_keyinfo(struct gpg_t *gpg);
void free_fingerprints(struct fingerprint_t *frpt);
#define _cleanup_gpg_ __attribute__((cleanup(gpg_closep)))
-static inline void gpg_closep(struct gpg_t **p) { gpg_close(*p); }
+static inline void gpg_closep(struct gpg_t **p) { if (*p) gpg_close(*p); }
// vim: et:sts=4:sw=4:cino=(0
View
9 gpg-protocol.rl
@@ -117,10 +117,8 @@ struct gpg_t *gpg_agent_connection(const char *sock)
socklen_t sa_len;
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- warn("couldn't create socket");
+ if (fd < 0)
return NULL;
- }
len = strlen(sock);
split = memchr(sock, ':', len);
@@ -131,16 +129,13 @@ struct gpg_t *gpg_agent_connection(const char *sock)
memcpy(&sa.un.sun_path, sock, len);
sa_len = len + sizeof(sa.un.sun_family);
- if (connect(fd, &sa.sa, sa_len) < 0) {
- warn("failed to connect to gpg-agent");
+ if (connect(fd, &sa.sa, sa_len) < 0)
return NULL;
- }
struct gpg_t *gpg = malloc(sizeof(struct gpg_t));
*gpg = (struct gpg_t) { .fd = fd };
if (gpg_check_return(gpg) < 0) {
- warnx("incorrect response from gpg-agent");
gpg_close(gpg);
return NULL;
}
Please sign in to comment.
Something went wrong with that request. Please try again.