MCPcopy Index your code
hub / github.com/google-gemini/gemini-cli / registerCleanup

Function registerCleanup

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

Source from the content-addressed store, hash-verified

402}
403
404export function registerCleanup(
405 getProcesses,
406 getLogFileDescriptors,
407 originalSandboxSetting,
408) {
409 let cleanedUp = false;
410 const cleanup = () => {
411 if (cleanedUp) return;
412 cleanedUp = true;
413
414 console.log('\n👋 Shutting down...');
415
416 manageTelemetrySettings(false, null, null, originalSandboxSetting);
417
418 const processes = getProcesses ? getProcesses() : [];
419 processes.forEach((proc) => {
420 if (proc && proc.pid) {
421 const name = path.basename(proc.spawnfile);
422 try {
423 console.log(`🛑 Stopping ${name} (PID: ${proc.pid})...`);
424 process.kill(proc.pid, 'SIGTERM');
425 console.log(`✅ ${name} stopped.`);
426 } catch (e) {
427 if (e.code !== 'ESRCH') {
428 console.error(`Error stopping ${name}: ${e.message}`);
429 }
430 }
431 }
432 });
433
434 const logFileDescriptors = getLogFileDescriptors
435 ? getLogFileDescriptors()
436 : [];
437 logFileDescriptors.forEach((fd) => {
438 if (fd) {
439 try {
440 fs.closeSync(fd);
441 } catch {
442 /* no-op */
443 }
444 }
445 });
446 };
447
448 process.on('exit', cleanup);
449 process.on('SIGINT', () => process.exit(0));
450 process.on('SIGTERM', () => process.exit(0));
451 process.on('uncaughtException', (err) => {
452 console.error('Uncaught Exception:', err);
453 cleanup();
454 process.exit(1);
455 });
456}

Callers 7

startInteractiveUIFunction · 0.90
mainFunction · 0.90
cleanup.test.tsFile · 0.90
AppContainerFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 3

onMethod · 0.80
cleanupFunction · 0.70
errorMethod · 0.65

Tested by

no test coverage detected