I am trying to use dlopen() and dlinfo() to get the path my executable. I am able to get the path to a .so by using the handle returned by dlopen() but when I use the handle returned by dlopen(NULL,RTLD_LAZY); then the path I get back is empty.
void* executable_handle = dlopen(0, RTLD_LAZY);
if (nullptr != executable_handle) 
{
    char pp_linkmap[sizeof(link_map)];
    int r = dlinfo(executable_handle, RTLD_DI_LINKMAP, pp_linkmap);
    if (0 == r)
    {
        link_map* plink = *(link_map**)pp_linkmap;
        printf("path: %s\n", plink->l_name);
    }
}
Am I wrong in my assumption that the handle for the executable can be used in the dlinfo functions the same way a .so handle can be used?
 
     
    