aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-11-18 01:00:29 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-11-18 01:00:29 +0100
commit66d12f660d33de130dc2f90b59c55e7407a86ffc (patch)
treea0500e102136639d01400dcfa0e2bc8a06abf688 /src
parent1195c0d970898d9dbda754607f3b80ef220b12fe (diff)
downloadblogc-66d12f660d33de130dc2f90b59c55e7407a86ffc.tar.gz
blogc-66d12f660d33de130dc2f90b59c55e7407a86ffc.tar.bz2
blogc-66d12f660d33de130dc2f90b59c55e7407a86ffc.zip
git-receiver: avoid static buffer.
this simplifies code, but makes it less portable
Diffstat (limited to 'src')
-rw-r--r--src/blogc-git-receiver/pre-receive.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 954c379..14d5ca2 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -93,7 +93,6 @@ int
bgr_pre_receive_hook(int argc, char *argv[])
{
int rv = 0;
- char buffer[4096];
char *master = NULL;
if (isatty(STDIN_FILENO)) {
@@ -148,15 +147,14 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *repo_dir = NULL;
char *output_dir = NULL;
- if (NULL == getcwd(buffer, sizeof(buffer))) {
- fprintf(stderr, "error: failed to get repository remote path: %s\n",
+ repo_dir = getcwd(NULL, 0);
+ if (repo_dir == NULL) {
+ fprintf(stderr, "error: failed to get repository path: %s\n",
strerror(errno));
rv = 1;
goto cleanup;
}
- repo_dir = bc_strdup(buffer);
-
char dir[] = "/tmp/blogc_XXXXXX";
if (NULL == mkdtemp(dir)) {
rv = 1;
@@ -239,18 +237,13 @@ bgr_pre_receive_hook(int argc, char *argv[])
goto cleanup;
}
- char *htdocs_sym = NULL;
- ssize_t htdocs_sym_len = readlink("htdocs", buffer, sizeof(buffer));
- if (0 < htdocs_sym_len) {
- if (0 != unlink("htdocs")) {
- fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
- repo_dir, strerror(errno));
- rmdir_recursive(output_dir);
- rv = 1;
- goto cleanup;
- }
- buffer[htdocs_sym_len] = '\0';
- htdocs_sym = buffer;
+ char *htdocs_sym = realpath("htdocs", NULL);
+ if ((htdocs_sym != NULL) && (0 != unlink("htdocs"))) {
+ fprintf(stderr, "error: failed to remove symlink (%s/htdocs): %s\n",
+ repo_dir, strerror(errno));
+ rmdir_recursive(output_dir);
+ rv = 1;
+ goto cleanup2;
}
if (0 != symlink(output_dir, "htdocs")) {
@@ -258,12 +251,15 @@ bgr_pre_receive_hook(int argc, char *argv[])
repo_dir, strerror(errno));
rmdir_recursive(output_dir);
rv = 1;
- goto cleanup;
+ goto cleanup2;
}
if (htdocs_sym != NULL)
rmdir_recursive(htdocs_sym);
+cleanup2:
+ free(htdocs_sym);
+
cleanup:
free(master);
free(output_dir);