Description: Link against libtirpc when no librpcsvc library is available
 setup.py decides between glibc's RPC implementation ("rpcsvc") and libtirpc by
 checking for the header /usr/include/rpc/rpc.h outside of /usr/include/tirpc.
 If the header is present, it links -lrpcsvc, which does not exist any more
 since glibc 2.32 removed the SUN RPC implementation.  The header can still be
 present on such systems - for example it may be left over from an older
 libc6-dev installation in the build chroot - and in that case the link fails
 with "cannot find -lrpcsvc: No such file or directory" (observed on arm64).
 .
 Therefore check whether the library is really available in the directories
 searched by the linker before preferring the rpcsvc variant, and fall back to
 libtirpc (headers in /usr/include/tirpc) when only the header exists.
 .
 Systems which do provide librpcsvc keep the previous behaviour, and the patch
 is architecture independent (the failing environment only differed in having a
 stale rpc/rpc.h present).
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Origin: vendor
Forwarded: no
Last-Update: 2026-10-20
--- python-fsquota-0.1.0+dfsg1.orig/setup.py
+++ python-fsquota-0.1.0+dfsg1/setup.py
@@ -19,6 +19,7 @@ import os
 import os.path
 import sys
 import subprocess
+import sysconfig
 import shutil
 import re
 
@@ -114,10 +115,27 @@ if (   (match1 and (int(match1.group(1))
 # - Debian has libtirpc, but headers and implementation are still in glibc too
 #   so there's a risk symbols are resolved from libc while compiling against tirpc headers;
 #   therefore we do not use tirpc when rpc headers are present outside tirpc
+# - glibc 2.32 removed the RPC implementation (and hence librpcsvc) entirely, so
+#   the rpc headers can be present without any library to link against (e.g. they
+#   may be left over from an older libc6-dev); verify the library is available
+#   before preferring it, otherwise the link fails with "cannot find -lrpcsvc"
 if re.match(r"^Linux", osr):
     extrasrc += ["src/linuxapi.c"]
 
-    if os.path.isdir('/usr/include/tirpc') and not os.path.isfile('/usr/include/rpc/rpc.h'):
+    # directories searched by the linker for -l<name>
+    rpcsvc_lib_dirs = ['/usr/lib', '/lib', '/usr/lib64', '/lib64',
+                       '/usr/local/lib', '/usr/local/lib64']
+    libdir = sysconfig.get_config_var('LIBDIR')     # e.g. /usr/lib/<triplet>
+    if libdir:
+        rpcsvc_lib_dirs.insert(0, libdir)
+    multiarch = sysconfig.get_config_var('MULTIARCH')
+    if multiarch:
+        rpcsvc_lib_dirs += [os.path.join('/lib', multiarch)]
+    rpcsvc_avail = any(os.path.isfile(os.path.join(d, "librpcsvc" + ext))
+                       for d in rpcsvc_lib_dirs for ext in (".so", ".a"))
+
+    if (   os.path.isdir('/usr/include/tirpc')
+       and (not os.path.isfile('/usr/include/rpc/rpc.h') or not rpcsvc_avail)):
         print("Configured to use tirpc library instead of rpcsvc", file=sys.stderr)
         extrainc  += ["/usr/include/tirpc"]
         extralibs += ["tirpc"]
