diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-12-17 21:55:46 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-12-17 21:55:46 +0100 |
commit | 91737269d67a0403727faaa70521ff904dba695b (patch) | |
tree | b5c431f12f0a04c1b7a8a00a27a3e745f9815808 /src/blogc-make | |
parent | 3f58386ebd99fe980b35487ceb721fedcce73ac5 (diff) | |
download | blogc-91737269d67a0403727faaa70521ff904dba695b.tar.gz blogc-91737269d67a0403727faaa70521ff904dba695b.tar.bz2 blogc-91737269d67a0403727faaa70521ff904dba695b.zip |
git-receiver: make: runserver: improved realpath(3) usage
Diffstat (limited to 'src/blogc-make')
-rw-r--r-- | src/blogc-make/ctx.c | 15 |
1 files changed, 11 insertions, 4 deletions
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"); |