Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bae0d7237 |
+10
-2
@@ -14,6 +14,15 @@ 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")) {
|
||||||
@@ -21,8 +30,7 @@ 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,
|
||||||
);
|
);
|
||||||
const owner = status?.match(/^Uid:\s+(\d+)/m)?.[1];
|
if (status !== null && isRunnableProfileProcess(status, uid)) {
|
||||||
if (owner !== undefined && Number(owner) === uid) {
|
|
||||||
ids.push(Number(entry.name));
|
ids.push(Number(entry.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-4
@@ -1,6 +1,7 @@
|
|||||||
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";
|
||||||
@@ -16,6 +17,11 @@ 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"] },
|
||||||
@@ -81,7 +87,7 @@ Deno.test({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "cleanup kills daemonized processes before returning",
|
name: "cleanup leaves no runnable daemonized process",
|
||||||
permissions: "inherit",
|
permissions: "inherit",
|
||||||
async fn() {
|
async fn() {
|
||||||
if (Deno.uid() !== 0) return;
|
if (Deno.uid() !== 0) return;
|
||||||
@@ -95,9 +101,15 @@ Deno.test({
|
|||||||
|
|
||||||
await killProfileProcesses(selected.uid);
|
await killProfileProcesses(selected.uid);
|
||||||
|
|
||||||
await assertRejects(
|
const status = await Deno.readTextFile(`/proc/${pid}/status`).catch(
|
||||||
() => Deno.stat(`/proc/${pid}`),
|
(error) => {
|
||||||
Deno.errors.NotFound,
|
if (error instanceof Deno.errors.NotFound) return null;
|
||||||
|
throw error;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
status === null || !isRunnableProfileProcess(status, selected.uid),
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user