aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blogc-git-receiver/post-receive.c5
-rw-r--r--src/blogc-git-receiver/pre-receive.c5
-rw-r--r--src/blogc-make/ctx.c15
-rw-r--r--src/blogc-runserver/httpd.c10
4 files changed, 26 insertions, 9 deletions
diff --git a/src/blogc-git-receiver/post-receive.c b/src/blogc-git-receiver/post-receive.c
index 3b0f48c..3c7cb00 100644
--- a/src/blogc-git-receiver/post-receive.c
+++ b/src/blogc-git-receiver/post-receive.c
@@ -6,6 +6,8 @@
* See the file LICENSE.
*/
+#include <errno.h>
+#include <string.h>
#include <stdio.h>
#include <libgen.h>
#include <unistd.h>
@@ -25,7 +27,8 @@ bgr_post_receive_hook(int argc, char *argv[])
char *hooks_dir = dirname(argv[0]); // this was validated by main()
char *real_hooks_dir = realpath(hooks_dir, NULL);
if (real_hooks_dir == NULL) {
- fprintf(stderr, "error: failed to guess repository root.\n");
+ fprintf(stderr, "error: failed to guess repository root: %s\n",
+ strerror(errno));
return 3;
}
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index ab95fd4..12be165 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -101,7 +101,8 @@ bgr_pre_receive_hook(int argc, char *argv[])
char *hooks_dir = dirname(argv[0]); // this was validated by main()
char *real_hooks_dir = realpath(hooks_dir, NULL);
if (real_hooks_dir == NULL) {
- fprintf(stderr, "error: failed to guess repository root.\n");
+ fprintf(stderr, "error: failed to guess repository root: %s\n",
+ strerror(errno));
return 3;
}
@@ -152,7 +153,7 @@ default_sym:
char *build_dir = realpath(sym, NULL);
if (build_dir == NULL) {
fprintf(stderr, "error: failed to get the hash of last built "
- "commit.\n");
+ "commit: %s\n", strerror(errno));
rv = 3;
goto cleanup;
}
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index eb0fa22..fd71137 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -9,6 +9,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
+#include <errno.h>
#include <libgen.h>
#include <time.h>
#include <stdlib.h>
@@ -170,8 +171,16 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
if (settings_file == NULL || err == NULL || *err != NULL)
return NULL;
+ char real_filename[PATH_MAX];
+ if (NULL == realpath(settings_file, real_filename)) {
+ *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS,
+ "Failed to resolve settings file (%s): %s", settings_file,
+ strerror(errno));
+ return NULL;
+ }
+
size_t content_len;
- char *content = bc_file_get_contents(settings_file, true, &content_len,
+ char *content = bc_file_get_contents(real_filename, true, &content_len,
err);
if (*err != NULL)
return NULL;
@@ -217,10 +226,8 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
}
rv->settings = settings;
- char *real_filename = realpath(settings_file, NULL);
rv->settings_fctx = bm_filectx_new(rv, real_filename, NULL, NULL);
- rv->root_dir = realpath(dirname(real_filename), NULL);
- free(real_filename);
+ rv->root_dir = bc_strdup(dirname(real_filename));
const char *output_dir = getenv("OUTPUT_DIR");
rv->short_output_dir = bc_strdup(output_dir != NULL ? output_dir : "_build");
diff --git a/src/blogc-runserver/httpd.c b/src/blogc-runserver/httpd.c
index 274aa5e..6cbd198 100644
--- a/src/blogc-runserver/httpd.c
+++ b/src/blogc-runserver/httpd.c
@@ -102,8 +102,14 @@ handle_request(void *arg)
free(abs_path);
if (real_path == NULL) {
- status_code = 404;
- error(client_socket, 404, "Not Found");
+ if (errno == ENOENT) {
+ status_code = 404;
+ error(client_socket, 404, "Not Found");
+ }
+ else {
+ status_code = 500;
+ error(client_socket, 500, "Internal Server Error");
+ }
goto point2;
}