Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add joinpath, pass '-' to ssh-add

  • Loading branch information...
commit fc6cb6779de735bad9f8e24562dc55faba39f465 1 parent 5e2acda
@vodik authored
Showing with 52 additions and 9 deletions.
  1. +2 −3 envoy-exec.c
  2. +3 −6 envoy.c
  3. +46 −0 util.c
  4. +1 −0  util.h
View
5 envoy-exec.c
@@ -96,10 +96,9 @@ static _noreturn_ void exec_wrapper(const char *cmd, int argc, char *argv[])
char *saveptr, *segment = strtok_r(buf, ":", &saveptr);
for (; segment; segment = strtok_r(NULL, ":", &saveptr)) {
- _cleanup_free_ char *full_path;
-
- safe_asprintf(&full_path, "%s/%s", segment, cmd);
+ char *full_path = joinpath(segment, cmd, NULL);
safe_execv(full_path, args);
+ free(full_path);
}
}
View
9 envoy.c
@@ -105,15 +105,12 @@ static int get_agent(struct agent_data_t *data, enum agent id, bool start)
static char *get_key_path(const char *home, const char *fragment)
{
- char *out;
-
/* path exists, add it */
- if (access(fragment, F_OK) == 0)
+ if (fragment[0] == '-' || access(fragment, F_OK) == 0)
return strdup(fragment);
/* assume it's a key in $HOME/.ssh */
- safe_asprintf(&out, "%s/.ssh/%s", home, fragment);
- return out;
+ return joinpath(home, ".ssh", fragment, NULL);
}
static _noreturn_ void add_keys(char **keys, int count)
@@ -307,7 +304,7 @@ int main(int argc, char *argv[])
print_env(&data);
/* fall through */
case ACTION_NONE:
- if (data.status == ENVOY_RUNNING || data.type == AGENT_GPG_AGENT)
+ if (data.status != ENVOY_STARTED || data.type == AGENT_GPG_AGENT)
break;
/* fall through */
case ACTION_FORCE_ADD:
View
46 util.c
@@ -5,6 +5,52 @@
#include <stdarg.h>
#include <err.h>
+static char *joinpath_ap(const char *root, va_list ap)
+{
+ size_t len;
+ char *ret, *p;
+ const char *temp;
+
+ va_list aq;
+ va_copy(aq, ap);
+
+ if (!root)
+ return NULL;
+
+ len = strlen(root);
+ while ((temp = va_arg(ap, const char *))) {
+ size_t temp_len = strlen(temp) + 1;
+ if (temp_len > ((size_t) -1) - len) {
+ return NULL;
+ }
+
+ len += temp_len;
+ }
+
+ ret = malloc(len + 1);
+ if (ret) {
+ p = stpcpy(ret, root);
+ while ((temp = va_arg(aq, const char *))) {
+ p++[0] = '/';
+ p = stpcpy(p, temp);
+ }
+ }
+
+ return ret;
+}
+
+char *joinpath(const char *root, ...)
+{
+ va_list ap;
+ char *ret;
+
+ va_start(ap, root);
+ ret = joinpath_ap(root, ap);
+ va_end(ap);
+
+ return ret;
+}
+
void safe_asprintf(char **strp, const char *fmt, ...)
{
va_list ap;
View
1  util.h
@@ -33,6 +33,7 @@ static inline void freep(void *p) { free(*(void **)p); }
static inline bool streq(const char *s1, const char *s2) { return strcmp(s1, s2) == 0; }
static inline bool strneq(const char *s1, const char *s2, size_t n) { return strncmp(s1, s2, n) == 0; }
+char *joinpath(const char *root, ...);
void safe_asprintf(char **strp, const char *fmt, ...) _printf_(2, 3);
// vim: et:sts=4:sw=4:cino=(0
Please sign in to comment.
Something went wrong with that request. Please try again.