From ac2e710cad00070e2aeb5a01f574fc2a978e36af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 27 Jan 2019 01:34:50 +1100 Subject: [PATCH] Use readlink to get fullpath of proxysql --- src/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5ede651f8e..ba72e05a53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1435,7 +1435,18 @@ int main(int argc, const char * argv[]) { { cpu_timer t; - int fd = open(argv[0], O_RDONLY); + int fd = -1; + char buff[PATH_MAX+1]; + ssize_t len = -1; +#if defined(__FreeBSD__) + len = readlink("/proc/curproc/file", buff, sizeof(buff)-1); +#else + len = readlink("/proc/self/exe", buff, sizeof(buff)-1); +#endif + if (len != -1) { + buff[len] = '\0'; + fd = open(buff, O_RDONLY); + } if(fd >= 0) { struct stat statbuf; if(fstat(fd, &statbuf) == 0) { @@ -1452,10 +1463,10 @@ int main(int argc, const char * argv[]) { memcpy(binary_sha1, buf, SHA_DIGEST_LENGTH*2); munmap(fb,statbuf.st_size); } else { - proxy_error("Unable to mmap %s: %s\n", argv[0], strerror(errno)); + proxy_error("Unable to mmap %s: %s\n", buff, strerror(errno)); } } else { - proxy_error("Unable to fstat %s: %s\n", argv[0], strerror(errno)); + proxy_error("Unable to fstat %s: %s\n", buff, strerror(errno)); } } else { proxy_error("Unable to open %s: %s\n", argv[0], strerror(errno));