()
| 473 | let wineInitPromise: Promise<void> | null; |
| 474 | |
| 475 | export function startWineInit() { |
| 476 | const wine = execProps<string | undefined>('wine'); |
| 477 | if (!wine) { |
| 478 | logger.info('WINE not configured'); |
| 479 | return; |
| 480 | } |
| 481 | |
| 482 | const server = execProps('wineServer'); |
| 483 | const executionType = execProps('executionType', 'none'); |
| 484 | // We need to fire up a firejail wine server even in nsjail world (for now). |
| 485 | const firejail = executionType === 'firejail' || executionType === 'nsjail' ? execProps<string>('firejail') : null; |
| 486 | const env = applyWineEnv({PATH: unwrapString(process.env.PATH)}); |
| 487 | const prefix = env.WINEPREFIX; |
| 488 | |
| 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 |
no test coverage detected