ClickHouse/utils/self-extracting-executable
Azat Khuzhin 1fb7605fb4 Fix self extracting binaries under qemu linux-user (qemu-$ARCH-static)
The problem was that the decompressor uses realpath(/proc/self/exe)
instead of readlink(/proc/self/exe), while realpath() does lots of
trickerly [1] which leads to bypassing qemu linux-user override [2] of
/proc/self/exe to the executable with with it had been called -- and
the reason for this is that the getpid() after unshare returns 1, while
reading /proc/self returns the pid that was before unshare (from the
chroot) [3].

  [1]: 4290aed051/stdlib/canonicalize.c (L223)
  [2]: ed8ad9728a/linux-user/syscall.c (L8634)
  [3]: https://gist.github.com/azat/fcbd8b6c26afd505ae5f3387fc15f0e2

But note, that even after this patch qemu without binfmt will not work,
due to internally the code calls execv() while qemu does not handle it
(see [4]).

  [4]: https://patchwork.kernel.org/project/qemu-devel/patch/1453091602-21843-1-git-send-email-petrosagg@gmail.com/

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-07-17 13:10:40 +02:00
..
CMakeLists.txt
compressor.cpp Check return value of close() in self-extracting-executable 2023-02-07 11:28:22 +01:00
decompressor.cpp Fix self extracting binaries under qemu linux-user (qemu-$ARCH-static) 2023-07-17 13:10:40 +02:00
post_build.sh
types.h add --exec param, allow compressed to be renamed 2022-08-19 20:43:10 +00:00