blackship 0.6.1

A FreeBSD jail manager with state machine control
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
//! The Warden - Jail Supervisor
//!
//! Monitors jails and implements one-for-one restart strategy:
//! - Watches for kernel jail removal events via kqueue (FreeBSD 16+)
//! - Falls back to event-driven mpsc channel on older systems
//! - Auto-restarts failed jails, each restart waiting twice as long as the last
//! - Gives up on a jail that needs more than five restarts in five minutes

use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex as StdMutex};
use std::time::{Duration, Instant};

use rand::{RngExt, rng};
use state_machines::runtime::{Clock, Runner};
use supervisor_machines::{Decision, Exit, Intensity, Policy, Strategy, Supervisor};
use tokio::sync::{Mutex, mpsc};

use crate::bridge::Bridge;
use crate::error::Result;
use crate::jail::kqueue::{JailEvent, JailEventSource, JailIdent};
use crate::sys::OsVersion;

mod supervisor;

use supervisor::{DynamicSupervisor, SupervisorCtx, SupervisorEvent, SupervisorState};

/// How often the kqueue is drained and supervision timers are advanced.
const KQUEUE_DRAIN_INTERVAL: Duration = Duration::from_millis(250);

/// Dispatch budget for one supervision drain.
const SUPERVISION_STEPS: usize = 32;

/// Mailbox capacity of a single supervision runner.
const SUPERVISION_MAILBOX: usize = 8;

/// Events the Warden receives
#[derive(Debug)]
pub enum WardenEvent {
    /// A jail has failed (process crashed or state machine error)
    JailFailed { name: String },
    /// A jail's health check failed
    JailHealthFailed { name: String },
    /// A jail started successfully
    JailStarted { name: String },
    /// A jail was stopped (intentionally)
    JailStopped { name: String, jid: i32 },
    /// A jail's health check passed for the first time since it last failed
    JailHealthy { name: String },
    /// A jail exhausted its startup `QoS` budget without a health signal
    QosTimeout { name: String },
    /// Register a jail for kqueue monitoring (sent via `WardenHandle` after restart)
    RegisterJail {
        name: String,
        jid: i32,
        descriptor_fd: Option<i32>,
    },
    /// Shutdown the Warden
    Shutdown,
}

/// Shared tracking of jails being stopped intentionally.
#[derive(Clone, Default)]
struct IntentionalStops {
    jids: Arc<StdMutex<HashSet<i32>>>,
}

impl IntentionalStops {
    fn lock_jids(&self) -> std::sync::MutexGuard<'_, HashSet<i32>> {
        self.jids
            .lock()
            .unwrap_or_else(std::sync::PoisonError::into_inner)
    }

    fn mark(&self, jid: i32) {
        self.lock_jids().insert(jid);
    }

    fn clear(&self, jid: i32) {
        self.lock_jids().remove(&jid);
    }

    fn contains(&self, jid: i32) -> bool {
        self.lock_jids().contains(&jid)
    }
}

/// Pick the kqueue identity to monitor a jail under.
///
/// A descriptor outlives jid reuse, so it wins whenever one is held.
const fn monitor_ident(jid: i32, descriptor_fd: Option<i32>) -> JailIdent {
    match descriptor_fd {
        Some(fd) => JailIdent::Descriptor(fd),
        None => JailIdent::Jid(jid),
    }
}

/// Whether a jail is already monitored under a descriptor identity.
fn has_descriptor_ident(monitored: &HashMap<JailIdent, MonitoredJail>, name: &str) -> bool {
    monitored
        .iter()
        .any(|(ident, jail)| jail.name == name && matches!(ident, JailIdent::Descriptor(_)))
}

/// The identities registered for a jail, optionally narrowed to one jid.
fn idents_for(
    monitored: &HashMap<JailIdent, MonitoredJail>,
    name: &str,
    only_jid: Option<i32>,
) -> Vec<JailIdent> {
    monitored
        .iter()
        .filter(|(_, jail)| jail.name == name && only_jid.is_none_or(|wanted| jail.jid == wanted))
        .map(|(ident, _)| *ident)
        .collect()
}

/// The jail behind a registered kqueue identity
#[derive(Clone)]
struct MonitoredJail {
    name: String,
    jid: i32,
}

/// Restarts tolerated per jail before supervision gives up on it.
const RESTART_INTENSITY: Option<Intensity> = Intensity::new(5, Duration::from_secs(300));
/// First restart delay, doubled per recent restart up to the ceiling.
const RESTART_DELAY_BASE: Duration = Duration::from_secs(1);
const RESTART_DELAY_CEILING: Duration = Duration::from_secs(60);

