且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么 DYLD_LIBRARY_PATH 不在这里传播?

更新时间:2023-11-14 08:51:22

大概您正在运行 El Capitan (OS X 10.11) 或更高版本.这是系统完整性保护的副作用.来自 系统完整性保护指南:运行时保护 文章:

Presumably, you are running El Capitan (OS X 10.11) or later. It's a side effect of System Integrity Protection. From the System Integrity Protection Guide: Runtime Protections article:

当一个进程启动时,内核会检查是否主进程可执行文件在磁盘上受到保护或使用特殊系统签名权利.如果其中一个为真,则设置一个标志以表示它受到保护以防修改.…

When a process is started, the kernel checks to see whether the main executable is protected on disk or is signed with an special system entitlement. If either is true, then a flag is set to denote that it is protected against modification. …

… 任何动态链接器 (dyld)环境变量,例如 DYLD_LIBRARY_PATH,在启动受保护的进程.

… Any dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are purged when launching protected processes.

所有系统提供的解释器,包括 /bin/sh,都以这种方式受到保护.因此,当您调用 sh 时,所有 DYLD_* 环境变量都会被清除.

All of the system-provided interpreters, including /bin/sh, are protected in this fashion. Therefore, when you invoke sh, all DYLD_* environment variables are purged.

您可以编写一个设置 DYLD_LIBRARY_PATH 然后执行 .sconf_temp/conftest_7 的 shell 脚本.你可以使用 shell 解释器来执行——事实上,你必须——并且环境变量会很好,因为清除是在受保护的可执行文件启动时发生的.基本上,这种方法类似于您问题中的工作示例,但封装在 shell 脚本中.

You could write a shell script which sets DYLD_LIBRARY_PATH and then executes .sconf_temp/conftest_7. You can use the the shell interpreter to execute that — indeed, you must — and the environment variable will be fine, since the purging happens when a protected executable is started. Basically, this approach is analogous to the working example in your question, but encapsulated in a shell script.