Triggers fail to execute when operating in rootless/--no-chown mode
I was experimenting with using Alpine/apk-tools as a basis for an immutable, rootless container engine's rootfs; using a tool like
bwrap --bind ./alpine-rootfs / --ro-bind /etc/resolv.conf /etc/resolv.conf --dev /dev --proc /proc --unshare-pid --unshare-ipc --unshare-uts /bin/ash for example, one can run a "rootless" Alpine container - goal is to not have any files in the rootfs owned by uid 0/root, because that would mean rootless rootfs cleanup would become difficult.
However, when executing triggers, apk expects to be running as uid 0, and attempts to
chroot into the target rootfs, irrespective of the fact that the active rootfs is being targeted - see https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/src/database.c#L1909.
I'm not sure what would be the ideal way to remove this dependency on chroot - I considered a
snprintf(fd_pathbuf, sizeof(fd_pathbuf), "/proc/self/fd/%d", fd); readlink(fd_pathbuf, fd_path, sizeof(fd_path)); and then
strcmp(fd_path, "/") but I am not sure if there is a better solution, or an alternate approach worth taking.