pkg
pkg copied to clipboard
pkg: Error opening the trusted directory
Hit this error when recently upgraded from 1.17.0 to 1.20.0 in cross toolchain setup https://github.com/dotnet/dotnet-buildtools-prereqs-docker/issues/965.
Repro (ubuntu amd64):
#!/usr/bin/env bash
set -e
__RootfsDir=$(pwd)/.tools/rootfs/x64
__FreeBSDPkg=1.20.0 # works with 1.17.0
mkdir -p $__RootfsDir/usr/local/etc
wget -O - https://download.freebsd.org/ftp/releases/amd64/amd64/14.0-RELEASE/base.txz | tar -C "$__RootfsDir" -Jxf - ./lib ./usr/lib ./usr/libdata ./usr/include ./usr/share/keys ./etc ./bin/freebsd-version
echo "ABI = \"FreeBSD:14:amd64\"; FINGERPRINTS = \"$__RootfsDir/usr/share/keys\"; REPOS_DIR = [\"$__RootfsDir/etc/pkg\"]; REPO_AUTOUPDATE = NO; RUN_SCRIPTS = NO;" > "${__RootfsDir}"/usr/local/etc/pkg.conf
echo "FreeBSD: { url: \"pkg+http://pkg.FreeBSD.org/\${ABI}/quarterly\", mirror_type: \"srv\", signature_type: \"fingerprints\", fingerprints: \"$__RootfsDir/usr/share/keys/pkg\", enabled: yes }" > "${__RootfsDir}"/etc/pkg/FreeBSD.conf
mkdir -p $__RootfsDir/tmp
wget -O - "https://github.com/freebsd/pkg/archive/${__FreeBSDPkg}.tar.gz" | tar -C $__RootfsDir/tmp -zxf -
cd $__RootfsDir/tmp/pkg-$__FreeBSDPkg
mkdir -p $__RootfsDir/host/etc
./autogen.sh && ./configure --prefix="$__RootfsDir"/host && make -j && make install
rm -rf $__RootfsDir/tmp/pkg-$__FreeBSDPkg
INSTALL_AS_USER=$(whoami) $__RootfsDir/host/sbin/pkg -r $__RootfsDir -C $__RootfsDir/usr/local/etc/pkg.conf update
INSTALL_AS_USER=$(whoami) $__RootfsDir/host/sbin/pkg -r $__RootfsDir -C $__RootfsDir/usr/local/etc/pkg.conf install --yes libunwind icu libinotify openssl krb5 terminfo-db
With pwd=/testdir, it fails:
pkg: Error opening the trusted directory /testdir/.tools/rootfs/x64/usr/share/keys/pkg/trusted pkg: Error loading trusted certificates Unable to update repository FreeBSD Error updating repositories!
seems like RELATIVE_PATH macro trims the leading / which fails openat:
https://github.com/freebsd/pkg/blob/e7387625fd3fa359e8ec2b77efa76243664eb3f9/libpkg/pkg_repo.c#L1057
strace:
[pid 11734] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=11739, si_uid=33333, si_status=0, si_utime=42, si_stime=6} ---
[pid 11734] openat(4, "testdir/.tools/rootfs/x64/usr/share/keys/pkg/trusted", O_RDONLY|O_DIRECTORY) = -1 ENOENT (No such file or directory)
[pid 11734] write(2, "pkg: ", 5pkg: ) = 5
1.17.2 appears to be the last version that worked. 1.17.3 started throwing the above error