Use getauxval for obtaining the executable path.
It appears that reading /proc/self/exe actually can return the path of the shared library from which the reading is made.
This commit is contained in:
@ -22,6 +22,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/auxv.h>
|
||||||
|
#include <elf.h>
|
||||||
#include <log_manager.h>
|
#include <log_manager.h>
|
||||||
#include <modules.h>
|
#include <modules.h>
|
||||||
#include <query_classifier.h>
|
#include <query_classifier.h>
|
||||||
@ -86,53 +88,48 @@ static void end_and_unload_classifier(QUERY_CLASSIFIER* classifier, const char*
|
|||||||
static bool resolve_pp_path(char* path, int size)
|
static bool resolve_pp_path(char* path, int size)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
ssize_t sz = readlink("/proc/self/exe", path, size);
|
const char* exe_path = (const char*) getauxval(AT_EXECFN);
|
||||||
|
size_t len = strlen(exe_path);
|
||||||
|
|
||||||
if (sz >= 0)
|
if (len < size)
|
||||||
{
|
{
|
||||||
if (sz == size)
|
strcpy(path, exe_path);
|
||||||
|
char* s = path + len;
|
||||||
|
|
||||||
|
// Find the last '/'.
|
||||||
|
while ((*s != '/') && (s != path))
|
||||||
{
|
{
|
||||||
MXS_ERROR("The full path of the current executable does not fit in a "
|
--s;
|
||||||
"buffer of %d bytes.", size);
|
--len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*s == '/')
|
||||||
|
{
|
||||||
|
++s;
|
||||||
|
++len;
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = 0;
|
||||||
|
|
||||||
|
int required_size = len + sizeof(MAXPP) + 1;
|
||||||
|
|
||||||
|
if (required_size <= size)
|
||||||
|
{
|
||||||
|
strcat(path, MAXPP);
|
||||||
|
|
||||||
|
MXS_NOTICE("Path of plugin process executable: %s", path);
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* s = path + sz;
|
MXS_ERROR("The full path of the plugin process executable does "
|
||||||
|
"not fit into a buffer of %d bytes. ", size);
|
||||||
// Find the last '/'.
|
|
||||||
while ((*s != '/') && (s != path))
|
|
||||||
{
|
|
||||||
--s;
|
|
||||||
--sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*s == '/')
|
|
||||||
{
|
|
||||||
++s;
|
|
||||||
++sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
*s = 0;
|
|
||||||
|
|
||||||
int required_size = sz + sizeof(MAXPP) + 1;
|
|
||||||
|
|
||||||
if (required_size + 1 <= size)
|
|
||||||
{
|
|
||||||
strcat(path, MAXPP);
|
|
||||||
|
|
||||||
MXS_NOTICE("Path of plugin process executable: %s", path);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MXS_ERROR("The full path of the plugin process executable does "
|
|
||||||
"not fit into a buffer of %d bytes. ", size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Could not establish location of current process.");
|
MXS_ERROR("The full path of the current executable does not fit in a "
|
||||||
|
"buffer of %d bytes.", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
Reference in New Issue
Block a user