From 89041ad29d55afc396aff3e403eec3b8c6055113 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Mon, 11 Mar 2024 15:10:25 +0100 Subject: [PATCH] registry, ptp: Canonicalize the library path returned by dladdr On systems using UsrMerge (like openSUSE or Fedora), /lib64 is a symlink to /usr/lib64. So dladdr is returning the path to the gstreamer library in /lib64 in priv_gst_get_relocated_libgstreamer. Later gst_plugin_loader_spawn tries to build the path to the gst-plugin-scanner helper from /lib64 and ends up trying to use /lib64/../libexec/gstreamer-1.0/gst-plugin-scanner which doesn't exist. By canonicalizing the path with a call to realpath, gst-plugin-scanner is found correctly under /usr/lib64/../libexec/gstreamer-1.0/gst-plugin-scanner Similar change applied to gstreamer/libs/gst/net/gstptpclock.c Part-of: --- subprojects/gstreamer/gst/gstregistry.c | 21 ++++++++++++++++++- .../gstreamer/libs/gst/net/gstptpclock.c | 21 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/subprojects/gstreamer/gst/gstregistry.c b/subprojects/gstreamer/gst/gstregistry.c index c84de1d7f6..2226d1853f 100644 --- a/subprojects/gstreamer/gst/gstregistry.c +++ b/subprojects/gstreamer/gst/gstregistry.c @@ -1599,6 +1599,8 @@ priv_gst_get_relocated_libgstreamer (void) #elif defined(HAVE_DLADDR) { Dl_info info; + char *real_fname = NULL; + long path_max = 0; GST_DEBUG ("attempting to retrieve libgstreamer-1.0 location using " "dladdr()"); @@ -1609,8 +1611,25 @@ priv_gst_get_relocated_libgstreamer (void) if (!info.dli_fname) { return NULL; } +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf (info.dli_fname, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; +#endif + + real_fname = g_malloc (path_max); + if (realpath (info.dli_fname, real_fname)) { + dir = g_path_get_dirname (real_fname); + GST_DEBUG ("real directory location: %s", dir); + } else { + GST_ERROR ("could not canonicalize path %s: %s", info.dli_fname, + g_strerror (errno)); + dir = g_path_get_dirname (info.dli_fname); + } + g_free (real_fname); - dir = g_path_get_dirname (info.dli_fname); } else { GST_LOG ("dladdr() failed"); return NULL; diff --git a/subprojects/gstreamer/libs/gst/net/gstptpclock.c b/subprojects/gstreamer/libs/gst/net/gstptpclock.c index 09f482ecd1..fc3268fae4 100644 --- a/subprojects/gstreamer/libs/gst/net/gstptpclock.c +++ b/subprojects/gstreamer/libs/gst/net/gstptpclock.c @@ -2569,6 +2569,8 @@ get_relocated_libgstnet (void) #elif defined(HAVE_DLADDR) { Dl_info info; + char *real_fname = NULL; + long path_max = 0; GST_DEBUG ("attempting to retrieve libgstnet-1.0 location using " "dladdr()"); @@ -2579,8 +2581,25 @@ get_relocated_libgstnet (void) if (!info.dli_fname) { return NULL; } +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf (info.dli_fname, _PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; +#endif + + real_fname = g_malloc (path_max); + if (realpath (info.dli_fname, real_fname)) { + dir = g_path_get_dirname (real_fname); + GST_DEBUG ("real directory location: %s", dir); + } else { + GST_ERROR ("could not canonicalize path %s: %s", info.dli_fname, + g_strerror (errno)); + dir = g_path_get_dirname (info.dli_fname); + } + g_free (real_fname); - dir = g_path_get_dirname (info.dli_fname); } else { GST_LOG ("dladdr() failed"); return NULL;