Skip to content

Commit bfa858a

Browse files
committed
Trim LD_LIBRARY_PATH on startup
1 parent b881633 commit bfa858a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

ci/build/code-server.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55

66
# More complicated than readlink -f or realpath to support macOS.
77
# See https://github.com/cdr/code-server/issues/1537
8-
bin_dir() {
8+
root_dir() {
99
# We read the symlink, which may be relative from $0.
1010
dst="$(readlink "$0")"
1111
# We cd into the $0 directory.
1212
cd "$(dirname "$0")" || exit 1
13-
# Now we can cd into the dst directory.
14-
cd "$(dirname "$dst")" || exit 1
15-
# Finally we use pwd -P to print the absolute path of the directory of $dst.
13+
# Now we can cd into the directory above the dst directory which is the root
14+
# of the release.
15+
cd "$(dirname "$dst")/.." || exit 1
16+
# Finally we use pwd -P to print the absolute path the root.
1617
pwd -P || exit 1
1718
}
1819

19-
BIN_DIR=$(bin_dir)
20+
ROOT=$(root_dir)
2021
if [ "$(uname)" = "Linux" ]; then
21-
export LD_LIBRARY_PATH="$BIN_DIR/../lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}"
22+
export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH"
2223
elif [ "$(uname)" = "Darwin" ]; then
23-
export DYLD_LIBRARY_PATH="$BIN_DIR/../lib${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}"
24+
export DYLD_LIBRARY_PATH="$ROOT/lib:$DYLD_LIBRARY_PATH"
2425
fi
25-
exec "$BIN_DIR/../lib/node" "$BIN_DIR/.." "$@"
26+
exec "$ROOT/lib/node" "$ROOT" "$@"

src/node/entry.ts

+18
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,25 @@ const main = async (cliArgs: Args): Promise<void> => {
126126
}
127127
}
128128

129+
function trimLDLibraryPath(): void {
130+
let ldVar: string
131+
if (process.platform === "linux") {
132+
ldVar = "LD_LIBRARY_PATH"
133+
} else if (process.platform === "darwin") {
134+
ldVar = "DYLD_LIBRARY_PATH"
135+
} else {
136+
return
137+
}
138+
139+
// Removes the leading path added by ./ci/build/code-server.sh to use our bundled
140+
// dynamic libraries. See ci/build/build-standalone-release.sh
141+
// This is required to avoid child processes using our bundled libraries.
142+
process.env[ldVar] = process.env[ldVar]?.replace(path.dirname(process.execPath) + ":", "")
143+
}
144+
129145
async function entry(): Promise<void> {
146+
trimLDLibraryPath()
147+
130148
const tryParse = async (): Promise<Args> => {
131149
try {
132150
let args = parse(process.argv.slice(2))

0 commit comments

Comments
 (0)