From 7ab47b3d833436f9107a529069ae77efae840378 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Thu, 28 May 2020 00:49:37 -0400 Subject: [PATCH] Trim LD_LIBRARY_PATH on startup --- ci/build/code-server.sh | 17 +++++++++-------- src/node/entry.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ci/build/code-server.sh b/ci/build/code-server.sh index aca05745..4793cc5b 100755 --- a/ci/build/code-server.sh +++ b/ci/build/code-server.sh @@ -5,21 +5,22 @@ # More complicated than readlink -f or realpath to support macOS. # See https://github.com/cdr/code-server/issues/1537 -bin_dir() { +root_dir() { # We read the symlink, which may be relative from $0. dst="$(readlink "$0")" # We cd into the $0 directory. cd "$(dirname "$0")" || exit 1 - # Now we can cd into the dst directory. - cd "$(dirname "$dst")" || exit 1 - # Finally we use pwd -P to print the absolute path of the directory of $dst. + # Now we can cd into the directory above the dst directory which is the root + # of the release. + cd "$(dirname "$dst")/.." || exit 1 + # Finally we use pwd -P to print the absolute path the root. pwd -P || exit 1 } -BIN_DIR=$(bin_dir) +ROOT="$(root_dir)" 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 - export DYLD_LIBRARY_PATH="$BIN_DIR/../lib${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}" + export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH" fi -exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@" +exec "$ROOT/lib/node" "$ROOT" "$@" diff --git a/src/node/entry.ts b/src/node/entry.ts index 69d32ca8..42907784 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -126,7 +126,25 @@ const main = async (cliArgs: Args): Promise => { } } +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 { + trimLDLibraryPath() + const tryParse = async (): Promise => { try { let args = parse(process.argv.slice(2))