mihomo-cli 26.10.95 → 26.10.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +1 -1
- package/dist/index.js +81 -75
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## [26.10.96] - 2026-10-01
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- **裸 `-` 一律按未知选项报错**:此前被 argv 校验豁免、取位置参数时又跳过,两头不认等于静默丢弃——`sub update -`(短横线笔误)会被当成无参形态批量更新全部订阅,`start -` 静默起默认代理,`sub add <url> -` 更会建出 remove/use 都无法指定的订阅(只剩 reset 能收拾)
|
|
10
|
+
- **pid 文件清理免提权**:文件在 runtime/ 下(用户属主目录),目录可写即可删其中任意文件、与文件属主无关——root 属主的 TUN 残留文件也直接删,不再走 sudo rm。此前零进程的 `mihomo stop` 会为一个没有进程读的无害文件弹管理员密码(取消后还警告「未能清理」,而文件随后就被免提权的 runtime 清理删掉);sudo 清理脚本被取消后也不再紧接着弹第二次密码
|
|
11
|
+
- **进程还活着时不再删 pid 文件**:sudo 清理被取消、root TUN 内核仍在路由时,pid 文件是 status/isRunning 的真相源——免提权化初版在此场景把它删掉,status 从此对活着的内核报「未运行」;现改为复核确认进程清零后才清理
|
|
12
|
+
- **legacy 迁移脚本不再删活进程的 pid**:清理旧 v3–v4 root LaunchDaemon 的脚本在 `bootout` 后无条件 `rm pid`,机器残留旧 plist(检测只看文件存在)却另有一个无关活 root TUN 时,bootout 返回 113(未装载)仍会删掉活 TUN 的 pid——之后并发 `mihomo status` 对仍在路由的内核误报「未运行」,此刻 Ctrl+C 凝固成「活 TUN + 无 pid」。脚本不再碰 pid,改为拆除成功、复核进程清零后免提权清理;有并存的活 TUN 时保留其 pid
|
|
13
|
+
- `mihomo reset` 遇 root 残留清理的 sudo 未走通(取消/非 TTY/脚本失败)时不再完全静默:进程复核已清空则继续重置,但黄字告知可能有残留未清及重试入口(26.10.95 统一后该场景的警告通道被丢弃)
|
|
14
|
+
- `mihomo stop` 收尾警告归因修正:进程在死亡等待内自行退光、而 sudo 清理脚本被取消/失败时,旧逻辑把它说成「root 属主的 pid 文件未能清理」(文件可能根本没出过问题),现按「清理未完成、进程目前已不在」归因;两类收尾错误(脚本/pid 文件)拆为独立字段,服务路径的提示同步按字段分开
|
|
15
|
+
- 残留清理报错不再把 surviving 进程一概说成「root 属主」:没进过 root 分支(用户态 SIGKILL 未能终止)时按「用户态未能终止」描述,root 断言只跟随 sudo 脚本失败出现;pid 文件清理失败的文案也不再断言「root 属主」(免提权 unlink 失败与属主无关),且「用户态残留 + pid 文件小错」不再被拦成命令失败(错误消息会是 unlink 报错、与「进程未终止」的提示自相矛盾),归外层残留处置
|
|
16
|
+
- pid 文件清理失败的警告不再连打两遍(clearPid 内部遗留的 console.warn 与调用方警告叠加);sudo 失败短语全仓统一为 describeSudoFailure(非鉴权错误保留原始消息——非交互环境的具体原因不再被「sudo 执行失败」笼统盖掉),pid 文件短语统一 describePidCleanupFailure
|
|
17
|
+
- 空环境裸 `mihomo sub remove`(未给名称)改报「没有订阅」,与带名称形态及 use/update 同口径(旧报「请指定名称」并引导补一个不存在的参数)
|
|
18
|
+
- 混合属主时 root 残留清理的预告只列 root 属主的 PID:用户态游离内核混在其中时,旧消息把全部 PID 都标成「root 属主的内核残留」,与实际属主不符
|
|
19
|
+
|
|
20
|
+
### 内部
|
|
21
|
+
|
|
22
|
+
- root 残留清理脚本 buildKernelCleanupScript 不再 `rm pid`:cleanupAll 路径的 pid 删除统一在末尾、复核 remaining 为空才免提权 unlink,消除该路径「活进程不删 isRunning 真相源」在提权脚本内的字面例外(此前仅靠「sudo 取消脚本不执行 + pkill 失败 exit 2」两道时序间接保证;legacy 迁移脚本 buildLegacyCleanupScript 的同款 `rm pid` 也已收口,见上方修复段);buildRootResidueCleanupError 在 scriptError 与 pidError 并存时改为 scriptError 优先(主归因「清理未走完」、pid 错误仅附带,手动命令给 pkill 而非 rm,防漏掉潜在存活进程);reset 的警告理由去掉 `as Error` 断言、改显式空值守卫;补「脚本不得含 rm」的结构断言、只读文件免提权删除与双错误并存象限用例
|
|
23
|
+
- `CleanupResult.sudoError` 拆为 `scriptError`(pkill 脚本)与 `pidError`(pid 文件删除)两个字段:进程死光但脚本没走完与仅 pid 文件残留是两种归因,合并字段让调用方提示说错事;处置判据 classifyResidueCleanup 同步(throw 档只看 scriptError,pidError 不参与拦截),reset 的警告判据也收口到它
|
|
24
|
+
- `StaleState` 删除无消费方的 `needsSudo`/`hasRootPidFile`/`hasRootProcess` 字段;`clearPid` 的三态返回值(cancelled/failed/null)随免提权化收敛为 `Error | null`
|
|
25
|
+
- 覆写数组拼接误用的「值类型描述」抽为 describeValueKind:文件级(系统默认值)与合并级(订阅现值)两处检查共用,消除已漂移的双实现
|
|
26
|
+
- 测试注释清理:三处历史叙事(引入版本、旧实现去向)改为只留判据,历史留在 CHANGELOG/git
|
|
27
|
+
|
|
3
28
|
## [26.10.95] - 2026-10-01
|
|
4
29
|
|
|
5
30
|
### 修复
|
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ mihomo ui yacd # YACD
|
|
|
127
127
|
| ----------------------------- | -------------------------------------- |
|
|
128
128
|
| `mihomo sub` | 列出所有订阅(含流量、到期时间) |
|
|
129
129
|
| `mihomo sub use <name>` | 切换当前订阅(支持模糊匹配,自动重启;重启透传 `-s`/`-u` 等启动选项) |
|
|
130
|
-
| `mihomo sub add [url] [name]` |
|
|
130
|
+
| `mihomo sub add [url] [name]` | 添加订阅并自动切换(名称不可重复、不能以 `-` 开头;交互下不带 URL 时自动读剪贴板并确认) |
|
|
131
131
|
| `mihomo sub update` | 更新所有订阅 |
|
|
132
132
|
| `mihomo sub update <name>` | 更新指定订阅(支持模糊匹配) |
|
|
133
133
|
| `mihomo sub remove <name>` | 删除订阅(别名 `rm`/`delete`;精确名直接删,模糊匹配需确认,`-y` 跳过) |
|
package/dist/index.js
CHANGED
|
@@ -271,7 +271,7 @@ function assertKnownFlags(args, known, command) {
|
|
|
271
271
|
if (!args) return;
|
|
272
272
|
const knownSet = new Set(known);
|
|
273
273
|
for (const a of args) {
|
|
274
|
-
if (!a.startsWith("-")
|
|
274
|
+
if (!a.startsWith("-")) continue;
|
|
275
275
|
if (knownSet.has(a)) continue;
|
|
276
276
|
const match = matchValueFlagToken(a);
|
|
277
277
|
if (match && match.form !== "exact" && knownSet.has(match.baseForm)) continue;
|
|
@@ -3964,6 +3964,11 @@ function assertValidParsedKey(rawKey, parsed) {
|
|
|
3964
3964
|
});
|
|
3965
3965
|
}
|
|
3966
3966
|
}
|
|
3967
|
+
function describeValueKind(value) {
|
|
3968
|
+
if (value === null) return "null";
|
|
3969
|
+
if (typeof value === "object") return "\u6620\u5C04";
|
|
3970
|
+
return `\u6807\u91CF\uFF08${typeof value}\uFF09`;
|
|
3971
|
+
}
|
|
3967
3972
|
function mergeConfigLevel(target, override, parseOperators) {
|
|
3968
3973
|
let t = target;
|
|
3969
3974
|
if (t === null || t === void 0) {
|
|
@@ -3997,13 +4002,10 @@ function mergeConfigLevel(target, override, parseOperators) {
|
|
|
3997
4002
|
const existingValue = result[key];
|
|
3998
4003
|
if (arrayPrepend || arrayAppend) {
|
|
3999
4004
|
if (existingValue !== void 0 && !Array.isArray(existingValue)) {
|
|
4000
|
-
throw new CliError(
|
|
4001
|
-
|
|
4002
|
-
{
|
|
4003
|
-
|
|
4004
|
-
hint: [`+${key} / ${key}+ \u7528\u4E8E\u5411\u6570\u7EC4\u524D\u7F6E/\u8FFD\u52A0\u5143\u7D20\uFF08\u5982 rules+\uFF09\u3002`, `\u82E5\u8981\u66FF\u6362\u975E\u6570\u7EC4\u7684 ${key}\uFF0C\u8BF7\u76F4\u63A5\u5199 ${key}: <\u503C>\u3002`]
|
|
4005
|
-
}
|
|
4006
|
-
);
|
|
4005
|
+
throw new CliError(`\u8986\u5199\u952E "${rawKey}" \u7684\u6570\u7EC4\u62FC\u63A5\u8BED\u4E49\u53EA\u9002\u7528\u4E8E\u6570\u7EC4\uFF0C\u4F46 "${key}" \u5F53\u524D\u662F ${describeValueKind(existingValue)}`, {
|
|
4006
|
+
label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
|
|
4007
|
+
hint: [`+${key} / ${key}+ \u7528\u4E8E\u5411\u6570\u7EC4\u524D\u7F6E/\u8FFD\u52A0\u5143\u7D20\uFF08\u5982 rules+\uFF09\u3002`, `\u82E5\u8981\u66FF\u6362\u975E\u6570\u7EC4\u7684 ${key}\uFF0C\u8BF7\u76F4\u63A5\u5199 ${key}: <\u503C>\u3002`]
|
|
4008
|
+
});
|
|
4007
4009
|
}
|
|
4008
4010
|
const existingArr = Array.isArray(existingValue) ? existingValue : [];
|
|
4009
4011
|
const overrideArr = Array.isArray(value) ? value : [value];
|
|
@@ -4215,8 +4217,7 @@ function assertFileLevelOperatorRules(config, fileName) {
|
|
|
4215
4217
|
if (!parsed.arrayPrepend && !parsed.arrayAppend) continue;
|
|
4216
4218
|
const base = BASE_CONFIG[parsed.key];
|
|
4217
4219
|
if (base === void 0 || Array.isArray(base)) continue;
|
|
4218
|
-
|
|
4219
|
-
throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684\u952E "${rawKey}" \u7528\u4E86\u6570\u7EC4\u62FC\u63A5\uFF0C\u4F46\u7CFB\u7EDF\u914D\u7F6E "${parsed.key}" \u7684\u9ED8\u8BA4\u503C\u662F${kind}\u3001\u4E0D\u662F\u6570\u7EC4`, {
|
|
4220
|
+
throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684\u952E "${rawKey}" \u7528\u4E86\u6570\u7EC4\u62FC\u63A5\uFF0C\u4F46\u7CFB\u7EDF\u914D\u7F6E "${parsed.key}" \u7684\u9ED8\u8BA4\u503C\u662F ${describeValueKind(base)}\u3001\u4E0D\u662F\u6570\u7EC4`, {
|
|
4220
4221
|
label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
|
|
4221
4222
|
hint: [
|
|
4222
4223
|
`+${parsed.key} / ${parsed.key}+ \u7528\u4E8E\u5411\u6570\u7EC4\u524D\u7F6E/\u8FFD\u52A0\u5143\u7D20\uFF08\u5982 rules+\uFF09\uFF1B\u7CFB\u7EDF\u9ED8\u8BA4\u7684 ${parsed.key} \u4E0D\u662F\u6570\u7EC4\uFF0C\u62FC\u63A5\u53EA\u4F1A\u4EA7\u51FA\u5185\u6838\u65E0\u6CD5\u89E3\u6790\u7684\u914D\u7F6E\u3002`,
|
|
@@ -5001,14 +5002,9 @@ function isPidFileOwnedByRoot() {
|
|
|
5001
5002
|
}
|
|
5002
5003
|
function checkStaleState() {
|
|
5003
5004
|
const allPids = getMihomoPids();
|
|
5004
|
-
const hasRootProcess = allPids.some((p) => isProcessRoot(p));
|
|
5005
|
-
const hasRootPidFile = isPidFileOwnedByRoot();
|
|
5006
5005
|
return {
|
|
5007
|
-
needsCleanup: allPids.length > 0 ||
|
|
5008
|
-
allPids
|
|
5009
|
-
hasRootProcess,
|
|
5010
|
-
hasRootPidFile,
|
|
5011
|
-
needsSudo: hasRootProcess || hasRootPidFile
|
|
5006
|
+
needsCleanup: allPids.length > 0 || isPidFileOwnedByRoot(),
|
|
5007
|
+
allPids
|
|
5012
5008
|
};
|
|
5013
5009
|
}
|
|
5014
5010
|
function getProcessInfo(pid) {
|
|
@@ -5048,6 +5044,9 @@ var SudoAuthError = class extends Error {
|
|
|
5048
5044
|
this.name = "SudoAuthError";
|
|
5049
5045
|
}
|
|
5050
5046
|
};
|
|
5047
|
+
function describeSudoFailure(e) {
|
|
5048
|
+
return e instanceof SudoAuthError ? "sudo \u5DF2\u53D6\u6D88\u6216\u5BC6\u7801\u9519\u8BEF" : e.message;
|
|
5049
|
+
}
|
|
5051
5050
|
function sudoExitToError(action, status, codeMessages) {
|
|
5052
5051
|
if (status === 1) return new SudoAuthError();
|
|
5053
5052
|
if (status == null) return new Error(`${action}\u88AB\u4E2D\u65AD\uFF08sudo \u8FDB\u7A0B\u88AB\u4FE1\u53F7\u7EC8\u6B62\uFF09`);
|
|
@@ -5089,33 +5088,32 @@ function clearRuntime() {
|
|
|
5089
5088
|
}
|
|
5090
5089
|
ensureDirs();
|
|
5091
5090
|
}
|
|
5092
|
-
function
|
|
5093
|
-
|
|
5094
|
-
const cancelled = outcome === "cancelled" || outcome instanceof SudoAuthError;
|
|
5095
|
-
const reason = cancelled ? "sudo \u53D6\u6D88\u6216\u5BC6\u7801\u9519\u8BEF" : "sudo \u6267\u884C\u5931\u8D25";
|
|
5096
|
-
console.warn(colors.yellow(`\u8B66\u544A: root \u5C5E\u4E3B\u7684 pid \u6587\u4EF6\u672A\u80FD\u6E05\u7406\uFF08${reason}\uFF09\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5`));
|
|
5091
|
+
function describePidCleanupFailure(err) {
|
|
5092
|
+
return `pid \u6587\u4EF6\u672A\u80FD\u6E05\u7406\uFF08${err.message}\uFF09`;
|
|
5097
5093
|
}
|
|
5098
|
-
function
|
|
5099
|
-
if (
|
|
5100
|
-
|
|
5101
|
-
return null;
|
|
5094
|
+
function warnPidCleanupFailed(err) {
|
|
5095
|
+
if (!err) return;
|
|
5096
|
+
console.warn(colors.yellow(`\u8B66\u544A: ${describePidCleanupFailure(err)}\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5`));
|
|
5102
5097
|
}
|
|
5103
5098
|
function clearPid() {
|
|
5104
|
-
if (!fs8.existsSync(PATHS.pidFile)) return null;
|
|
5105
|
-
if (isPidFileOwnedByRoot()) {
|
|
5106
|
-
const result = spawnSync4("sudo", ["rm", "-f", PATHS.pidFile], { stdio: "inherit", timeout: SUDO_TIMEOUT_MS });
|
|
5107
|
-
if (result.status === 1) return "cancelled";
|
|
5108
|
-
if (result.error || result.status !== 0) {
|
|
5109
|
-
console.warn("\u8B66\u544A: root \u5C5E\u4E3B\u7684 pid \u6587\u4EF6\u672A\u80FD\u6E05\u7406\uFF08sudo \u5931\u8D25\u6216\u5DF2\u53D6\u6D88\uFF09\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5");
|
|
5110
|
-
return "failed";
|
|
5111
|
-
}
|
|
5112
|
-
return null;
|
|
5113
|
-
}
|
|
5114
5099
|
try {
|
|
5115
5100
|
fs8.unlinkSync(PATHS.pidFile);
|
|
5116
|
-
|
|
5101
|
+
return null;
|
|
5102
|
+
} catch (e) {
|
|
5103
|
+
if (e.code === "ENOENT") return null;
|
|
5104
|
+
return e;
|
|
5117
5105
|
}
|
|
5118
|
-
|
|
5106
|
+
}
|
|
5107
|
+
async function waitUntilNoMihomo(attempts = PROCESS_WAIT_ATTEMPTS, interval = PROCESS_WAIT_INTERVAL) {
|
|
5108
|
+
for (let i = 0; i < attempts; i++) {
|
|
5109
|
+
if (getMihomoPids().length === 0) return;
|
|
5110
|
+
await sleep(interval);
|
|
5111
|
+
}
|
|
5112
|
+
}
|
|
5113
|
+
async function reapPidWhenQuiet() {
|
|
5114
|
+
await waitUntilNoMihomo();
|
|
5115
|
+
if (getMihomoPids().length > 0) return null;
|
|
5116
|
+
return clearPid();
|
|
5119
5117
|
}
|
|
5120
5118
|
function killProcess(pid) {
|
|
5121
5119
|
try {
|
|
@@ -5141,7 +5139,6 @@ function buildKernelCleanupScript() {
|
|
|
5141
5139
|
`pkill -9 -f ${shellQuote(MAIN_INSTANCE_PATTERN)} 2>/dev/null`,
|
|
5142
5140
|
"rc=$?",
|
|
5143
5141
|
"[ $rc -le 1 ] || exit 2",
|
|
5144
|
-
`rm -f ${shellQuote(PATHS.pidFile)} 2>/dev/null || true`,
|
|
5145
5142
|
"exit 0",
|
|
5146
5143
|
""
|
|
5147
5144
|
].join("\n");
|
|
@@ -5149,13 +5146,14 @@ function buildKernelCleanupScript() {
|
|
|
5149
5146
|
async function cleanupAll() {
|
|
5150
5147
|
const pids = getMihomoPids();
|
|
5151
5148
|
if (pids.length === 0) {
|
|
5152
|
-
return { killed: 0, failed: 0, remaining: [],
|
|
5149
|
+
return { killed: 0, failed: 0, remaining: [], scriptError: null, pidError: clearPid() };
|
|
5153
5150
|
}
|
|
5154
5151
|
let killedCount = 0;
|
|
5155
5152
|
const failedPids = [];
|
|
5156
|
-
let
|
|
5157
|
-
|
|
5158
|
-
|
|
5153
|
+
let scriptError = null;
|
|
5154
|
+
const rootPids = pids.filter(isProcessRoot);
|
|
5155
|
+
if (rootPids.length > 0) {
|
|
5156
|
+
console.log(`\u68C0\u6D4B\u5230 root \u5C5E\u4E3B\u7684\u5185\u6838\u6B8B\u7559\uFF08PID ${rootPids.join(", ")}\uFF09\uFF0C\u6E05\u7406\u9700\u8981\u4E00\u6B21\u7BA1\u7406\u5458\u5BC6\u7801`);
|
|
5159
5157
|
try {
|
|
5160
5158
|
runSudoScript(buildKernelCleanupScript(), {
|
|
5161
5159
|
action: "\u6E05\u7406\u6B8B\u7559\u8FDB\u7A0B",
|
|
@@ -5164,7 +5162,7 @@ async function cleanupAll() {
|
|
|
5164
5162
|
});
|
|
5165
5163
|
killedCount = pids.length;
|
|
5166
5164
|
} catch (e) {
|
|
5167
|
-
|
|
5165
|
+
scriptError = e;
|
|
5168
5166
|
}
|
|
5169
5167
|
} else if (pids.length > BATCH_KILL_THRESHOLD) {
|
|
5170
5168
|
if (killAllMihomo()) {
|
|
@@ -5185,13 +5183,10 @@ async function cleanupAll() {
|
|
|
5185
5183
|
}
|
|
5186
5184
|
}
|
|
5187
5185
|
}
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
}
|
|
5192
|
-
const pidError = pidCleanupError(clearPid());
|
|
5193
|
-
if (!sudoError) sudoError = pidError;
|
|
5194
|
-
return { killed: killedCount, failed: failedPids.length, remaining: getMihomoPids(), sudoError };
|
|
5186
|
+
await waitUntilNoMihomo();
|
|
5187
|
+
const remaining = getMihomoPids();
|
|
5188
|
+
const pidError = remaining.length === 0 ? clearPid() : null;
|
|
5189
|
+
return { killed: killedCount, failed: failedPids.length, remaining, scriptError, pidError };
|
|
5195
5190
|
}
|
|
5196
5191
|
async function stop() {
|
|
5197
5192
|
const allPids = getMihomoPids();
|
|
@@ -5201,8 +5196,11 @@ async function stop() {
|
|
|
5201
5196
|
return { success: true, notRunning: true };
|
|
5202
5197
|
}
|
|
5203
5198
|
const result = await cleanupAll();
|
|
5204
|
-
if (result.remaining.length === 0
|
|
5205
|
-
warnPidCleanupFailed(result.
|
|
5199
|
+
if (result.remaining.length === 0) {
|
|
5200
|
+
warnPidCleanupFailed(result.pidError);
|
|
5201
|
+
if (result.scriptError) {
|
|
5202
|
+
console.warn(colors.yellow(`\u8B66\u544A: root \u6B8B\u7559\u6E05\u7406\u672A\u5B8C\u6210\uFF08${describeSudoFailure(result.scriptError)}\uFF09\uFF0C\u8FDB\u7A0B\u76EE\u524D\u5DF2\u4E0D\u5728\uFF1B\u518D\u53D1\u73B0\u6B8B\u7559\u53EF\u91CD\u8BD5 mihomo stop`));
|
|
5203
|
+
}
|
|
5206
5204
|
}
|
|
5207
5205
|
const remaining = getMihomoPids();
|
|
5208
5206
|
if (remaining.length > 0) {
|
|
@@ -5444,23 +5442,21 @@ async function waitUntilUnloaded(target = serviceTarget()) {
|
|
|
5444
5442
|
});
|
|
5445
5443
|
}
|
|
5446
5444
|
function buildRootResidueCleanupError(result, ctx) {
|
|
5447
|
-
const
|
|
5445
|
+
const { scriptError, pidError } = result;
|
|
5446
|
+
const cancelled = scriptError instanceof SudoAuthError;
|
|
5448
5447
|
const hasKernelResidue = result.remaining.length > 0;
|
|
5449
|
-
const
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
];
|
|
5454
|
-
hint.push(hasKernelResidue ? "\u624B\u52A8\u6E05\u7406: sudo pkill -9 mihomo" : `\u624B\u52A8\u6E05\u7406: sudo rm -f ${PATHS.pidFile}`);
|
|
5448
|
+
const pidList = `PID ${result.remaining.join(", ")}`;
|
|
5449
|
+
const residueHint = hasKernelResidue ? scriptError ? `root \u6B8B\u7559\u5185\u6838\u4ECD\u5728\u8FD0\u884C\uFF08${pidList}\uFF09\uFF0C\u53EF\u80FD\u7EE7\u7EED\u5360\u7528\u4EE3\u7406\u7AEF\u53E3` : `\u6B8B\u7559\u5185\u6838\u4ECD\u5728\u8FD0\u884C\uFF08${pidList}\uFF09\u2014\u2014\u7528\u6237\u6001\u672A\u80FD\u7EC8\u6B62\uFF0C\u4E0E\u63D0\u6743\u65E0\u5173` : scriptError ? `root \u6B8B\u7559\u6E05\u7406\u672A\u5B8C\u6210\uFF0C\u8FDB\u7A0B\u76EE\u524D\u5DF2\u4E0D\u5728\uFF08\u6B7B\u4EA1\u7B49\u5F85\u5185\u81EA\u884C\u9000\u51FA\uFF0C\u975E sudo \u6E05\u7406\uFF09${pidError ? `\uFF1B${describePidCleanupFailure(pidError)}` : ""}` : pidError ? `${describePidCleanupFailure(pidError)}: ${PATHS.pidFile}` : "root \u6B8B\u7559\u672A\u6E05\u7406\u5E72\u51C0";
|
|
5450
|
+
const hint = [ctx.mainOutcome, residueHint, `\u91CD\u65B0\u8FD0\u884C\u53EF\u518D\u6B21\u5C1D\u8BD5\u6E05\u7406: ${ctx.retryCommand}`];
|
|
5451
|
+
hint.push(hasKernelResidue || scriptError ? "\u624B\u52A8\u6E05\u7406: sudo pkill -9 mihomo" : `\u624B\u52A8\u6E05\u7406: sudo rm -f ${PATHS.pidFile}`);
|
|
5455
5452
|
if (cancelled) {
|
|
5456
5453
|
return new CliError("\u7BA1\u7406\u5458\u5BC6\u7801\u672A\u8F93\u5165\u6216\u6709\u8BEF\uFF0Croot \u6B8B\u7559\u672A\u88AB\u6E05\u7406", { label: "\u5DF2\u53D6\u6D88", hint });
|
|
5457
5454
|
}
|
|
5458
|
-
return new CliError(
|
|
5455
|
+
return new CliError(scriptError?.message ?? pidError?.message ?? "root \u6B8B\u7559\u672A\u6E05\u7406\u5E72\u51C0", { label: "\u6E05\u7406\u6B8B\u7559\u8FDB\u7A0B\u5931\u8D25", hint });
|
|
5459
5456
|
}
|
|
5460
5457
|
function classifyResidueCleanup(result) {
|
|
5461
|
-
if (result.remaining.length > 0
|
|
5462
|
-
|
|
5463
|
-
return "ok";
|
|
5458
|
+
if (result.remaining.length > 0) return result.scriptError !== null ? "throw" : "ok";
|
|
5459
|
+
return result.scriptError !== null || result.pidError !== null ? "warn" : "ok";
|
|
5464
5460
|
}
|
|
5465
5461
|
async function cleanupKernelsOrThrow(ctx) {
|
|
5466
5462
|
const result = await cleanupAll();
|
|
@@ -5626,7 +5622,6 @@ function buildLegacyCleanupScript() {
|
|
|
5626
5622
|
`rm -f ${shellQuote(PATHS.systemDaemonPlist)}`,
|
|
5627
5623
|
`chown "$SUDO_UID:$SUDO_GID" ${shellQuote(PATHS.logFile)} 2>/dev/null || true`,
|
|
5628
5624
|
`chown -R "$SUDO_UID:$SUDO_GID" ${shellQuote(DIRS.data)} 2>/dev/null || true`,
|
|
5629
|
-
`rm -f ${shellQuote(PATHS.pidFile)}`,
|
|
5630
5625
|
"exit 0",
|
|
5631
5626
|
""
|
|
5632
5627
|
].join("\n");
|
|
@@ -5641,7 +5636,7 @@ function cleanupLegacySystemInstall() {
|
|
|
5641
5636
|
codeMessages: { 3: "launchctl bootout \u672A\u80FD\u5378\u8F7D\u65E7 daemon\uFF08\u8BE6\u89C1\u4E0A\u65B9\u8F93\u51FA\uFF09" }
|
|
5642
5637
|
});
|
|
5643
5638
|
}
|
|
5644
|
-
function cleanupLegacyInstallOrThrow() {
|
|
5639
|
+
async function cleanupLegacyInstallOrThrow() {
|
|
5645
5640
|
try {
|
|
5646
5641
|
cleanupLegacySystemInstall();
|
|
5647
5642
|
} catch (e) {
|
|
@@ -5651,6 +5646,10 @@ function cleanupLegacyInstallOrThrow() {
|
|
|
5651
5646
|
hint: ["\u4E5F\u53EF\u624B\u52A8\u6E05\u7406:", ` sudo launchctl bootout system/$(basename ${PATHS.systemDaemonPlist} .plist)`, ` sudo rm -f ${PATHS.systemDaemonPlist}`]
|
|
5652
5647
|
});
|
|
5653
5648
|
}
|
|
5649
|
+
const pidError = await reapPidWhenQuiet();
|
|
5650
|
+
if (pidError) {
|
|
5651
|
+
console.warn(colors.yellow(`\u8B66\u544A: ${describePidCleanupFailure(pidError)}\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5`));
|
|
5652
|
+
}
|
|
5654
5653
|
}
|
|
5655
5654
|
function logOversized() {
|
|
5656
5655
|
try {
|
|
@@ -7001,7 +7000,7 @@ async function cmdStart(args) {
|
|
|
7001
7000
|
if (detectLegacySystemInstall()) {
|
|
7002
7001
|
console.log(colors.yellow("\u68C0\u6D4B\u5230\u65E7\u7248\u672C\u5B89\u88C5\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1\uFF08root LaunchDaemon\uFF09\uFF0C\u542F\u52A8 TUN \u524D\u9700\u6E05\u7406"));
|
|
7003
7002
|
console.log(colors.gray(" \u6E05\u7406\u9700\u8981\u4E00\u6B21\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u5220\u9664 root \u62E5\u6709\u7684\u6587\u4EF6\uFF09"));
|
|
7004
|
-
cleanupLegacyInstallOrThrow();
|
|
7003
|
+
await cleanupLegacyInstallOrThrow();
|
|
7005
7004
|
console.log(colors.green("\u5DF2\u6E05\u7406\u9057\u7559\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1"));
|
|
7006
7005
|
console.log("");
|
|
7007
7006
|
}
|
|
@@ -8330,7 +8329,7 @@ async function cmdReset(args) {
|
|
|
8330
8329
|
console.log("\u5DF2\u53D6\u6D88");
|
|
8331
8330
|
return;
|
|
8332
8331
|
}
|
|
8333
|
-
if ((needsStop || serviceTargeted) && legacy) cleanupLegacyInstallOrThrow();
|
|
8332
|
+
if ((needsStop || serviceTargeted) && legacy) await cleanupLegacyInstallOrThrow();
|
|
8334
8333
|
if (serviceActive) {
|
|
8335
8334
|
if (serviceTargeted) await uninstallService();
|
|
8336
8335
|
else if (needsStop) await stopService();
|
|
@@ -8343,6 +8342,13 @@ async function cmdReset(args) {
|
|
|
8343
8342
|
hint: ["\u8BF7\u624B\u52A8\u8FD0\u884C: sudo pkill -9 mihomo"]
|
|
8344
8343
|
});
|
|
8345
8344
|
}
|
|
8345
|
+
if (classifyResidueCleanup(cleanup) === "warn") {
|
|
8346
|
+
const reason = cleanup.scriptError ? `root \u6B8B\u7559\u6E05\u7406\u672A\u5B8C\u6210\uFF08${describeSudoFailure(cleanup.scriptError)}\uFF09\uFF0C\u53EF\u80FD\u4ECD\u6709\u6B8B\u7559\u8FDB\u7A0B` : cleanup.pidError ? describePidCleanupFailure(cleanup.pidError) : null;
|
|
8347
|
+
if (reason) {
|
|
8348
|
+
console.warn(colors.yellow(`\u8B66\u544A: ${reason}`));
|
|
8349
|
+
console.warn(colors.gray("\u91CD\u8BD5\u6E05\u7406: mihomo stop"));
|
|
8350
|
+
}
|
|
8351
|
+
}
|
|
8346
8352
|
recordServiceStopped();
|
|
8347
8353
|
}
|
|
8348
8354
|
const deleted = /* @__PURE__ */ new Set();
|
|
@@ -8394,7 +8400,7 @@ async function handleLegacyInstall() {
|
|
|
8394
8400
|
console.log(colors.gray(" \u5B83\u4F1A\u4E0E\u65B0\u7684\u7528\u6237\u7EA7\u670D\u52A1\u62A2\u5360\u540C\u4E00\u7EC4\u7AEF\u53E3\uFF0C\u9700\u5148\u6E05\u7406"));
|
|
8395
8401
|
console.log(colors.gray(" \u6E05\u7406\u9700\u8981\u4E00\u6B21\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u5220\u9664 root \u62E5\u6709\u7684\u6587\u4EF6\uFF09"));
|
|
8396
8402
|
console.log("");
|
|
8397
|
-
cleanupLegacyInstallOrThrow();
|
|
8403
|
+
await cleanupLegacyInstallOrThrow();
|
|
8398
8404
|
console.log(`${colors.green("\u5DF2\u6E05\u7406\u9057\u7559\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1")}`);
|
|
8399
8405
|
console.log("");
|
|
8400
8406
|
}
|
|
@@ -8464,7 +8470,7 @@ async function cmdUninstall(args) {
|
|
|
8464
8470
|
}
|
|
8465
8471
|
if (legacy) {
|
|
8466
8472
|
console.log(colors.gray("\u68C0\u6D4B\u5230\u65E7\u7248\u672C\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1\uFF0C\u6E05\u7406\u9700\u8981\u4E00\u6B21\u7BA1\u7406\u5458\u5BC6\u7801"));
|
|
8467
|
-
cleanupLegacyInstallOrThrow();
|
|
8473
|
+
await cleanupLegacyInstallOrThrow();
|
|
8468
8474
|
console.log(colors.green("\u5DF2\u6E05\u7406\u9057\u7559\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1"));
|
|
8469
8475
|
}
|
|
8470
8476
|
const remaining = getMihomoPids();
|
|
@@ -8492,7 +8498,7 @@ async function cmdStop(args) {
|
|
|
8492
8498
|
if (detectLegacySystemInstall()) {
|
|
8493
8499
|
console.log(colors.yellow("\u68C0\u6D4B\u5230\u65E7\u7248\u672C\u5B89\u88C5\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1\uFF08root LaunchDaemon\uFF09\uFF0C\u505C\u6B62\u524D\u9700\u6E05\u7406"));
|
|
8494
8500
|
console.log(colors.gray(" \u6E05\u7406\u9700\u8981\u4E00\u6B21\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u5220\u9664 root \u62E5\u6709\u7684\u6587\u4EF6\uFF09"));
|
|
8495
|
-
cleanupLegacyInstallOrThrow();
|
|
8501
|
+
await cleanupLegacyInstallOrThrow();
|
|
8496
8502
|
console.log(colors.green("\u5DF2\u6E05\u7406\u9057\u7559\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1"));
|
|
8497
8503
|
console.log("");
|
|
8498
8504
|
}
|
|
@@ -8708,14 +8714,14 @@ async function subRemove(args) {
|
|
|
8708
8714
|
assertPositionalCount(args, 1, 2, "mihomo sub remove <name>");
|
|
8709
8715
|
const name = getNonFlagArg(args, 2);
|
|
8710
8716
|
const subs = getSubscriptions();
|
|
8717
|
+
if (subs.length === 0) {
|
|
8718
|
+
throw new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "mihomo sub add <url> [name]" });
|
|
8719
|
+
}
|
|
8711
8720
|
if (!name) {
|
|
8712
8721
|
throw new CliError("\u8BF7\u6307\u5B9A\u8981\u5220\u9664\u7684\u8BA2\u9605\u540D\u79F0", {
|
|
8713
|
-
hint:
|
|
8722
|
+
hint: ["", "\u53EF\u7528\u8BA2\u9605:", ...subs.map((s) => ` ${s.name}`)]
|
|
8714
8723
|
});
|
|
8715
8724
|
}
|
|
8716
|
-
if (subs.length === 0) {
|
|
8717
|
-
throw new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "mihomo sub add <url> [name]" });
|
|
8718
|
-
}
|
|
8719
8725
|
const target = resolveSubscription(subs, name);
|
|
8720
8726
|
const isExact = target.name === name;
|
|
8721
8727
|
const skipConfirm = hasFlag(args, "-y", "--yes");
|