mslxdff 0.1.169 → 0.1.170
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/package.json +1 -1
- package/src/daemon.js +13 -2
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { join, dirname } from "node:path";
|
|
4
4
|
import os from "node:os";
|
|
@@ -87,15 +87,26 @@ export function stopDaemon({ reason = "stop" } = {}) {
|
|
|
87
87
|
appendFileSync(logFile(), `[lifecycle] stopDaemon called by pid=${process.pid} — killing daemon pid=${pid}\n`);
|
|
88
88
|
} catch {}
|
|
89
89
|
if (victimAlive) { try { writeExitMarker(daemonDir(), { reason, prevPid: pid, prevVersion: readPidVersion(), byPid: process.pid }); } catch {} }
|
|
90
|
+
let killFailed = false;
|
|
90
91
|
try {
|
|
91
92
|
process.kill(pid, "SIGTERM");
|
|
92
93
|
} catch (err) {
|
|
93
|
-
if (err.code
|
|
94
|
+
if (err.code === "ESRCH") {
|
|
95
|
+
// process already gone — nothing to do
|
|
96
|
+
} else if (err.code === "EPERM" && process.platform === "win32") {
|
|
97
|
+
// Windows: process.kill uses TerminateProcess which requires matching elevation.
|
|
98
|
+
// Fall back to taskkill /F which can terminate processes we don't own a handle to.
|
|
99
|
+
const r = spawnSync("taskkill", ["/PID", String(pid), "/F"], { windowsHide: true });
|
|
100
|
+
if (r.error || r.status !== 0) killFailed = true;
|
|
101
|
+
} else {
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
94
104
|
}
|
|
95
105
|
try {
|
|
96
106
|
unlinkSync(pidFile());
|
|
97
107
|
} catch {
|
|
98
108
|
// already gone
|
|
99
109
|
}
|
|
110
|
+
if (killFailed) return { stopped: false, pid, reason: "EPERM — process kill denied (try running terminal as Administrator, or use restart-daemon.bat)" };
|
|
100
111
|
return { stopped: true, pid, stale: !victimAlive };
|
|
101
112
|
}
|