rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.64k stars 306 forks source link

Bear intercept does not work with shell scripts #553

Closed nareshkbohra closed 7 months ago

nareshkbohra commented 8 months ago

Describe the bug Shell script based wrapper on custom code generator are not being executed when running under bear intercept. I can still intercept basic command such as ls but any shell script just exits with error code 127.

To Reproduce

  1. Create a shell script test.sh with only an echo hello and run bear intercept -- ./test.sh. This will exit with error code 127.

Expected behavior Even if this does not get captured, this should atleast run , as following compilation are dependent on it.

Environment:

Additional context

Before you send...

rizsotto commented 8 months ago

Hey @nareshkbohra , thanks for the report.

I am not sure what's the reason for this, because the whole integration test set is based on shell scripts... Could you send logs, while running bear intercept -vvvv -- ./test.sh, and maybe check the followings: ./test.sh exits with zero when you run without Bear? Or what is the shell that you executing with the script? And what kind of executable is that shell (file /bin/sh if your shell is /bin/sh)?

nareshkbohra commented 8 months ago

Hi rizsotto, Thanks for your response.

Logs:

 bear intercept --verbose  -- ./test.sh
[16:48:43.789866, br, 8491] bear: 3.1.2
[16:48:43.790001, br, 8491] arguments: ["bear", "intercept", "--verbose", "--", "./test.sh"]
[16:48:43.790108, br, 8491] environment: ["NODE_VERSION=16.18.1", "HOSTNAME=6a00be7d971f", "OS_NAME=CS75", "TERM=screen-256color", "SHFMT_VERSION=3.1.2", "CCACHE_LOGFILE=", "OLDPWD=/home/naresh.bohra/work/code/wifi-mwm", "PIP_INDEX_URL=https://devpi.infra.corp.arista.io/root/pypi/+simple/", "PROMPT_DIRTRIM=3", "DIST_CACHE_DIR=/garage/naresh.bohra/ccache_builds", "USER=jenkins", "LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:", "EXTRA_GCC_VERSION=5.2.0", "SINGLE_BUNDLE_UPGRADE_SUPPORT=FALSE", "GO111MODULE=off", "PATH=/export/make-4.2.1:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/naresh.bohra/bin:/home/naresh.bohra/.local", "SC_VERSION=0.6.0", "DIST_WIFI_BASE=\"http://distwifi/storage/bin\"", "PWD=/tmp/test", "GJF_VERSION=1.7", "DBG_BLD=1", "EDITOR=vim", "CACHE_TOOL=ccache", "LANG=en_US.UTF-8", "TZ=Asia/Kolkata", "LLVM_VERSION=8.0.0", "GOLANGCI_LINT_VERSION=1.50.1", "PS1=\\[\\033[0;37m\\][\\u@\\h\\w]$(parse_git_branch)\\n$ \\[\\033[1;37m\\]", "SHLVL=1", "HOME=/home/naresh.bohra", "LC_CTYPE=en_US.utf8", "LESSOPEN=||/usr/bin/lesspipe.sh %s", "CCACHE_VERSION=3.7.6", "NOLOGFILE=1", "GO_VERSION_1_20_5=1.20.5", "GO_VERSION=1.17.7", "_=/home/naresh.bohra/.local/bear"]
[16:48:43.790132, br, 8491] sysname: Linux
[16:48:43.790135, br, 8491] release: 4.19.134-32460324.AroraKernel419.1.el7.x86_64
[16:48:43.790138, br, 8491] version: #1 SMP Thu Jun 29 12:57:31 PDT 2023
[16:48:43.790141, br, 8491] machine: x86_64
[16:48:43.790175, br, 8491] arguments parsed: {program: intercept, arguments: [{--: [./test.sh]}, {--library: [/home/naresh.bohra/.local/lib64/bear/libexec.so]}, {--output: [events.json]}, {--verbose: []}, {--wrapper: [/home/naresh.bohra/.local/lib64/bear/wrapper]}, {--wrapper-dir: [/home/naresh.bohra/.local/lib64/bear/wrapper.d]}, {command: [intercept]}]}
[16:48:43.790265, br, 8491] Created library preload session. [library=/home/naresh.bohra/.local/lib64/bear/libexec.so, executor=/home/naresh.bohra/.local/lib64/bear/wrapper]
[16:48:43.791993, br, 8491] Running gRPC server. dns:///localhost:39037
[16:48:43.792230, br, 8491] Process spawned. [pid: 8496, command: ["/home/naresh.bohra/.local/lib64/bear/wrapper", "--destination", "dns:///localhost:39037", "--verbose", "--execute", "./test.sh", "--", "./test.sh"]]
[16:48:43.792259, br, 8491] Process wait requested. [pid: 8496]
[16:48:43.793961, el, 8496] lib.cc; on_load
[16:48:43.794871, wr, 8496, ppid: 8491] wrapper: 3.1.3
[16:48:43.794896, wr, 8496, ppid: 8491] arguments: ["/home/naresh.bohra/.local/lib64/bear/wrapper", "--destination", "dns:///localhost:39037", "--verbose", "--execute", "./test.sh", "--", "./test.sh"]
[16:48:43.794978, wr, 8496, ppid: 8491] environment: ["CACHE_TOOL=ccache", "CCACHE_LOGFILE=", "CCACHE_VERSION=3.7.6", "DBG_BLD=1", "DIST_CACHE_DIR=/garage/naresh.bohra/ccache_builds", "DIST_WIFI_BASE=\"http://distwifi/storage/bin\"", "EDITOR=vim", "EXTRA_GCC_VERSION=5.2.0", "GJF_VERSION=1.7", "GO111MODULE=off", "GOLANGCI_LINT_VERSION=1.50.1", "GO_VERSION=1.17.7", "GO_VERSION_1_20_5=1.20.5", "HOME=/home/naresh.bohra", "HOSTNAME=6a00be7d971f", "IMAGE_SIGN_AUTHTOKEN=/home/naresh.bohra/work/code/api_token", "INTERCEPT_REPORT_COMMAND=/home/naresh.bohra/.local/lib64/bear/wrapper", "INTERCEPT_REPORT_DESTINATION=dns:///localhost:39037", "INTERCEPT_VERBOSE=true", "LANG=en_US.UTF-8", "LC_CTYPE=en_US.utf8", "LD_PRELOAD=/home/naresh.bohra/.local/lib64/bear/libexec.so", "LESSOPEN=||/usr/bin/lesspipe.sh %s", "LLVM_VERSION=8.0.0", "LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:", "NODE_VERSION=16.18.1", "NOLOGFILE=1", "OLDPWD=/home/naresh.bohra/work/code/wifi-mwm", "OS_NAME=CS75", "PATH=/export/make-4.2.1:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/naresh.bohra/bin:/home/naresh.bohra/.local", "PIP_INDEX_URL=https://devpi.infra.corp.arista.io/root/pypi/+simple/", "PROMPT_DIRTRIM=3", "PS1=\\[\\033[0;37m\\][\\u@\\h\\w]$(parse_git_branch)\\n$ \\[\\033[1;37m\\]", "PWD=/tmp/test", "SC_VERSION=0.6.0", "SHFMT_VERSION=3.1.2", "SHLVL=1", "SINGLE_BUNDLE_UPGRADE_SUPPORT=FALSE", "TERM=screen-256color", "TZ=Asia/Kolkata", "USER=jenkins", "VAULT_AUTHTOKEN=/tmp/vault_token", "_=/home/naresh.bohra/.local/bear"]
[16:48:43.795019, wr, 8496, ppid: 8491] arguments parsed: {program: /home/naresh.bohra/.local/lib64/bear/wrapper, arguments: [{--: [./test.sh]}, {--destination: [dns:///localhost:39037]}, {--execute: [./test.sh]}, {--verbose: []}]}
[16:48:43.795892, wr, 8496, ppid: 8491] gRPC call requested: supervise::Supervisor::Resolve
[16:48:43.797273, br, 8491] trying to resolve for library: ./test.sh
[16:48:43.797531, wr, 8496, ppid: 8491] gRPC call [Resolve] finished: true
[16:48:43.797849, wr, 8496, ppid: 8491] Process spawned. [pid: 8501, command: ["./test.sh"]]
[16:48:43.797882, wr, 8496, ppid: 8491] gRPC call requested: supervise::Interceptor::Register
[16:48:43.799576, wr, 8496, ppid: 8491] gRPC call [Register] finished: true
[16:48:43.799619, wr, 8496, ppid: 8491] Process wait requested. [pid: 8501]
[16:48:43.799648, wr, 8496, ppid: 8491] Process wait request: done. [pid: 8501]
[16:48:43.799652, wr, 8496, ppid: 8491] gRPC call requested: supervise::Interceptor::Register
[16:48:43.799930, wr, 8496, ppid: 8491] gRPC call [Register] finished: true
[16:48:43.800267, wr, 8496, ppid: 8491] succeeded with: 127
[16:48:43.800307, el, 8496] lib.cc; on_unload
[16:48:43.800833, br, 8491] Process wait request: done. [pid: 8496]
[16:48:43.800876, br, 8491] Running command. [Exited with 127]
[16:48:43.800890, br, 8491] Stopping gRPC server.
[16:48:43.801135, br, 8491] succeeded with: 127

I could not run with -vvvv as it was throwing unrecognized parameter.

Content of test.sh is simple

$ cat test.sh
echo hello
[naresh.bohra@6a00be7d971f/tmp/test]
$ ./test.sh
hello
[naresh.bohra@6a00be7d971f/tmp/test]
$ echo $?
0
[naresh.bohra@6a00be7d971f/tmp/test]
$ echo $SHELL
/bin/bash
[naresh.bohra@6a00be7d971f/tmp/test]
$ file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=94b20c7f7a0529512f63bae145b524890ceae5a5, stripped

Now thinking about shell, does it change anything to specify #!/bin/sh at the top.

nareshkbohra commented 8 months ago

Actually specifying #!/bin/sh does makes it work. Is there a way to specify for bear to pick that shell?

$ cat test.sh
#!/bin/sh
echo hello
[naresh.bohra@6a00be7d971f/tmp/test]
$ bear intercept   -- ./test.sh
hello
nareshkbohra commented 8 months ago

Not sure if this is relevant but I have /bin/sh symlinked with /bin/bash .

[naresh.bohra@6a00be7d971f/tmp/test]
$ ls -larth /bin/sh
lrwxrwxrwx 1 root root 4 Aug 17 13:46 /bin/sh -> bash
nareshkbohra commented 7 months ago

Added shebang at the top of script and bear started working. Closing the issue for now.