diff --git a/utils.c b/utils.c index 90db86a2..50004bb4 100644 --- a/utils.c +++ b/utils.c @@ -2563,15 +2563,21 @@ void uwsgi_chown(char *filename, char *owner) { char *uwsgi_get_binary_path(char *argvzero) { - char *buf; -#ifdef __linux__ - buf = uwsgi_malloc(uwsgi.page_size); +#if defined(__linux__) + char *buf = uwsgi_malloc(uwsgi.page_size); ssize_t len = readlink("/proc/self/exe", buf, uwsgi.page_size); if (len > 0) { return buf; } +#elif defined(__APPLE__) + char *buf = uwsgi_malloc(uwsgi.page_size); + uint32_t len = uwsgi.page_size; + if (_NSGetExecutablePath(buf, &len) == 0) { + return buf; + } #endif + return argvzero; } diff --git a/uwsgi.h b/uwsgi.h index eaf3746c..e8589547 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -162,6 +162,7 @@ extern int pivot_root(const char *new_root, const char *put_old); #ifdef __APPLE__ #define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4 +#include #endif #include