34 public async ValueTask
CheckSignals(Func<
string?, (
int, Task)> startChild, CancellationToken cancellationToken)
36 var (childPid, _) = startChild?.Invoke(
null) ??
throw new ArgumentNullException(nameof(startChild));
37 var signalTcs =
new TaskCompletionSource<Signum>();
38 async Task<Signum?> CheckSignal(Signum signum)
42 using var unixSignal =
new UnixSignal(signum);
43 if (!unixSignal.IsSet)
45 logger.LogTrace(
"Waiting for {signum}...", signum);
46 while (!unixSignal.IsSet)
47 await Task.Delay(TimeSpan.FromMilliseconds(250), cancellationToken);
49 logger.LogTrace(
"{signum} received!", signum);
52 logger.LogDebug(
"{signum} has already been sent", signum);
54 signalTcs.TrySetResult(signum);
56 catch (OperationCanceledException)
65 CheckSignal(Signum.SIGUSR1),
66 CheckSignal(Signum.SIGUSR2),
68 var completedTask = await Task.WhenAny(tasks);
69 if (cancellationToken.IsCancellationRequested)
71 await Task.WhenAll(tasks);
75 var signalReceived = await completedTask;
76 logger.LogInformation(
"Received {signalReceived}, forwarding to main TGS process!", signalReceived);
77 var result = Syscall.kill(childPid, signalReceived.Value);
80 new UnixIOException(Stdlib.GetLastError()),
81 "Failed to forward {signalReceived}!",
85 await Task.WhenAll(tasks);
86 if (cancellationToken.IsCancellationRequested)
89 var otherTask = tasks[0] == completedTask
93 signalReceived = await otherTask;
94 logger.LogInformation(
"Received {signalReceived}, forwarding to main TGS process!", signalReceived);
95 result = Syscall.kill(childPid, signalReceived.Value);
98 new UnixIOException(Stdlib.GetLastError()),
99 "Failed to forward {signalReceived}!",