You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "mbeckerle (via GitHub)" <gi...@apache.org> on 2023/06/05 14:29:17 UTC
[GitHub] [daffodil-vscode] mbeckerle opened a new issue, #652: vscode extension must be isolated from user's shell environment
mbeckerle opened a new issue, #652:
URL: https://github.com/apache/daffodil-vscode/issues/652
I was unable to get the daffodil vscode 1.3.0-RC2 to work when installed.
This is because the vscode extension is sensitive to the default environment. It currently picks up many things from the users default shell environment.
The vscode extension needs to be isolated from the user's shell environment.
One example is that the vscode extension requires Java 11.
Starting the vscode extension needs to guarantee Java 11 is what is being used. It should not use what is configured via the JAVA_HOME environment variable by the user. (Mine is defaulting to Java 17 these days.)
To get vscode to work I have this script I use to launch vscode in a minimal/empty environment with just the few things it needs. This technique is also useful to determine if you are depending on the environment in any way:
```
#! /bin/bash
if [ "$1" = "emptyEnv" ] # is it the special first arg
then
shift # discard special first arg, and continue with the rest of the script
else
# execute this same script again in an empty environment
CMD=$0
exec -c $CMD "emptyEnv" $* # exec with an empty environment and special first arg
fi
# the environment is empty when we get here
# just add env vars we need to get vscode to work
export LANG=en_US.UTF-8
export HOME=/home/mbeckerle
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 # java 11 required
export PATH=$JAVA_HOME/bin:$PATH
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus # vscode spits lots of errors without this
exec /usr/bin/code
# end
```
Then, within ~/.config/Code/User/settings.json, I had to create these settings for terminal:
```
"terminal.integrated.inheritEnv": false,
"terminal.integrated.profiles.linux": {
"Custom Init": {
"path": "/bin/bash",
"args": [
"--norc"
]
}
},
"terminal.integrated.defaultProfile.linux": "Custom Init"
```
That instructs vscode not to create a login shell for the terminal. The --norc option means it does not run the .bashrc file so that the java version specified in the launch script sticks.
I am not sure the inheritEnv setting actually does anything. That alone sounds like the right thing, but that alone didn't solve the problem.
You still have everything in the login shell environment where vscode was launched. Hence the need for the environment-emptying launch script.
With those two techniques combined, a terminal created by vscode does not inherit everything my typical shell has. For example there is no daffodil on the path, no DAFFODIL_CLASSPATH env var, etc. Rather it has only a small environment of just what vscode needs.
Given the above if I just create a terminal with Terminal > new Terminal: The environment is relatively simple:
```
bash-5.0$ env
COLORTERM=truecolor
TERM_PROGRAM_VERSION=1.78.2
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
NO_AT_BRIDGE=1
PWD=/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP
VSCODE_GIT_ASKPASS_NODE=/usr/share/code/code
HOME=/home/mbeckerle
LANG=en_US.UTF-8
GIT_ASKPASS=/usr/share/code/resources/app/extensions/git/dist/askpass.sh
CHROME_DESKTOP=code-url-handler.desktop
VSCODE_GIT_ASKPASS_EXTRA_ARGS=--ms-enable-electron-run-as-node
TERM=xterm-256color
VSCODE_GIT_IPC_HANDLE=/tmp/vscode-git-56a269c0f5.sock
DISPLAY=:0
SHLVL=1
VSCODE_GIT_ASKPASS_MAIN=/usr/share/code/resources/app/extensions/git/dist/askpass-main.js
GDK_BACKEND=x11
PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
TERM_PROGRAM=vscode
_=/usr/bin/env
```
If I run daffodil debugging, then c-C in the terminal it creates, then the environment has this added environment variable only.
```
DAFFODIL_DEBUG_CLASSPATH=/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP/../ethernetIP/src/main/resources:/home/mbeckerle/dataiti/opensource/DFDLSchemas/PCAP/lib_managed/jars/com.owlcyberdefense/dfdl-ethernetip/dfdl-ethernetip-1.2.0.jar
```
This works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil-vscode] shanedell commented on issue #652: vscode extension must be isolated from user's shell environment
Posted by "shanedell (via GitHub)" <gi...@apache.org>.
shanedell commented on issue #652:
URL: https://github.com/apache/daffodil-vscode/issues/652#issuecomment-1579546421
@mbeckerle So currently we allow for grabbing of the active terminal if it has the name `daffodil-debugger`, should we no longer do this? So if the code finds a terminal open with the name `daffodil-debugger` it will destroy it and open a new one to use for that instance to run. Once that terminal completes it will stay open so you can view output. So before each run of the debugger it will close any terminals with `daffodil-debugger` and start a fresh terminal. Does this sound like something you want?
Also my plan is instead of letting the VSCode API decide what shell is used that it will automatically make windows use `bat` and macos/linux use `bash`. Specifically when it uses `bash` it runs:
```bash
env -i bash --norc
```
What this does is make a complete clean environment that will have no environment variables set. This protect against the issues you were seeing before. I am not sure what the way to do this on windows is currently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil-vscode] shanedell closed issue #652: vscode extension must be isolated from user's shell environment
Posted by "shanedell (via GitHub)" <gi...@apache.org>.
shanedell closed issue #652: vscode extension must be isolated from user's shell environment
URL: https://github.com/apache/daffodil-vscode/issues/652
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil-vscode] shanedell commented on issue #652: vscode extension must be isolated from user's shell environment
Posted by "shanedell (via GitHub)" <gi...@apache.org>.
shanedell commented on issue #652:
URL: https://github.com/apache/daffodil-vscode/issues/652#issuecomment-1581250946
So I think actually this a simpler fix that mentioned above. So basically all we need to do is close any found terminals with name `daffodil-debugger` and open a new one that way the ENV variables we use allows get exported
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [daffodil-vscode] shanedell commented on issue #652: vscode extension must be isolated from user's shell environment
Posted by "shanedell (via GitHub)" <gi...@apache.org>.
shanedell commented on issue #652:
URL: https://github.com/apache/daffodil-vscode/issues/652#issuecomment-1577110944
@mbeckerle I believe we had back ported, along with omega-edit, to support Java 8. Is this not working or do we have it documented somewhere saying we need Java 11? If so that should be updated as I believe we support Java 8 and up.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org