为什么bash会错误地解释来自某些脚本(python,perl,libtool)的shebang和命令?(Why do shebangs and commands from certain scrip

编程入门 行业动态 更新时间:2024-10-14 02:20:39
为什么bash会错误地解释来自某些脚本(python,perl,libtool)的shebang和命令?(Why do shebangs and commands from certain scripts (python, perl, libtool) are wrongly interpreted by bash?)

编辑:这个问题仍然存在:我重建了我的整个系统,我在一个理智的主机上使用的chroot就像一个魅力。 但是一旦我启动相同的目标系统,问题又出现了:对于perl和python的shebang被错误地解释了......

我已经成功地建立和管理我自己的Linux系统大约4年了,但我现在有点困难,我非常感谢能找到解决这个地狱般问题的方向:

一些Python,Perl脚本甚至来自'configure'脚本中的命令都被误解了:我已经确定了python-config,xscreensaver-text和intltool-merge(Perl脚本),其Shebangs不受尊重或仅由shell解释。

我们一直在讨论locales,encondings,关于UTF-8的考虑因素,检查env,$ LANG,$ TERM等等,切换Linux内核(3.1.5,3.5.4,3.8.1,3.11.1),但是仍然没有成功。

这是xscreensaver-text的strace输出,首先是CLI的简单调用,然后是带有显式Perl的第二次调用。 它的shebang是:

#!/bin/perl -w root@poopy:~# strace /usr/bin/xscreensaver-text execve("/usr/bin/xscreensaver-text", ["/usr/bin/xscreensaver-text"], [/* 32 vars */]) = -1 ENOEXEC (Exec format error) write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error ) = 32 exit_group(1) = ? +++ exited with 1 +++ root@poopy:~# strace perl /usr/bin/xscreensaver-text execve("/usr/bin/perl", ["perl", "/usr/bin/xscreensaver-text"], [/* 32 vars */]) = 0 brk(0) = 0x601000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eb1d000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=198969, ...}) = 0 mmap(NULL, 198969, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd74eaec000 close(3) = 0 open("/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \37\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1868472, ...}) = 0 mmap(NULL, 3981888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd74e52f000 mprotect(0x7fd74e6f1000, 2097152, PROT_NONE) = 0 mmap(0x7fd74e8f1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c2000) = 0x7fd74e8f1000 mmap(0x7fd74e8f7000, 16960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd74e8f7000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eaeb000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eae9000 arch_prctl(ARCH_SET_FS, 0x7fd74eae9740) = 0 mprotect(0x7fd74e8f1000, 16384, PROT_READ) = 0 mprotect(0x7fd74eb1e000, 4096, PROT_READ) = 0 munmap(0x7fd74eaec000, 198969) = 0 brk(0) = 0x601000 brk(0x622000) = 0x622000 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd74eae9a10) = 16061 wait4(16061, poopy Linux 3.11.1 ven. 27 sept. 2013 14:06:27 CEST up 2:17, 1 user load average: 0,03, 0,06, 0,12 [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16061 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16061, si_status=0, si_utime=2, si_stime=0} --- exit_group(0) = ? +++ exited with 0 +++

我的路径是:

/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/jdk/bin:/usr/lib64/jdk/jre/bin

它位于具有i686 multilib功能的x86_64系统上。 我的语言环境是fr_FR.utf8($ LANG和$ LC_ALL)。 我将添加你们需要的任何信息。 我在'/ etc / passwd'中的shell是'/ bin / bash',它存在且完美无缺。 尝试与普通用户和root,没有区别。 Bash 4.2,linux 3.11.1,glibc 2.17。 试过xterms,xfce-terminal和ttys,同样的问题。

'python-config'或'intltool-merge'(以及许多其他)具有完全相同的行为。 我甚至看到一个'configure'脚本失败并显示消息“ac_cv_somevariable:command not found”。 知道在哪里寻找调试吗?

谢谢。

EDIT : this problem is still there : I rebuilt my entire system and the chroot I use for it on a sane host works like a charm. But once I boot the same target system, the problem appears again: shebang for perl and python are wrongly interpreted...

I've been building and administrating my own Linux system successfully for about 4 years but I'm kinda stuck now and I'd appreciate very very much to get directions to fix that hellish problem:

Some Python, Perl scripts or even commands from within 'configure' scripts are misinterpreted: I've identified python-config, xscreensaver-text and intltool-merge (Perl scripts) whose Shebangs are not respected or are only interpreted by the shell.

We've been messing around with locales, encondings, considerations about UTF-8, checking env, $LANG, $TERM and such, switching Linux kernels (3.1.5, 3.5.4, 3.8.1, 3.11.1), but still no success.

Here is the strace output from xscreensaver-text, first with a simple call form the CLI then a second call with explicit Perl. Its shebang is:

#!/bin/perl -w root@poopy:~# strace /usr/bin/xscreensaver-text execve("/usr/bin/xscreensaver-text", ["/usr/bin/xscreensaver-text"], [/* 32 vars */]) = -1 ENOEXEC (Exec format error) write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error ) = 32 exit_group(1) = ? +++ exited with 1 +++ root@poopy:~# strace perl /usr/bin/xscreensaver-text execve("/usr/bin/perl", ["perl", "/usr/bin/xscreensaver-text"], [/* 32 vars */]) = 0 brk(0) = 0x601000 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eb1d000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=198969, ...}) = 0 mmap(NULL, 198969, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd74eaec000 close(3) = 0 open("/usr/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \37\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1868472, ...}) = 0 mmap(NULL, 3981888, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd74e52f000 mprotect(0x7fd74e6f1000, 2097152, PROT_NONE) = 0 mmap(0x7fd74e8f1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c2000) = 0x7fd74e8f1000 mmap(0x7fd74e8f7000, 16960, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd74e8f7000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eaeb000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd74eae9000 arch_prctl(ARCH_SET_FS, 0x7fd74eae9740) = 0 mprotect(0x7fd74e8f1000, 16384, PROT_READ) = 0 mprotect(0x7fd74eb1e000, 4096, PROT_READ) = 0 munmap(0x7fd74eaec000, 198969) = 0 brk(0) = 0x601000 brk(0x622000) = 0x622000 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd74eae9a10) = 16061 wait4(16061, poopy Linux 3.11.1 ven. 27 sept. 2013 14:06:27 CEST up 2:17, 1 user load average: 0,03, 0,06, 0,12 [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 16061 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16061, si_status=0, si_utime=2, si_stime=0} --- exit_group(0) = ? +++ exited with 0 +++

My PATH is:

/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/lib64/jdk/bin:/usr/lib64/jdk/jre/bin

It is on an x86_64 system with i686 multilib capabilities. My locale is fr_FR.utf8 ($LANG and $LC_ALL). I will add any info you guys will need. My shell in '/etc/passwd' is '/bin/bash', it exists and works flawlessly. Tried with normal users and root, no difference. Bash 4.2, linux 3.11.1, glibc 2.17. Tried in xterms, xfce-terminal and ttys, same problem.

The 'python-config' or 'intltool-merge' (and many others) have exactly the same behaviour. I even saw once a 'configure' script failing with the message "ac_cv_somevariable: command not found". Any idea where to look for debugging this?

Thanks.

最满意答案

从Linux 3.10开始,如果希望内核处理解释的脚本,则必须将名为CONFIG_BINFMT_SCRIPT的新选项设置为Y.

这里有更多解释: http : //cateee.net/lkddb/web-lkddb/BINFMT_SCRIPT.html

如果您将其编译为模块,请尝试modprobe binfmt_script模块,然后测试您的脚本。

Since Linux 3.10 a new option called CONFIG_BINFMT_SCRIPT must be set to Y if you want your kernel to handle interpreted scripts.

More explainations here : http://cateee.net/lkddb/web-lkddb/BINFMT_SCRIPT.html

If you compiled it as a module, try to modprobe the binfmt_script module and then test your scripts.

更多推荐

本文发布于:2023-08-03 07:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   命令   错误   libtool   perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!