MCPcopy Index your code
hub / github.com/compiler-explorer/compiler-explorer / asyncSetup

Function asyncSetup

lib/exec.ts:491–584  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

489 logger.info(`Initialising WINE in ${prefix}`);
490
491 const asyncSetup = async (): Promise<void> => {
492 await fs.mkdir(prefix, {recursive: true});
493
494 logger.info('Killing any pre-existing wine-server');
495 child_process.exec(`${server} -k || true`, {env: env});
496
497 // We run a long-lived cmd process, to:
498 // * test that WINE works
499 // * be something which holds open a working firejail sandbox
500 // All future WINE compiles go through the same sandbox.
501 // We wait until the process has printed out some known good text, but don't wait
502 // for it to exit (it won't, on purpose).
503
504 let wineServer: child_process.ChildProcess | undefined;
505 if (firejail) {
506 logger.info('Starting a new, firejailed, long-lived wineserver complex');
507 wineServer = child_process.spawn(
508 firejail,
509 [
510 '--quiet',
511 '--profile=' + getFirejailProfileFilePath('wine'),
512 '--private',
513 `--name=${wineSandboxName}`,
514 wine,
515 'cmd',
516 ],
517 {env: env, detached: true},
518 );
519 logger.info(`firejailed pid=${wineServer.pid}`);
520 } else {
521 logger.info(`Starting a new, long-lived wineserver complex ${server}`);
522 wineServer = child_process.spawn(wine, ['cmd'], {env: env, detached: true});
523 logger.info(`wineserver pid=${wineServer.pid}`);
524 }
525
526 wineServer.on('close', code => {
527 logger.info(`WINE server complex exited with code ${code}`);
528 });
529
530 Graceful.on('exit', () => {
531 const waitingPromises: Promise<void>[] = [];
532
533 function waitForExit(process: child_process.ChildProcess, name: string): Promise<void> {
534 return new Promise(resolve => {
535 process.on('close', () => {
536 logger.info(`Process '${name}' closed`);
537 resolve();
538 });
539 });
540 }
541
542 if (wineServer && !wineServer.killed) {
543 logger.info('Shutting down WINE server complex');
544 wineServer.kill();
545 if (wineServer.killed) {
546 waitingPromises.push(waitForExit(wineServer, 'WINE server'));
547 }
548 wineServer = undefined;

Callers 1

startWineInitFunction · 0.85

Calls 10

waitForExitFunction · 0.85
setupOnErrorFunction · 0.85
pushMethod · 0.80
toStringMethod · 0.80
errorMethod · 0.80
assertFunction · 0.70
unwrapFunction · 0.70
execMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected