447f3f494e
经长链路排查(同机对照可工作的 Tailscale),修复 macOS 系统扩展 realize 失败(OSSystemExtensionErrorDomain code=4)与 libbox 运行时崩溃,使内嵌 sing-box 的系统扩展能在 macOS 15 上激活并启动隧道。 系统扩展 realize(三个叠加根因): - 扩展自包含:PacketTunnel 加 OTHER_LDFLAGS="" 切断对项目级 CocoaPods 链接 标志的继承(原会把 flutter_secure_storage 链进扩展);Libbox.xcframework 改纯 Link(静态),从 Embed Frameworks 移除冗余内嵌 - bundle 名 = 标识符:PRODUCT_NAME 设为 com.pangolin.pangolin.PacketTunnel - 扩展 Info.plist 补 NSSystemExtensionUsageDescription(网络扩展类别强制要求) - App Group 改 macOS 原生格式 BYL4KQHMTN.com.pangolin.pangolin;NEMachServiceName 以其为前缀;扩展补 network.client/server;get-task-allow=false + 签名加 --timestamp - CFBundleVersion 随构建递增(否则 sysextd 视为同版本不更新) libbox 运行时: - startOrReloadService(options:) 传 nil 致空指针 SIGSEGV → 传 LibboxOverrideOptions() - 默认接口监控阻塞到首个 path 更新再返回,修 "no available network interface" 配套: - scripts/local_test.sh:build/sign/notarize/copy/run 一条龙(Developer ID + 公证) - client/macos/sign_libbox.sh:构建期以 Developer ID 重签内嵌 Libbox - VpnChannel:401 自动刷新 token、详尽 os_log;auth/api 统一走 kApiBaseUrl - docs/macos-sysext-realize-troubleshooting.html:完整踩坑复盘 WIP / 临时(后续清理): - 隧道运行时仍在排查:剥离远程 rule-set 后 sing-box 启动卡点未定位 - 含临时诊断代码:main.swift stderr 重定向、box.log 输出、rule-set 剥离、debug 日志 - api_config 仍指向联调节点,发版前还原 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JEHzjEcFzvGwgbxT6Wbt6c
25 lines
993 B
Swift
25 lines
993 B
Swift
// main.swift — System Extension 入口
|
|
//
|
|
// System Extension 是可执行程序(非 appex 的 NSExtensionMain 插件),需显式 main。
|
|
// NEProvider.startSystemExtensionMode() 读 Info.plist 的 NEProviderClasses,
|
|
// 按系统请求实例化并运行 PacketTunnelProvider。dispatchMain() 保持进程常驻。
|
|
|
|
import Foundation
|
|
import NetworkExtension
|
|
|
|
// 【临时诊断】把 stderr/stdout 重定向到 App Group 容器文件,捕获 libbox(Go)的
|
|
// fatal error / panic——系统扩展默认不把 stderr 收进统一日志。诊断完移除。
|
|
if let c = FileManager.default.containerURL(
|
|
forSecurityApplicationGroupIdentifier: "BYL4KQHMTN.com.pangolin.pangolin") {
|
|
let p = c.appendingPathComponent("stderr.log").path
|
|
freopen(p, "a", stderr)
|
|
freopen(p, "a", stdout)
|
|
setvbuf(stderr, nil, _IONBF, 0)
|
|
FileHandle.standardError.write("=== boot \(Date()) ===\n".data(using: .utf8)!)
|
|
}
|
|
|
|
autoreleasepool {
|
|
NEProvider.startSystemExtensionMode()
|
|
}
|
|
dispatchMain()
|