acquire method

Starts holding an assertion with options; throws when the helper cannot be spawned (the caller warns and continues).

Implementation

@override
Future<PowerAssertionHandle> acquire(PowerAssertionOptions options) async {
  if (_helperMissing) return _silentNoop;
  final arguments = systemdInhibitArguments(options, pid: pid);
  try {
    final process = await _launcher('systemd-inhibit', arguments);
    return ProcessPowerAssertionHandle(
      process: process,
      description: 'systemd-inhibit ${arguments.join(' ')}',
    );
  } on ProcessException catch (error) {
    // errno 2 = ENOENT: helper absent (containers, systemd-less hosts).
    if (error.errorCode != 2) rethrow;
    _helperMissing = true;
    return _silentNoop;
  }
}