我有一个调用os.Executable()
一个简单的围棋程序。在旧版本的Linux系统(2.6.32),它无法读取/proc/self/exe
,通过strace -f myexe -v public_html/ |& head -30
为显示:
execve("/home/willem/myexe", ["myexe", "-v", "public_html/"], [/* 45 vars */]) = 0
mmap(0x1200000, 13352277, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0x1200000
readlink("/proc/self/exe", "/hom/willem/my"..., 4096) = 37
mmap(0x400000, 13463552, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400000
mmap(0x400000, 10254571, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400000
mprotect(0x400000, 10254571, PROT_READ|PROT_EXEC) = 0
mmap(0xfc7000, 938770, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0x9c7000) = 0xfc7000
mprotect(0xfc7000, 938770, PROT_READ|PROT_WRITE) = 0
mmap(0x10ad000, 170408, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x10ad000
munmap(0x1201000, 13348181) = 0
uname({sys="Linux", node="sip5-83.nexcess.net", ...}) = 0
brk(0) = 0x10d7000
brk(0x10d81c0) = 0x10d81c0
arch_prctl(ARCH_SET_FS, 0x10d7880) = 0
set_tid_address(0x10d7b50) = 16193
set_robust_list(0x10d7b60, 24) = 0
rt_sigaction(SIGRTMIN, {0x83c310, [], SA_RESTORER|SA_SIGINFO, 0x83ba20}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x83c3a0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x83ba20}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=10240*1024, rlim_max=RLIM64_INFINITY}) = 0
readlink("/proc/self/exe", 0x7ffcfec64dc0, 4096) = -1 ENOENT (No such file or directory)
我不明白为什么第一的readlink工作和第二个没有。有没有叉子和可执行文件不移动。有任何想法吗?
我可以通过os.Executable()
移动到我的程序的初始化修复它,但我想明白为什么它不工作不变。
所以原因竟然是UPX(可执行压缩机)。我没有想到的是较早的,因为它是包含在我的构建流水线。显然,在一些系统上它没有解压到内存,但使用临时文件,导致了这一错误。我仍然不解,为什么跟踪输出不显示重命名,但很可惜。