Permalink
Browse files

better error handling for broken gpg-agent connections

  • Loading branch information...
1 parent c7113cd commit 068d31452ef77dbe456b0669ed5274a74112d870 @vodik committed Feb 26, 2014
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
Submodule clique updated 2 files
+0 −1 systemd-scope.c
+0 −1 systemd-unit.c
View
@@ -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
@@ -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
@@ -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;
}

0 comments on commit 068d314

Please sign in to comment.