Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 80f3d922d1 |
+2
-10
@@ -14,15 +14,6 @@ export function agentCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isRunnableProfileProcess(
|
|
||||||
status: string,
|
|
||||||
uid: number,
|
|
||||||
): boolean {
|
|
||||||
const owner = status.match(/^Uid:\s+(\d+)/m)?.[1];
|
|
||||||
const state = status.match(/^State:\s+(\w)/m)?.[1];
|
|
||||||
return owner !== undefined && Number(owner) === uid && state !== "Z";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function profileProcessIds(uid: number): Promise<number[]> {
|
async function profileProcessIds(uid: number): Promise<number[]> {
|
||||||
const ids: number[] = [];
|
const ids: number[] = [];
|
||||||
for await (const entry of Deno.readDir("/proc")) {
|
for await (const entry of Deno.readDir("/proc")) {
|
||||||
@@ -30,7 +21,8 @@ async function profileProcessIds(uid: number): Promise<number[]> {
|
|||||||
const status = await Deno.readTextFile(`/proc/${entry.name}/status`).catch(
|
const status = await Deno.readTextFile(`/proc/${entry.name}/status`).catch(
|
||||||
() => null,
|
() => null,
|
||||||
);
|
);
|
||||||
if (status !== null && isRunnableProfileProcess(status, uid)) {
|
const owner = status?.match(/^Uid:\s+(\d+)/m)?.[1];
|
||||||
|
if (owner !== undefined && Number(owner) === uid) {
|
||||||
ids.push(Number(entry.name));
|
ids.push(Number(entry.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-16
@@ -1,7 +1,6 @@
|
|||||||
import { assertEquals, assertRejects } from "jsr:@std/assert@1";
|
import { assertEquals, assertRejects } from "jsr:@std/assert@1";
|
||||||
import {
|
import {
|
||||||
agentCommand,
|
agentCommand,
|
||||||
isRunnableProfileProcess,
|
|
||||||
killProfileProcesses,
|
killProfileProcesses,
|
||||||
readProfileFile,
|
readProfileFile,
|
||||||
} from "./isolation.ts";
|
} from "./isolation.ts";
|
||||||
@@ -17,11 +16,6 @@ const profile = (uid: number, home: string): RuntimeProfile => ({
|
|||||||
tokenFile: null,
|
tokenFile: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("zombie process entries are already quiescent", () => {
|
|
||||||
const status = "State:\tZ (zombie)\nUid:\t20010\t20010\t20010\t20010\n";
|
|
||||||
assertEquals(isRunnableProfileProcess(status, 20_010), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "refuses to read a profile result symlink as root",
|
name: "refuses to read a profile result symlink as root",
|
||||||
permissions: { read: true, write: true, sys: ["uid"] },
|
permissions: { read: true, write: true, sys: ["uid"] },
|
||||||
@@ -87,7 +81,7 @@ Deno.test({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "cleanup leaves no runnable daemonized process",
|
name: "cleanup kills daemonized processes before returning",
|
||||||
permissions: "inherit",
|
permissions: "inherit",
|
||||||
async fn() {
|
async fn() {
|
||||||
if (Deno.uid() !== 0) return;
|
if (Deno.uid() !== 0) return;
|
||||||
@@ -101,15 +95,9 @@ Deno.test({
|
|||||||
|
|
||||||
await killProfileProcesses(selected.uid);
|
await killProfileProcesses(selected.uid);
|
||||||
|
|
||||||
const status = await Deno.readTextFile(`/proc/${pid}/status`).catch(
|
await assertRejects(
|
||||||
(error) => {
|
() => Deno.stat(`/proc/${pid}`),
|
||||||
if (error instanceof Deno.errors.NotFound) return null;
|
Deno.errors.NotFound,
|
||||||
throw error;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
status === null || !isRunnableProfileProcess(status, selected.uid),
|
|
||||||
true,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user