/// One jail is one child under its own one-for-one supervisor.
type RestartPolicy = Supervisor<1, 8>;

fn restart_policy() -> Option<RestartPolicy> {
    RestartPolicy::new(Strategy::OneForOne, RESTART_INTENSITY?)
}

/// Monotonic millisecond ticks for the supervision runners.
struct MillisClock {
    origin: Instant,
}

impl MillisClock {
    fn new() -> Self {
        Self {
            origin: Instant::now(),
        }
    }
}

impl MillisClock {
    fn elapsed(&self) -> Duration {
        self.origin.elapsed()
    }
}

impl Clock for MillisClock {
    fn now(&self) -> u64 {
        u64::try_from(self.origin.elapsed().as_millis()).unwrap_or(u64::MAX)
    }
}

/// Supervision of a single jail: the runtime machine plus the restart policy
/// that decides whether and when it comes back.
struct Supervision {
    runner: Runner<DynamicSupervisor>,
    policy: Option<RestartPolicy>,
}

impl Supervision {
    fn new(
        name: &str,
        bridge: Arc<Mutex<Bridge>>,
        tx: mpsc::Sender<WardenEvent>,
        clock: &MillisClock,
    ) -> Self {
        let machine = DynamicSupervisor::new(SupervisorCtx::new(name, bridge, tx));
        let mut runner = Runner::new(machine, SUPERVISION_MAILBOX);

        if let Err(e) = runner.start(clock) {
            eprintln!("Warden: Failed to start supervision of jail '{name}': {e:?}");
        }

        Self {
            runner,
            policy: restart_policy(),
        }
    }

    fn state(&self) -> SupervisorState {
        self.runner.machine().current_state()
    }

    /// Arm the retry timer for a `Backoff` visit that has none, or give up.
    fn arm_backoff(&mut self, name: &str, clock: &MillisClock) {
        if self.state() != SupervisorState::Backoff || self.runner.next_deadline().is_some() {
            return;
        }

        let now = clock.elapsed();
        let Some(policy) = self.policy.as_mut() else {
            eprintln!("Warden: Not restarting jail '{name}' (no restart policy)");
            self.enqueue(name, SupervisorEvent::Exhausted);
            return;
        };
        if policy.stopped(0, Policy::Permanent, Exit::Abnormal, now) == Ok(Decision::Escalate) {
            eprintln!("Warden: Not restarting jail '{name}' (restart intensity exceeded)");
            self.enqueue(name, SupervisorEvent::Exhausted);
            return;
        }

        let delay = policy.restart_delay(RESTART_DELAY_BASE, RESTART_DELAY_CEILING, now);
        // Up to half off, so jails that failed together do not restart in lockstep.
        let delay = delay.mul_f64(rng().random_range(0.5..=1.0));
        println!(
            "Warden: Restarting jail '{name}' in {delay:?} (restart {} in window)",
            policy.recent_restarts(now)
        );

        let ticks = u64::try_from(delay.as_millis()).unwrap_or(u64::MAX);
        if let Err(e) = self
            .runner
            .schedule_after(clock, ticks, SupervisorEvent::Retry)
        {
            eprintln!("Warden: Failed to schedule restart of jail '{name}': {e:?}");
        }
    }

    fn enqueue(&self, name: &str, event: SupervisorEvent) {
        if let Err(e) = self.runner.enqueue(event) {
            eprintln!("Warden: Supervision mailbox rejected event for '{name}': {e:?}");
        }
    }
}

/// Terminating and Destroyed are the events a stop records before and after removal.
const fn stop_in_progress(event: crate::audit::AuditEvent) -> bool {
    matches!(
        event,
        crate::audit::AuditEvent::Terminating | crate::audit::AuditEvent::Destroyed
    )
}

/// The Warden supervises all jails with one-for-one restart strategy
pub struct Warden {
    /// Channel to receive events
    rx: mpsc::Receiver<WardenEvent>,
    /// Sender for notifying the Warden (cloneable)
    tx: mpsc::Sender<WardenEvent>,
    /// Supervision runner per jail
    supervisors: HashMap<String, Supervision>,
    /// Logical clock driving the supervision timers
    clock: MillisClock,
    /// Reference to bridge for restart operations
    bridge: Arc<Mutex<Bridge>>,
    /// Kqueue event source for kernel jail monitoring (FreeBSD 16+)
    kqueue: Option<JailEventSource>,
    /// Map of registered kqueue identity -> jail, for event resolution
    monitored: HashMap<JailIdent, MonitoredJail>,
    /// Where an operator's `down` from another process leaves its mark.
    audit: Option<crate::audit::AuditLog>,
    /// Shared tracking for intentional stop requests
    intentional_stops: IntentionalStops,
}

