@@ -25,6 +25,7 @@ use std::{
25
25
} ;
26
26
27
27
use bollard:: Docker ;
28
+ use lading_signal:: Broadcaster ;
28
29
use metrics:: gauge;
29
30
use nix:: {
30
31
errno:: Errno ,
@@ -221,7 +222,11 @@ impl Server {
221
222
/// # Panics
222
223
///
223
224
/// None are known.
224
- pub async fn run ( self , pid_snd : TargetPidSender ) -> Result < ( ) , Error > {
225
+ pub async fn run (
226
+ self ,
227
+ pid_snd : TargetPidSender ,
228
+ target_running : Broadcaster ,
229
+ ) -> Result < ( ) , Error > {
225
230
let config = self . config ;
226
231
227
232
// Note that each target mode has different expectations around target
@@ -230,13 +235,13 @@ impl Server {
230
235
// signalled to exit.
231
236
match config {
232
237
Config :: Pid ( config) => {
233
- Self :: watch ( config, pid_snd, self . shutdown ) . await ?;
238
+ Self :: watch ( config, pid_snd, target_running , self . shutdown ) . await ?;
234
239
}
235
240
Config :: Docker ( config) => {
236
- Self :: watch_container ( config, pid_snd, self . shutdown ) . await ?;
241
+ Self :: watch_container ( config, pid_snd, target_running , self . shutdown ) . await ?;
237
242
}
238
243
Config :: Binary ( config) => {
239
- Self :: execute_binary ( config, pid_snd, self . shutdown ) . await ?;
244
+ Self :: execute_binary ( config, pid_snd, target_running , self . shutdown ) . await ?;
240
245
}
241
246
}
242
247
@@ -248,6 +253,7 @@ impl Server {
248
253
async fn watch_container (
249
254
config : DockerConfig ,
250
255
pid_snd : TargetPidSender ,
256
+ target_running : Broadcaster ,
251
257
shutdown : lading_signal:: Watcher ,
252
258
) -> Result < ( ) , Error > {
253
259
let docker = Docker :: connect_with_socket_defaults ( ) ?;
@@ -269,6 +275,7 @@ impl Server {
269
275
pid. try_into ( ) . expect ( "cannot convert pid to 32 bit type" ) ,
270
276
) ) ?;
271
277
drop ( pid_snd) ;
278
+ target_running. signal ( ) ;
272
279
273
280
// Use PIDfd to watch the target process (linux kernel 5.3 and up)
274
281
#[ cfg( target_os = "linux" ) ]
@@ -329,6 +336,7 @@ impl Server {
329
336
async fn watch (
330
337
config : PidConfig ,
331
338
pid_snd : TargetPidSender ,
339
+ target_running : Broadcaster ,
332
340
shutdown : lading_signal:: Watcher ,
333
341
) -> Result < ( ) , Error > {
334
342
// Convert pid config value to a plain i32 (no truncation concerns;
@@ -348,6 +356,7 @@ impl Server {
348
356
349
357
pid_snd. send ( Some ( config. pid . get ( ) ) ) ?;
350
358
drop ( pid_snd) ;
359
+ target_running. signal ( ) ;
351
360
352
361
// Use PIDfd to watch the target process (linux kernel 5.3 and up)
353
362
#[ cfg( target_os = "linux" ) ]
@@ -406,6 +415,7 @@ impl Server {
406
415
async fn execute_binary (
407
416
config : BinaryConfig ,
408
417
pid_snd : TargetPidSender ,
418
+ target_running : Broadcaster ,
409
419
shutdown : lading_signal:: Watcher ,
410
420
) -> Result < ExitStatus , Error > {
411
421
let mut target_cmd = Command :: new ( config. command ) ;
@@ -424,6 +434,7 @@ impl Server {
424
434
let target_id = target_child. id ( ) . ok_or ( Error :: ProcessFinished ) ?;
425
435
pid_snd. send ( Some ( target_id) ) ?;
426
436
drop ( pid_snd) ;
437
+ target_running. signal ( ) ;
427
438
428
439
let mut interval = time:: interval ( Duration :: from_secs ( 400 ) ) ;
429
440
let shutdown_wait = shutdown. recv ( ) ;
0 commit comments