Trim LD_LIBRARY_PATH on startup

This commit is contained in:
Anmol Sethi 2020-05-28 00:49:37 -04:00
parent 9a3b9fcac2
commit 7ab47b3d83
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB
2 changed files with 27 additions and 8 deletions

View File

@ -5,21 +5,22 @@
# More complicated than readlink -f or realpath to support macOS. # More complicated than readlink -f or realpath to support macOS.
# See https://github.com/cdr/code-server/issues/1537 # See https://github.com/cdr/code-server/issues/1537
bin_dir() { root_dir() {
# We read the symlink, which may be relative from $0. # We read the symlink, which may be relative from $0.
dst="$(readlink "$0")" dst="$(readlink "$0")"
# We cd into the $0 directory. # We cd into the $0 directory.
cd "$(dirname "$0")" || exit 1 cd "$(dirname "$0")" || exit 1
# Now we can cd into the dst directory. # Now we can cd into the directory above the dst directory which is the root
cd "$(dirname "$dst")" || exit 1 # of the release.
# Finally we use pwd -P to print the absolute path of the directory of $dst. cd "$(dirname "$dst")/.." || exit 1
# Finally we use pwd -P to print the absolute path the root.
pwd -P || exit 1 pwd -P || exit 1
} }
BIN_DIR=$(bin_dir) ROOT="$(root_dir)"
if [ "$(uname)" = "Linux" ]; then if [ "$(uname)" = "Linux" ]; then
export LD_LIBRARY_PATH="$BIN_DIR/../lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}" export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH"
elif [ "$(uname)" = "Darwin" ]; then elif [ "$(uname)" = "Darwin" ]; then
export DYLD_LIBRARY_PATH="$BIN_DIR/../lib${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}" export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH"
fi fi
exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@" exec "$ROOT/lib/node" "$ROOT" "$@"

View File

@ -126,7 +126,25 @@ const main = async (cliArgs: Args): Promise<void> => {
} }
} }
function trimLDLibraryPath(): void {
let ldVar: string
if (process.platform === "linux") {
ldVar = "LD_LIBRARY_PATH"
} else if (process.platform === "darwin") {
ldVar = "DYLD_LIBRARY_PATH"
} else {
return
}
// Removes the leading path added by ./ci/build/code-server.sh to use our bundled
// dynamic libraries. See ci/build/build-standalone-release.sh
// This is required to avoid child processes using our bundled libraries.
process.env[ldVar] = process.env[ldVar]?.replace(path.dirname(process.execPath) + ":", "")
}
async function entry(): Promise<void> { async function entry(): Promise<void> {
trimLDLibraryPath()
const tryParse = async (): Promise<Args> => { const tryParse = async (): Promise<Args> => {
try { try {
let args = parse(process.argv.slice(2)) let args = parse(process.argv.slice(2))