impl Warden {
    /// Create a new Warden for the given bridge
    pub fn new(bridge: Arc<Mutex<Bridge>>) -> Self {
        let (tx, rx) = mpsc::channel(100);

        // Try to create kqueue source on FreeBSD 16+
        let kqueue = if OsVersion::detect_kernel().is_ok_and(|v| v.supports_jail_kqueue()) {
            match JailEventSource::new() {
                Ok(source) => {
                    println!("Warden: Using kqueue jail event monitoring");
                    Some(source)
                }
                Err(e) => {
                    eprintln!(
                        "Warden: Failed to create kqueue source: {e}, falling back to polling"
                    );
                    None
                }
            }
        } else {
            None
        };

        let intentional_stops = IntentionalStops::default();
        let audit = bridge.try_lock().ok().map(|bridge| bridge.audit_log());

        Self {
            rx,
            tx,
            supervisors: HashMap::new(),
            clock: MillisClock::new(),
            bridge,
            kqueue,
            monitored: HashMap::new(),
            intentional_stops,
            audit,
        }
    }

    /// Get a sender to notify the Warden of events
    pub fn sender(&self) -> mpsc::Sender<WardenEvent> {
        self.tx.clone()
    }

    /// Register a jail directly (before the event loop starts)
    pub fn register_jail_direct(&mut self, name: &str, jid: i32, descriptor_fd: Option<i32>) {
        self.register_jail_monitoring(name, jid, descriptor_fd);
    }

    /// Register a jail for kqueue monitoring.
    ///
    /// A descriptor identity is preferred: it stays valid across jid reuse.
    fn register_jail_monitoring(&mut self, name: &str, jid: i32, descriptor_fd: Option<i32>) {
        let ident = monitor_ident(jid, descriptor_fd);

        if descriptor_fd.is_none() && has_descriptor_ident(&self.monitored, name) {
            return;
        }

        for stale in idents_for(&self.monitored, name, None) {
            if stale != ident {
                self.unregister_ident(name, stale);
            }
        }

        self.monitored.insert(
            ident,
            MonitoredJail {
                name: name.to_string(),
                jid,
            },
        );

        if let Some(ref kq) = self.kqueue {
            let registered = match ident {
                JailIdent::Descriptor(fd) => kq.register_jaildesc(fd),
                JailIdent::Jid(jid) => kq.register_jail(jid),
            };

            match registered {
                Ok(()) => println!("Warden: Monitoring jail '{name}' ({ident}) via kqueue"),
                Err(e) => {
                    eprintln!("Warden: Failed to register kqueue for jail '{name}' ({ident}): {e}");
                }
            }
        }
    }

    /// Stop monitoring only the identities that belong to a specific jid.
    fn unregister_jail_jid(&mut self, name: &str, jid: i32) {
        self.unregister_idents(name, Some(jid));
    }

    fn unregister_idents(&mut self, name: &str, only_jid: Option<i32>) {
        for ident in idents_for(&self.monitored, name, only_jid) {
            self.unregister_ident(name, ident);
        }
    }

    fn unregister_ident(&mut self, name: &str, ident: JailIdent) {
        self.monitored.remove(&ident);
        if let Some(ref kq) = self.kqueue
            && let Err(e) = kq.unregister(ident)
        {
            eprintln!("Warden: Failed to unregister kqueue for jail '{name}' ({ident}): {e}");
        }
    }

    /// Process kqueue events (non-blocking poll)
    fn process_kqueue_events(&self) -> Vec<(MonitoredJail, JailEvent)> {
        let Some(kq) = &self.kqueue else {
            return Vec::new();
        };

        let events = match kq.poll(Some(Duration::ZERO)) {
            Ok(events) => events,
            Err(e) => {
                eprintln!("Warden: kqueue poll error: {e}");
                return Vec::new();
            }
        };

        let mut named_events = Vec::new();
        for event in events {
            if let Some(jail) = self.monitored.get(&event.ident()) {
                named_events.push((jail.clone(), event));
            }
        }

        named_events
    }

    /// Run the Warden event loop
    pub async fn run(&mut self) {
        println!("Warden: Starting jail supervisor");

        let mut ticker = tokio::time::interval(KQUEUE_DRAIN_INTERVAL);
        ticker.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);

        loop {
            tokio::select! {
                // mpsc channel events (health failures, manual notifications)
                event = self.rx.recv() => {
                    match event {
                        Some(WardenEvent::Shutdown) | None => {
                            println!("Warden: Shutting down");
                            break;
                        }
                        Some(event) => self.handle_event(event).await,
                    }
                }

                _ = ticker.tick() => self.drain_kqueue(),
            }

            self.pump().await;
        }

        println!("Warden: Supervisor stopped");
    }

    /// Whether the jail's last audit event says a stop was under way, which a
    /// `down` run from another process records before it removes the jail.
    fn stopped_by_operator(&self, name: &str) -> bool {
        self.audit
            .as_ref()
            .and_then(|audit| audit.last_event(name))
            .is_some_and(stop_in_progress)
    }

    /// Resolve pending kernel jail events (no-op without kqueue)
    fn drain_kqueue(&mut self) {
        for (jail, event) in self.process_kqueue_events() {
            let MonitoredJail { name, jid } = jail;
            match event {
                JailEvent::Remove { ident } => {
                    self.monitored.remove(&ident);
                    if self.intentional_stops.contains(jid) {
                        println!(
                            "Warden: Kernel reports jail '{name}' ({ident}) removed after requested stop"
                        );
                    } else if self.stopped_by_operator(&name) {
                        println!(
                            "Warden: Kernel reports jail '{name}' ({ident}) removed by a stop from another process"
                        );
                    } else {
                        println!("Warden: Kernel reports jail '{name}' ({ident}) removed");
                        self.handle_failure(&name);
                    }
                }
                JailEvent::Child { ident, coalesced } => {
                    let detail = if coalesced {
                        "multiple child jails"
                    } else {
                        "a child jail"
                    };
                    println!("Warden: Jail '{name}' ({ident}) created {detail}");
                }
                JailEvent::Set { .. } => {}
                JailEvent::Attach { ident, coalesced } => {
                    if coalesced {
                        println!("Warden: Jail '{name}' ({ident}) had multiple attaches");
                    }
                }
            }
        }
    }

    /// Advance every supervision runner: timers, dispatch, restart activities.
    async fn pump(&mut self) {
        for (name, supervision) in &mut self.supervisors {
            if supervision.runner.tick(&self.clock).is_err() {
                eprintln!("Warden: Monotonic clock went backwards supervising jail '{name}'");
            }

            if let Err(e) = supervision.runner.drain(SUPERVISION_STEPS).await {
                eprintln!("Warden: Supervision of jail '{name}' failed: {e:?}");
            }

            supervision.arm_backoff(name, &self.clock);
        }
    }

    /// Handle a single warden event
    async fn handle_event(&mut self, event: WardenEvent) {
        match event {
            WardenEvent::JailFailed { name } => {
                println!("Warden: Jail '{name}' failed, initiating restart");
                self.handle_failure(&name);
            }
            WardenEvent::JailHealthFailed { name } => {
                println!("Warden: Jail '{name}' health check failed, initiating restart");
                self.handle_failure(&name);
            }
            WardenEvent::JailHealthy { name } => {
                self.shift_to_steady(&name, "healthy").await;
            }
            WardenEvent::QosTimeout { name } => {
                self.shift_to_steady(&name, "timer").await;
            }
            WardenEvent::JailStarted { name } => {
                println!("Warden: Jail '{name}' started successfully");
                if let Some(supervision) = self.supervisors.get_mut(&name)
                    && supervision.state() == SupervisorState::Backoff
                {
                    supervision.enqueue(&name, SupervisorEvent::Recovered);
                }
            }
            WardenEvent::JailStopped { name, jid } => {
                println!("Warden: Jail '{name}' stopped intentionally");
                self.supervisors.remove(&name);
                self.unregister_jail_jid(&name, jid);
                self.intentional_stops.clear(jid);
            }
            WardenEvent::RegisterJail {
                name,
                jid,
                descriptor_fd,
            } => {
                self.register_jail_monitoring(&name, jid, descriptor_fd);
            }
            WardenEvent::Shutdown => {
                // Handled in run loop
            }
        }
    }

    /// Move a jail from its startup `QoS` profile to its steady one.
    #[allow(clippy::needless_pass_by_ref_mut)] // &self makes run()'s future need Warden: Sync, which it is not
    async fn shift_to_steady(&mut self, name: &str, trigger: &str) {
        let result = {
            let br = self.bridge.lock().await;
            br.shift_qos(name, crate::scope::QosPhase::Steady)
        };

        match result {
            Ok(crate::bridge::ShiftOutcome::Shifted) => {
                println!("Warden: Jail '{name}' shifted to steady QoS profile ({trigger})");
            }
            Ok(_) => {}
            Err(e) => eprintln!("Warden: Failed to shift jail '{name}' to steady QoS profile: {e}"),
        }
    }

    /// Hand a jail failure to its supervision machine
    fn handle_failure(&mut self, name: &str) {
        let bridge = Arc::clone(&self.bridge);
        let tx = self.tx.clone();
        let clock = &self.clock;

        let supervision = self
            .supervisors
            .entry(name.to_string())
            .or_insert_with(|| Supervision::new(name, bridge, tx, clock));

        match supervision.state() {
            SupervisorState::Healthy => supervision.enqueue(name, SupervisorEvent::Failed),
            SupervisorState::Dead => {
                eprintln!("Warden: Not restarting jail '{name}' (supervision exhausted)");
            }
            state => println!(
                "Warden: Jail '{}' is already recovering ({})",
                name,
                state.name()
            ),
        }
    }

    /// Request the Warden to shutdown
    pub async fn request_shutdown(sender: &mpsc::Sender<WardenEvent>) {
        // Receiver gone means already shut down.
        let _ = sender.send(WardenEvent::Shutdown).await;
    }
}

