28 lines
1.5 KiB
JavaScript
28 lines
1.5 KiB
JavaScript
// Invoked inside a private PID namespace. Check residual processes BEFORE its
|
|
// init exits: namespace teardown would otherwise mask a missed descendant kill.
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { instrumentCleanupTimer } from './case-inner-timing-fixture.mjs';
|
|
import { blockingQuerySource, killRecordedPids, recordedPids, recordedLivePids } from './case-sudo-fixture.mjs';
|
|
|
|
const [script,dir]=process.argv.slice(2),clock=join(dir,"clock '$;literal"),records=join(dir,'pids');
|
|
try {
|
|
writeFileSync(clock,'',{mode:0o600});
|
|
const worker=join(dir,'blocked.mjs');
|
|
writeFileSync(worker,blockingQuerySource(records,'sleep')+'\nloadSystem();');
|
|
const source=instrumentCleanupTimer(readFileSync(script,'utf8'),clock);
|
|
const body=source.slice(source.indexOf('# row253-supervisor-begin'),source.indexOf('# row253-supervisor-end'));
|
|
const result=spawnSync('/bin/bash',['-c',body+'\nexec /bin/bash -c "$TESTER_SUPERVISOR" -- 2 /usr/bin/setsid /usr/bin/sleep "$@"','--',process.execPath,worker],{
|
|
encoding:'utf8',timeout:12000,killSignal:'SIGKILL',
|
|
});
|
|
// These PIDs belong to this namespace; never use them to signal host PIDs.
|
|
process.stdout.write(JSON.stringify({
|
|
status:result.status,signal:result.signal,error:result.error?.message,
|
|
stdout:result.stdout,stderr:result.stderr,pairs:recordedPids(records),
|
|
live:recordedLivePids(records),clock:readFileSync(clock,'utf8'),
|
|
}));
|
|
} finally {
|
|
killRecordedPids(records);
|
|
}
|