summaryrefslogtreecommitdiff
path: root/unix-socket.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-07-28 15:18:11 -0700
committerJunio C Hamano <gitster@pobox.com>2014-07-28 15:18:11 -0700
commit00252a3cea0c502340451c967f816c7ca385f6b0 (patch)
treed4d94b9a8600349b4a434b08d812fa3e4923215a /unix-socket.c
parent583b61c1af1bac12d6b48b2583ad508b5ab9964c (diff)
parent81caab9bb380ff3e3069ecdee80353f59b1b87a9 (diff)
downloadgit-rs/strbuf-getcwd-2.1.tar.gz
Merge branch 'rs/strbuf-getcwd' into HEADrs/strbuf-getcwd-2.1
* rs/strbuf-getcwd: use strbuf_add_absolute_path() to add absolute paths abspath: convert absolute_path() to strbuf use xgetcwd() to set $GIT_DIR use xgetcwd() to get the current directory or die wrapper: add xgetcwd() abspath: convert real_path_internal() to strbuf abspath: use strbuf_getcwd() to remember original working directory setup: convert setup_git_directory_gently_1 et al. to strbuf unix-sockets: use strbuf_getcwd() strbuf: add strbuf_getcwd()
Diffstat (limited to 'unix-socket.c')
-rw-r--r--unix-socket.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/unix-socket.c b/unix-socket.c
index 91bd6b89d4..19ed48be99 100644
--- a/unix-socket.c
+++ b/unix-socket.c
@@ -18,12 +18,12 @@ static int chdir_len(const char *orig, int len)
}
struct unix_sockaddr_context {
- char orig_dir[PATH_MAX];
+ char *orig_dir;
};
static void unix_sockaddr_cleanup(struct unix_sockaddr_context *ctx)
{
- if (!ctx->orig_dir[0])
+ if (!ctx->orig_dir)
return;
/*
* If we fail, we can't just return an error, since we have
@@ -32,6 +32,7 @@ static void unix_sockaddr_cleanup(struct unix_sockaddr_context *ctx)
*/
if (chdir(ctx->orig_dir) < 0)
die("unable to restore original working directory");
+ free(ctx->orig_dir);
}
static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
@@ -39,10 +40,11 @@ static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
{
int size = strlen(path) + 1;
- ctx->orig_dir[0] = '\0';
+ ctx->orig_dir = NULL;
if (size > sizeof(sa->sun_path)) {
const char *slash = find_last_dir_sep(path);
const char *dir;
+ struct strbuf cwd = STRBUF_INIT;
if (!slash) {
errno = ENAMETOOLONG;
@@ -56,11 +58,9 @@ static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
errno = ENAMETOOLONG;
return -1;
}
-
- if (!getcwd(ctx->orig_dir, sizeof(ctx->orig_dir))) {
- errno = ENAMETOOLONG;
+ if (strbuf_getcwd(&cwd))
return -1;
- }
+ ctx->orig_dir = strbuf_detach(&cwd, NULL);
if (chdir_len(dir, slash - dir) < 0)
return -1;
}