21 lines
1.7 KiB
JavaScript
21 lines
1.7 KiB
JavaScript
// Owned bounded child ONLY for #656 FIFO nonblocking control, not a production entry.
|
|
import fs from 'node:fs';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { getPriority, setPriority } from 'node:os';
|
|
import { revocationFixture, outcome } from './model-revocation-fixture.mjs';
|
|
const cleanup=[];let answer;
|
|
try {
|
|
const f=await revocationFixture({after:close=>cleanup.push(close)},{onRoot:root=>process.send?.({kind:'owned-root',root})});
|
|
f.seed();fs.unlinkSync(f.temporary);const made=spawnSync('/usr/bin/mkfifo',['-m','600',f.temporary],{stdio:'ignore',timeout:5000,killSignal:'SIGTERM'});
|
|
if(made.status!==0)throw Error('owned fifo setup failed');
|
|
// Fixture setup can outlive a desktop scheduler's initial process classification.
|
|
// Set the measured priority at the controlled operation boundary, after setup.
|
|
setPriority(0,19);
|
|
await new Promise((resolve,reject)=>process.send({kind:'ready',nice:getPriority(0)},error=>error?reject(error):resolve()));
|
|
const began=Date.now(),result=await outcome(async()=>{await f.prepare();f.complete();});
|
|
answer={kind:'result',ok:result.ok,code:result.code??null,cachedRevoking:f.record()?.state==='revoking',finalPresent:f.exists(f.file),tmpPresent:f.exists(f.temporary),openModelFds:f.openModelFds(),elapsedMs:Date.now()-began,nice:getPriority(0)};f.valueFree();
|
|
}catch{answer={kind:'error',code:'owned-fifo-fixture-failed'};process.exitCode=1;}
|
|
let clean=true;for(const close of [...cleanup].reverse()){try{await close();}catch{clean=false;}}
|
|
if(!clean){answer={kind:'error',code:'owned-fifo-cleanup-failed'};process.exitCode=1;}
|
|
if(process.connected){await new Promise(resolve=>process.send({...answer,ownedCleanup:clean},()=>resolve()));process.disconnect();}
|