提交 de45164e 编写于 作者: R Rich Felker

add options when explicitly invoking dynamic loader

so far the options are --library-path and --preload which override the
corresponding environment variables, and --list which forces the
behavior of ldd even if the invocation name is not ldd. both the
two-arg form and the one-arg form using an equals sign are supported.

based loosely on a patch proposed by Rune.
上级 b1ef8067
......@@ -1055,12 +1055,31 @@ void *__dynlink(int argc, char **argv)
size_t l = strlen(ldname);
if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
*argv++ = (void *)-1;
if (argv[0] && !strcmp(argv[0], "--")) *argv++ = (void *)-1;
while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') {
char *opt = argv[0]+2;
*argv++ = (void *)-1;
if (!*opt) {
break;
} else if (!memcmp(opt, "list", 5)) {
ldd_mode = 1;
} else if (!memcmp(opt, "library-path", 12)) {
if (opt[12]=='=') env_path = opt+13;
else if (opt[12]) *argv = 0;
else if (*argv) env_path = *argv++;
} else if (!memcmp(opt, "preload", 7)) {
if (opt[7]=='=') env_preload = opt+8;
else if (opt[7]) *argv = 0;
else if (*argv) env_preload = *argv++;
} else {
argv[0] = 0;
}
argv[-1] = (void *)-1;
}
if (!argv[0]) {
dprintf(2, "musl libc\n"
"Version %s\n"
"Dynamic Program Loader\n"
"Usage: %s [--] pathname%s\n",
"Usage: %s [options] [--] pathname%s\n",
__libc_get_version(), ldname,
ldd_mode ? "" : " [args]");
_exit(1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册