MCPcopy Create free account
hub / github.com/anus-dev/ANUS / registerCleanup

Function registerCleanup

scripts/telemetry_utils.js:370–422  ·  view source on GitHub ↗
(
  getProcesses,
  getLogFileDescriptors,
  originalSandboxSetting,
)

Source from the content-addressed store, hash-verified

368}
369
370export function registerCleanup(
371 getProcesses,
372 getLogFileDescriptors,
373 originalSandboxSetting,
374) {
375 let cleanedUp = false;
376 const cleanup = () => {
377 if (cleanedUp) return;
378 cleanedUp = true;
379
380 console.log('\n👋 Shutting down...');
381
382 manageTelemetrySettings(false, null, originalSandboxSetting);
383
384 const processes = getProcesses ? getProcesses() : [];
385 processes.forEach((proc) => {
386 if (proc && proc.pid) {
387 const name = path.basename(proc.spawnfile);
388 try {
389 console.log(`🛑 Stopping ${name} (PID: ${proc.pid})...`);
390 process.kill(proc.pid, 'SIGTERM');
391 console.log(`✅ ${name} stopped.`);
392 } catch (e) {
393 if (e.code !== 'ESRCH') {
394 console.error(`Error stopping ${name}: ${e.message}`);
395 }
396 }
397 }
398 });
399
400 const logFileDescriptors = getLogFileDescriptors
401 ? getLogFileDescriptors()
402 : [];
403 logFileDescriptors.forEach((fd) => {
404 if (fd) {
405 try {
406 fs.closeSync(fd);
407 } catch (_) {
408 /* no-op */
409 }
410 }
411 });
412 };
413
414 process.on('exit', cleanup);
415 process.on('SIGINT', () => process.exit(0));
416 process.on('SIGTERM', () => process.exit(0));
417 process.on('uncaughtException', (err) => {
418 console.error('Uncaught Exception:', err);
419 cleanup();
420 process.exit(1);
421 });
422}

Callers 4

mainFunction · 0.90
AppFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 1

cleanupFunction · 0.70

Tested by

no test coverage detected