Skip to content

Commit b2f676c

Browse files
authored
Fix Chrome app-server proxy inheritance on Linux (ilysenko#1121)
1 parent bdbee43 commit b2f676c

2 files changed

Lines changed: 419 additions & 6 deletions

File tree

launcher/start.sh.template

Lines changed: 165 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,169 @@ chrome_extension_host_arch() {
958958
esac
959959
}
960960

961+
write_chrome_native_host_launcher() {
962+
local cache_root="$1"
963+
local launcher_path="$cache_root/native-host"
964+
local tmp_path
965+
966+
make_path_owner_trusted "$cache_root" || return 1
967+
tmp_path="$(mktemp "$cache_root/.native-host.tmp.XXXXXX")" || return 1
968+
if ! printf '%s\n' \
969+
'#!/usr/bin/env bash' \
970+
'set -euo pipefail' \
971+
'CODEX_CHROME_NATIVE_HOST_LAUNCHER_V2=1' \
972+
'cache_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"' \
973+
'run_proxy_probe() {' \
974+
' local output_file timeout_file probe_pid watchdog_pid rc=0 self_pid' \
975+
' command -v setsid >/dev/null 2>&1 || return 1' \
976+
' [ -r /proc/self/stat ] || return 1' \
977+
' output_file="$(mktemp "${TMPDIR:-/tmp}/codex-chrome-proxy-probe.XXXXXX")" || return 1' \
978+
' timeout_file="$(mktemp "${TMPDIR:-/tmp}/codex-chrome-proxy-timeout.XXXXXX")" || {' \
979+
' rm -f -- "$output_file"' \
980+
' return 1' \
981+
' }' \
982+
' self_pid=${BASHPID:-$$}' \
983+
' setsid "$@" >"$output_file" 2>/dev/null &' \
984+
' probe_pid=$!' \
985+
' (' \
986+
' sleep 0.5' \
987+
' [ -r "/proc/$probe_pid/stat" ] || exit 0' \
988+
' local stat_line rest' \
989+
' stat_line=$(< "/proc/$probe_pid/stat") || exit 0' \
990+
' rest=${stat_line##*) }' \
991+
' set -- $rest' \
992+
' [ "${2:-}" = "$self_pid" ] || exit 0' \
993+
' printf 1 > "$timeout_file"' \
994+
' if kill -0 "$probe_pid" 2>/dev/null; then' \
995+
' kill -TERM -- "-$probe_pid" 2>/dev/null || kill -TERM "$probe_pid" 2>/dev/null || true' \
996+
' sleep 0.1' \
997+
' kill -KILL -- "-$probe_pid" 2>/dev/null || kill -KILL "$probe_pid" 2>/dev/null || true' \
998+
' fi' \
999+
' ) >/dev/null 2>&1 &' \
1000+
' watchdog_pid=$!' \
1001+
' wait "$probe_pid" || rc=$?' \
1002+
' if [ -s "$timeout_file" ]; then' \
1003+
' wait "$watchdog_pid" 2>/dev/null || true' \
1004+
' rc=124' \
1005+
' else' \
1006+
' kill "$watchdog_pid" 2>/dev/null || true' \
1007+
' wait "$watchdog_pid" 2>/dev/null || true' \
1008+
' fi' \
1009+
' if [ "$rc" -eq 0 ]; then' \
1010+
' cat "$output_file"' \
1011+
' fi' \
1012+
' rm -f -- "$output_file" "$timeout_file"' \
1013+
' return "$rc"' \
1014+
'}' \
1015+
'http_proxy_inherited=0' \
1016+
'https_proxy_inherited=0' \
1017+
'all_proxy_inherited=0' \
1018+
'no_proxy_inherited=0' \
1019+
'[ -z "${HTTP_PROXY+x}" ] && [ -z "${http_proxy+x}" ] || http_proxy_inherited=1' \
1020+
'[ -z "${HTTPS_PROXY+x}" ] && [ -z "${https_proxy+x}" ] || https_proxy_inherited=1' \
1021+
'[ -z "${ALL_PROXY+x}" ] && [ -z "${all_proxy+x}" ] || all_proxy_inherited=1' \
1022+
'[ -z "${NO_PROXY+x}" ] && [ -z "${no_proxy+x}" ] || no_proxy_inherited=1' \
1023+
'while IFS="=" read -r name value; do' \
1024+
' case "$name" in' \
1025+
' HTTP_PROXY|http_proxy) [ "$http_proxy_inherited" -eq 1 ] || export "$name=$value" ;;' \
1026+
' HTTPS_PROXY|https_proxy) [ "$https_proxy_inherited" -eq 1 ] || export "$name=$value" ;;' \
1027+
' ALL_PROXY|all_proxy) [ "$all_proxy_inherited" -eq 1 ] || export "$name=$value" ;;' \
1028+
' NO_PROXY|no_proxy) [ "$no_proxy_inherited" -eq 1 ] || export "$name=$value" ;;' \
1029+
' esac' \
1030+
'done < <(run_proxy_probe systemctl --user show-environment 2>/dev/null || true)' \
1031+
'copy_proxy_pair() {' \
1032+
' local upper_name="$1" lower_name="$2"' \
1033+
' if [ -z "${!upper_name+x}" ] && [ -n "${!lower_name+x}" ]; then' \
1034+
' export "$upper_name=${!lower_name}"' \
1035+
' elif [ -z "${!lower_name+x}" ] && [ -n "${!upper_name+x}" ]; then' \
1036+
' export "$lower_name=${!upper_name}"' \
1037+
' fi' \
1038+
'}' \
1039+
'copy_proxy_family() {' \
1040+
' local source_upper="$1" source_lower="$2" target_upper="$3" target_lower="$4" value' \
1041+
' [ -z "${!target_upper+x}" ] && [ -z "${!target_lower+x}" ] || return 0' \
1042+
' if [ -n "${!source_upper+x}" ]; then' \
1043+
' value="${!source_upper}"' \
1044+
' elif [ -n "${!source_lower+x}" ]; then' \
1045+
' value="${!source_lower}"' \
1046+
' else' \
1047+
' return 0' \
1048+
' fi' \
1049+
' export "$target_upper=$value" "$target_lower=$value"' \
1050+
'}' \
1051+
'read_gnome_proxy_value() {' \
1052+
' local schema="$1" key="$2" value' \
1053+
' value="$(run_proxy_probe gsettings get "$schema" "$key" 2>/dev/null)" || return 1' \
1054+
' value="$(printf "%s" "$value" | tr -d "\047")"' \
1055+
' printf "%s\\n" "$value"' \
1056+
'}' \
1057+
'read_gnome_proxy_ignore_hosts() {' \
1058+
' local value' \
1059+
' value="$(run_proxy_probe gsettings get org.gnome.system.proxy ignore-hosts 2>/dev/null)" || return 1' \
1060+
' value="${value#@as }"' \
1061+
' value="${value#[}"' \
1062+
' value="${value%]}"' \
1063+
' value="$(printf "%s" "$value" | tr -d "\047" | sed "s/, */,/g")"' \
1064+
' printf "%s\\n" "$value"' \
1065+
'}' \
1066+
'set_gnome_proxy_pair() {' \
1067+
' local upper_name="$1" lower_name="$2" schema="$3" scheme="$4"' \
1068+
' local host port value' \
1069+
' [ -z "${!upper_name+x}" ] && [ -z "${!lower_name+x}" ] || return 0' \
1070+
' host="$(read_gnome_proxy_value "$schema" host)" || return 0' \
1071+
' port="$(read_gnome_proxy_value "$schema" port)" || return 0' \
1072+
' [ -n "$host" ] || return 0' \
1073+
' case "$port" in ""|*[!0-9]*) return 0 ;; esac' \
1074+
' [ "$port" -ge 1 ] && [ "$port" -le 65535 ] || return 0' \
1075+
' case "$host" in \[*\]) ;; *:*) host="[$host]" ;; esac' \
1076+
' value="$scheme://$host:$port"' \
1077+
' [ "$scheme" != socks5 ] || value="$value/"' \
1078+
' export "$upper_name=$value" "$lower_name=$value"' \
1079+
'}' \
1080+
'set_gnome_no_proxy_pair() {' \
1081+
' local value' \
1082+
' [ -z "${NO_PROXY+x}" ] && [ -z "${no_proxy+x}" ] || return 0' \
1083+
' value="$(read_gnome_proxy_ignore_hosts)" || return 0' \
1084+
' [ -n "$value" ] || return 0' \
1085+
' export "NO_PROXY=$value" "no_proxy=$value"' \
1086+
'}' \
1087+
'copy_proxy_pair HTTP_PROXY http_proxy' \
1088+
'copy_proxy_pair HTTPS_PROXY https_proxy' \
1089+
'copy_proxy_pair ALL_PROXY all_proxy' \
1090+
'copy_proxy_pair NO_PROXY no_proxy' \
1091+
'gnome_proxy_mode="$(read_gnome_proxy_value org.gnome.system.proxy mode 2>/dev/null || true)"' \
1092+
'if [ "$gnome_proxy_mode" = manual ]; then' \
1093+
' set_gnome_proxy_pair HTTP_PROXY http_proxy org.gnome.system.proxy.http http' \
1094+
' gnome_use_same_proxy="$(read_gnome_proxy_value org.gnome.system.proxy use-same-proxy 2>/dev/null || true)"' \
1095+
' if [ "$gnome_use_same_proxy" = true ]; then' \
1096+
' copy_proxy_family HTTP_PROXY http_proxy HTTPS_PROXY https_proxy' \
1097+
' copy_proxy_family HTTP_PROXY http_proxy ALL_PROXY all_proxy' \
1098+
' else' \
1099+
' set_gnome_proxy_pair HTTPS_PROXY https_proxy org.gnome.system.proxy.https http' \
1100+
' set_gnome_proxy_pair ALL_PROXY all_proxy org.gnome.system.proxy.socks socks5' \
1101+
' fi' \
1102+
' set_gnome_no_proxy_pair' \
1103+
'fi' \
1104+
'case "$(uname -m)" in' \
1105+
' x86_64) extension_arch=x64 ;;' \
1106+
' aarch64|arm64) extension_arch=arm64 ;;' \
1107+
' *) exit 1 ;;' \
1108+
'esac' \
1109+
'host_path="$cache_root/latest/extension-host/linux/$extension_arch/extension-host"' \
1110+
'exec "$host_path" "$@"' > "$tmp_path"; then
1111+
rm -f -- "$tmp_path"
1112+
return 1
1113+
fi
1114+
if [ -d "$launcher_path" ] && [ ! -L "$launcher_path" ]; then
1115+
remove_tree_if_exists "$launcher_path"
1116+
fi
1117+
if ! chmod 0755 "$tmp_path" || ! mv -fT -- "$tmp_path" "$launcher_path"; then
1118+
rm -f -- "$tmp_path"
1119+
return 1
1120+
fi
1121+
printf '%s\n' "$launcher_path"
1122+
}
1123+
9611124
write_chrome_native_host_manifests() {
9621125
local host_path="$1"
9631126
local plugin_dir="$2"
@@ -1194,8 +1357,8 @@ sync_chrome_bundled_plugin_cache() {
11941357
mkdir -p "$marketplace_plugins_dir" "$marketplace_root/plugins"
11951358
replace_symlink "$cache_root/latest" "$marketplace_plugin_link"
11961359

1197-
host_path="$cache_root/latest/extension-host/linux/$extension_arch/extension-host"
1198-
[ -x "$host_path" ] || return 0
1360+
[ -x "$cache_root/latest/extension-host/linux/$extension_arch/extension-host" ] || return 0
1361+
host_path="$(write_chrome_native_host_launcher "$cache_root")" || return 0
11991362
write_chrome_native_host_manifests "$host_path" "$cache_root/latest" || \
12001363
echo "Chrome native host manifest sync failed; continuing with existing browser manifests."
12011364
}

0 commit comments

Comments
 (0)