mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:57:40 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -44,7 +44,9 @@ export class GatewayLockError extends Error {
|
||||
type LockOwnerStatus = "alive" | "dead" | "unknown";
|
||||
|
||||
function isAlive(pid: number): boolean {
|
||||
if (!Number.isFinite(pid) || pid <= 0) return false;
|
||||
if (!Number.isFinite(pid) || pid <= 0) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
return true;
|
||||
@@ -66,7 +68,9 @@ function parseProcCmdline(raw: string): string[] {
|
||||
|
||||
function isGatewayArgv(args: string[]): boolean {
|
||||
const normalized = args.map(normalizeProcArg);
|
||||
if (!normalized.includes("gateway")) return false;
|
||||
if (!normalized.includes("gateway")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const entryCandidates = [
|
||||
"dist/index.mjs",
|
||||
@@ -98,7 +102,9 @@ function readLinuxStartTime(pid: number): number | null {
|
||||
try {
|
||||
const raw = fsSync.readFileSync(`/proc/${pid}/stat`, "utf8").trim();
|
||||
const closeParen = raw.lastIndexOf(")");
|
||||
if (closeParen < 0) return null;
|
||||
if (closeParen < 0) {
|
||||
return null;
|
||||
}
|
||||
const rest = raw.slice(closeParen + 1).trim();
|
||||
const fields = rest.split(/\s+/);
|
||||
const startTime = Number.parseInt(fields[19] ?? "", 10);
|
||||
@@ -113,18 +119,26 @@ function resolveGatewayOwnerStatus(
|
||||
payload: LockPayload | null,
|
||||
platform: NodeJS.Platform,
|
||||
): LockOwnerStatus {
|
||||
if (!isAlive(pid)) return "dead";
|
||||
if (platform !== "linux") return "alive";
|
||||
if (!isAlive(pid)) {
|
||||
return "dead";
|
||||
}
|
||||
if (platform !== "linux") {
|
||||
return "alive";
|
||||
}
|
||||
|
||||
const payloadStartTime = payload?.startTime;
|
||||
if (Number.isFinite(payloadStartTime)) {
|
||||
const currentStartTime = readLinuxStartTime(pid);
|
||||
if (currentStartTime == null) return "unknown";
|
||||
if (currentStartTime == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return currentStartTime === payloadStartTime ? "alive" : "dead";
|
||||
}
|
||||
|
||||
const args = readLinuxCmdline(pid);
|
||||
if (!args) return "unknown";
|
||||
if (!args) {
|
||||
return "unknown";
|
||||
}
|
||||
return isGatewayArgv(args) ? "alive" : "dead";
|
||||
}
|
||||
|
||||
@@ -132,9 +146,15 @@ async function readLockPayload(lockPath: string): Promise<LockPayload | null> {
|
||||
try {
|
||||
const raw = await fs.readFile(lockPath, "utf8");
|
||||
const parsed = JSON.parse(raw) as Partial<LockPayload>;
|
||||
if (typeof parsed.pid !== "number") return null;
|
||||
if (typeof parsed.createdAt !== "string") return null;
|
||||
if (typeof parsed.configPath !== "string") return null;
|
||||
if (typeof parsed.pid !== "number") {
|
||||
return null;
|
||||
}
|
||||
if (typeof parsed.createdAt !== "string") {
|
||||
return null;
|
||||
}
|
||||
if (typeof parsed.configPath !== "string") {
|
||||
return null;
|
||||
}
|
||||
const startTime = typeof parsed.startTime === "number" ? parsed.startTime : undefined;
|
||||
return {
|
||||
pid: parsed.pid,
|
||||
|
||||
Reference in New Issue
Block a user