/// Handle for interacting with the Warden from non-async code
#[derive(Clone)]
pub struct WardenHandle {
    sender: mpsc::Sender<WardenEvent>,
    intentional_stops: IntentionalStops,
}

impl WardenHandle {
    /// Create a handle from a Warden
    pub fn new(warden: &Warden) -> Self {
        Self {
            sender: warden.sender(),
            intentional_stops: warden.intentional_stops.clone(),
        }
    }

    /// Mark a jail as being stopped intentionally before removal begins.
    pub fn mark_stop_requested(&self, jid: i32) {
        self.intentional_stops.mark(jid);
    }

    /// Clear the intentional stop marker for a jail.
    pub fn clear_stop_requested(&self, jid: i32) {
        self.intentional_stops.clear(jid);
    }

    fn channel_closed_err() -> crate::error::Error {
        crate::error::Error::Io(std::io::Error::other("Warden channel closed"))
    }

    /// Post an event from synchronous code without blocking.
    fn post(&self, event: WardenEvent) -> Result<()> {
        self.sender.try_send(event).map_err(|e| match e {
            mpsc::error::TrySendError::Closed(_) => Self::channel_closed_err(),
            mpsc::error::TrySendError::Full(_) => {
                crate::error::Error::Io(std::io::Error::other("Warden event queue full"))
            }
        })
    }

    /// Notify that a jail failed
    pub fn notify_failure(&self, name: &str) -> Result<()> {
        self.post(WardenEvent::JailFailed {
            name: name.to_string(),
        })
    }

    /// Notify that a jail's health check failed
    pub fn notify_health_failure(&self, name: &str) -> Result<()> {
        self.post(WardenEvent::JailHealthFailed {
            name: name.to_string(),
        })
    }

    /// Notify that a jail's health check passed
    pub fn notify_healthy(&self, name: &str) -> Result<()> {
        self.post(WardenEvent::JailHealthy {
            name: name.to_string(),
        })
    }

    /// Notify that a jail exhausted its startup `QoS` budget
    pub async fn notify_qos_timeout(&self, name: &str) -> Result<()> {
        self.sender
            .send(WardenEvent::QosTimeout {
                name: name.to_string(),
            })
            .await
            .map_err(|_| Self::channel_closed_err())
    }

    /// Notify that a jail started
    pub fn notify_started(&self, name: &str) -> Result<()> {
        self.post(WardenEvent::JailStarted {
            name: name.to_string(),
        })
    }

    /// Notify that a jail stopped intentionally
    pub fn notify_stopped(&self, name: &str, jid: i32) -> Result<()> {
        self.post(WardenEvent::JailStopped {
            name: name.to_string(),
            jid,
        })
    }

    /// Register a jail for kqueue monitoring
    pub fn register_jail(&self, name: &str, jid: i32, descriptor_fd: Option<i32>) -> Result<()> {
        self.post(WardenEvent::RegisterJail {
            name: name.to_string(),
            jid,
            descriptor_fd,
        })
    }
}

#[cfg(test)]
mod tests;