Skip to content

Commit

Permalink
Use readlink to get fullpath of proxysql
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Jan 26, 2019
1 parent 152d059 commit ac2e710
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down

0 comments on commit ac2e710

Please sign in to comment.