gstreamer/0001-Canonicalize-the-library-path-returned-by-dladdr.patch

103 lines
3.4 KiB
Diff
Raw Normal View History

From 8d17e447da1bb2b55186b24d6aa217551e2ea9a4 Mon Sep 17 00:00:00 2001
From: Antonio Larrosa <alarrosa@suse.com>
Date: Mon, 11 Mar 2024 15:10:25 +0100
Subject: [PATCH] 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
---
subprojects/gstreamer/gst/gstregistry.c | 21 ++++++++++++++++++-
.../gstreamer/libs/gst/net/gstptpclock.c | 20 +++++++++++++++++-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/gst/gstregistry.c b/gst/gstregistry.c
index c84de1d7f62..191d101e5ea 100644
--- a/gst/gstregistry.c
+++ b/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()");
@@ -1610,7 +1612,24 @@ priv_gst_get_relocated_libgstreamer (void)
return NULL;
}
- dir = g_path_get_dirname (info.dli_fname);
+#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);
+
} else {
GST_LOG ("dladdr() failed");
return NULL;
diff --git a/libs/gst/net/gstptpclock.c b/libs/gst/net/gstptpclock.c
index 0b69eb61cf2..c43b5d1e8a6 100644
--- a/libs/gst/net/gstptpclock.c
+++ b/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()");
@@ -2580,7 +2582,23 @@ get_relocated_libgstnet (void)
return NULL;
}
- dir = g_path_get_dirname (info.dli_fname);
+#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);
+
} else {
GST_LOG ("dladdr() failed");
return NULL;
--
GitLab