Skip to content

Commit

Permalink
csexec: export ${CSEXEC_ARGV0} if --skip-ld-linux is used
Browse files Browse the repository at this point in the history
... because shebang-executed shell scripts cannot easily access
the original value of argv[0] by other means.
  • Loading branch information
kdudka committed Dec 3, 2021
1 parent faddef0 commit b36625f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion doc/csexec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/csexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b36625f

Please sign in to comment.