[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#954374: libc6: please make maintainerscript compatible with busybox



Control: tag -1 + patch

Hi again,

Quoting Johannes Schauer (2020-03-21 22:50:46)
> Quoting Aurelien Jarno (2020-03-21 00:00:18)
> > On 2020-03-20 22:57, Johannes 'josch' Schauer wrote:
> > > would it be possible to make the libc6 preinst maintainer script
> > > compatible with busybox? Currently the preinst script calls "readlink
> > > -m" which is not supported by busybox. Hence the following error will be
> > > thrown:
> > > 
> > >     BusyBox v1.30.1 (Debian 1:1.30.1-4) multi-call binary.
> > >     
> > >     Usage: readlink [-fnv] FILE
> > >     
> > >     Display the value of a symlink
> > >     
> > >       -f      Canonicalize by following all symlinks
> > >       -n      Don't add newline
> > >       -v      Verbose
> > > 
> > > I tried to prepare a patch for the preinst script but ran into a FTBFS:
> > > 
> > > x86_64-linux-gnu-gcc-9   -shared -static-libgcc -Wl,-O1  -Wl,-z,defs -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2  -B/<<PKGBUILDDIR>>/build-tree/amd64-libc/csu/  -Wl,--version-script=/<<PKGBUILDDIR>>/build-tree/amd64-libc/libnss_files.map -Wl,-soname=libnss_files.so.2 -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both   -L/<<PKGBUILDDIR>>/build-tree/amd64-libc -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/math -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/elf -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/dlfcn -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/nss -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/nis -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/rt -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/resolv -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/mathvec -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/support -L/<<PKGBUILDDIR>>/build-tree/amd64-libc/nptl -Wl,-rpath-link=/<<PKGBUILDDIR>>/build-tree/amd64-libc:/<<PKGBUILDDIR>>/build-tree/amd64-libc/math:/<<PKGBUILDDIR>>/build-tree/amd64-libc/elf:/<<PKGBUILDDIR>>/build-tree/amd64-libc/dlfcn:/<<PKGBUILDDIR>>/build-tree/amd64-libc/nss:/<<PKGBUILDDIR>>/build-tree/amd64-libc/nis:/<<PKGBUILDDIR>>/build-tree/amd64-libc/rt:/<<PKGBUILDDIR>>/build-tree/amd64-libc/resolv:/<<PKGBUILDDIR>>/build-tree/amd64-libc/mathvec:/<<PKGBUILDDIR>>/build-tree/amd64-libc/support:/<<PKGBUILDDIR>>/build-tree/amd64-libc/nptl -o /<<PKGBUILDDIR>>/build-tree/amd64-libc/nss/libnss_files.so  /<<PKGBUILDDIR>>/build-tree/amd64-libc/csu/abi-note.o -Wl,--whole-archive /<<PKGBUILDDIR>>/build-tree/amd64-libc/nss/libnss_files_pic.a -Wl,--no-whole-archive   -Wl,--start-group /<<PKGBUILDDIR>>/build-tree/amd64-libc/linkobj/libc.so /<<PKGBUILDDIR>>/build-tree/amd64-libc/libc_nonshared.a -Wl,--as-needed /<<PKGBUILDDIR>>/build-tree/amd64-libc/elf/ld.so -Wl,--no-as-needed -Wl,--end-group
> > > /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libselinux.so: undefined reference to `gettid@GLIBC_2.30'
> > > collect2: error: ld returned 1 exit status
> > 
> > Strange. How did you try to build it?
> 
> It turned out to be a problem on my side. Sorry for the false alarm.
> 
> > > Thus, I'm now reporting this wishlist bug here before further working on
> > > a fix.
> > > 
> > > Would you be willing to accept a change that makes the preinst script of
> > > libc6 compatible with readlink from busybox?
> > 
> > On the principle yes, but it means we need to have an equivalent to
> > readlink -m. Do you have a way for doing that in busybox?
> 
> Indeed I have. There exists a version for bash with an extensive test suite:
> https://github.com/bashup/realpaths I ported that one to POSIX shell while
> keeping the test suite and comparing it with "realpath -m":
> https://gitlab.mister-muffin.de/josch/realpath
> 
> The preinst script should probably continue using coreutils readlink when it
> exists and only fall back to the re-implementation in POSIX shell if the
> version of readlink on the system does not provide the -m option (as it is the
> case with busybox).
> 
> Since I now was able to successfully rebuild glibc, I can confirm that this is
> the last puzzlepiece needed to allow to create and configure a system
> containing only the following packages (and their Depends) without errors:
> base-files, base-passwd, busybox, debianutils, dpkg, libc-bin, mawk, tar
> 
> So it would be great if this could be solved somehow. What do you think? :)

In case you find it useful, attached is a debdiff that worked for me.

Thanks!

cheers, josch
diff -Nru glibc-2.30/debian/changelog glibc-2.30/debian/changelog
--- glibc-2.30/debian/changelog	2020-03-12 23:47:03.000000000 +0100
+++ glibc-2.30/debian/changelog	2020-03-21 21:05:38.000000000 +0100
@@ -1,3 +1,10 @@
+glibc (2.30-2.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * wip
+
+ -- Johannes 'josch' Schauer <josch@debian.org>  Sat, 21 Mar 2020 21:05:38 +0100
+
 glibc (2.30-2) unstable; urgency=medium
 
   * debian/rules.d/debhelper.mk: depends on libgcc-sN instead of libgccN.
diff -Nru glibc-2.30/debian/debhelper.in/libc.preinst glibc-2.30/debian/debhelper.in/libc.preinst
--- glibc-2.30/debian/debhelper.in/libc.preinst	2020-03-11 09:56:37.000000000 +0100
+++ glibc-2.30/debian/debhelper.in/libc.preinst	2020-03-21 21:05:38.000000000 +0100
@@ -90,6 +90,94 @@
     done
 }
 
+# realpath -m and readlink -m are not supported under busybox
+# this function has a test suite and documentation here:
+# https://gitlab.mister-muffin.de/josch/realpath
+realpath_m_rec()
+{
+    # resolve symlink (if there is one) and use $@ to detect symlink loops
+    while [ -L "$1" ] && target=$(readlink -- "$1"); do
+        REPLY=$(dirname "$1")
+        # Resolve relative to symlink's directory
+        if [ "$REPLY" = "." ]; then
+            REPLY=$target
+        else
+            case "$target" in
+                /*)
+                    REPLY=$target;;
+                *)
+                    REPLY=$REPLY/$target;;
+            esac
+        fi
+        # Break out if we found a symlink loop
+        for target in "$@"; do [ "$REPLY" = "$target" ] && break 2; done
+        # Add to the loop-detect list and tail-recurse
+        set -- "$REPLY" "$@"
+    done
+    # recurse unless root
+    REPLY=$(dirname "$1")
+    if [ "$REPLY" != "/" ] && [ "$REPLY" != "." ]; then
+        REPLY=$(realpath_m_rec "$REPLY");
+    fi
+    # set $1 to dirname and $2 to basename
+    set -- "$REPLY" "$(basename "$1")"
+    # combine canon parent w/basename
+    REPLY=$PWD
+    while [ $# -gt 0 ]; do
+        # handle case of component starting with double slash and no
+        # other slashes separately because it cannot be solved by
+        # globbing
+        if echo "$1" | grep -E '^//[^/]*$' >/dev/null 2>&1; then
+            REPLY=//
+            first=$(echo "$1" | cut -c3-)
+            shift
+            set -- "$first" "$@"
+            continue
+        fi
+        # all other cases can be expressed by globbing
+        case $1 in
+            /*)
+                REPLY=/
+                first=$(echo "$1" | sed -e 's/^\/\+//')
+                shift
+                set -- "$first" "$@"
+                ;;
+            */*)
+                front=${1%%/*}
+                back=$(echo "$1" | sed -e "s/^$front\\/\\+//")
+                shift
+                set -- "$front" "$back" "$@"
+                ;;
+            ''|.)
+                shift
+                ;;
+            ..)
+                REPLY=$(dirname "$REPLY")
+                shift
+                ;;
+            *)
+                REPLY="${REPLY%/}/$1"
+                shift
+                ;;
+        esac
+    done
+    echo "$REPLY"
+}
+
+realpath_m()
+{
+    # realpath -m should never return a non-zero exit status
+    # if it does, we know that it does not support -m (like under busybox)
+    if realpath -m "$1" >/dev/null 2>&1; then
+        # use system realpath
+        realpath -m "$1"
+    else
+        # fall back to our own realpath -m implementation
+        realpath_m_rec "$1"
+    fi
+}
+
+
 if [ "$type" != abort-upgrade ]
 then
     # Load debconf module if available and usable
@@ -223,7 +311,7 @@
 then
     # Try to detect copies of the libc library in the various places
     # the dynamic linker uses.
-    ldfile=$(readlink -m RTLD_SO)
+    ldfile=$(realpath_m RTLD_SO)
     if test -f "$file"; then
         ldbytes=$(head -c 20 RTLD_SO | od -c)
     else

Attachment: signature.asc
Description: signature


Reply to: