From b36625fb58a4de064073940b771587b1cb517ed6 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Fri, 3 Dec 2021 10:54:10 +0100 Subject: [PATCH] csexec: export ${CSEXEC_ARGV0} if --skip-ld-linux is used ... because shebang-executed shell scripts cannot easily access the original value of argv[0] by other means. --- doc/csexec.adoc | 4 +++- src/csexec.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/csexec.adoc b/doc/csexec.adoc index 8acce7b..2af3c8c 100644 --- a/doc/csexec.adoc +++ b/doc/csexec.adoc @@ -57,7 +57,9 @@ ENVIRONMENT VARIABLES followed by a list of custom arguments for the analyzer, each of them separated by the *BEL* character. If the value of *`${CSEXEC_WRAP_CMD}`* starts with *--skip-ld-linux* followed by *BEL*, csexec does not explicitly - invoke the system dynamic linker. + invoke the system dynamic linker and it exports the *`${CSEXEC_ARGV0}`* + environment variable with the desired value of *argv0* (because + shebang-executed shell scripts cannot easily access it by other means). BUGS diff --git a/src/csexec.c b/src/csexec.c index 530086c..c5f2023 100644 --- a/src/csexec.c +++ b/src/csexec.c @@ -216,6 +216,9 @@ int main(int argc, char *argv[]) if (1 < wrap_argc && STREQ("--skip-ld-linux", exec_args[0])) { exec_file = exec_args[/* real wrap_cmd */ 1]; exec_args[++exec_args_offset] = argv[/* ARG0 */ 1]; + + // shebang-executed shell scripts cannot easily access the real argv[0] + setenv("CSEXEC_ARGV0", argv[/* ARG0 */ 1], /* overwrite */ 1); } else { // explicitly invoke dynamic linker