()
| 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; |
no test coverage detected