From 2f901f08cb0215f1007d01d3a18ee1ed044a0425 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Thu, 8 Nov 2012 07:33:43 +0100 Subject: [PATCH] fixed magic vars for symlinks --- core/utils.c | 11 +++++++++++ core/uwsgi.c | 27 ++++++++++++++++++--------- uwsgi.h | 1 + 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/core/utils.c b/core/utils.c index d06844fe..f2c25707 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1822,6 +1822,17 @@ int uwsgi_is_dir(char *filename) { return 0; } +int uwsgi_is_link(char *filename) { + struct stat st; + if (lstat(filename, &st)) { + return 0; + } + if (S_ISLNK(st.st_mode)) + return 1; + return 0; +} + + int uwsgi_logic_opt_if_opt(char *key, char *value) { // check for env-value syntax diff --git a/core/uwsgi.c b/core/uwsgi.c index 0d3fe442..9728e842 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -669,18 +669,27 @@ restart: void config_magic_table_fill(char *filename, char **magic_table) { char *tmp = NULL; + char *fullname = filename; - char *fullname = uwsgi_expand_path(filename, strlen(filename), NULL); - if (!fullname) { - fullname = filename; + // we have a special case for symlinks + if (uwsgi_is_link(filename)) { + if (filename[0] != '/') { + fullname = uwsgi_concat3(uwsgi.cwd, "/", filename); + } } - // free unused memory else { - char *minimal_name = uwsgi_malloc(strlen(fullname) + 1); - memcpy(minimal_name, fullname, strlen(fullname)); - minimal_name[strlen(fullname)] = 0; - free(fullname); - fullname = minimal_name; + + fullname = uwsgi_expand_path(filename, strlen(filename), NULL); + if (fullname) { + char *minimal_name = uwsgi_malloc(strlen(fullname) + 1); + memcpy(minimal_name, fullname, strlen(fullname)); + minimal_name[strlen(fullname)] = 0; + free(fullname); + fullname = minimal_name; + } + else { + fullname = filename; + } } magic_table['o'] = filename; diff --git a/uwsgi.h b/uwsgi.h index d486dfba..d57a1ecb 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3139,6 +3139,7 @@ int uwsgi_try_autoload(char *); uint64_t uwsgi_micros(void); int uwsgi_is_file(char *); +int uwsgi_is_link(char *); void uwsgi_receive_signal(int, char *, int); void uwsgi_exec_atexit(void);