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
//! Unix signal-aware exit code computation.
//!
//! Provides [`signal_exit_code`] which follows the POSIX `128 + signal_number`
//! convention: if a subprocess was killed by a signal, the canonical exit code
//! reported to the caller is `128 + N`, allowing signal kills to be distinguished
//! from normal exits (0–125).
use ExitStatus;
/// Compute the exit code to propagate for a subprocess [`ExitStatus`].
///
/// Follows the POSIX `128 + signal` convention on Unix platforms:
/// if the process was killed by signal `N`, returns `128 + N`.
/// Falls back to `status.code().unwrap_or(1)` on non-Unix or when
/// the status reports a numeric exit code (no signal).
///
/// # Fix(BUG-242)
///
/// Before this helper existed every `unwrap_or(-1)` / `unwrap_or(1)` at
/// exit-code call sites collapsed all signal kills to a single code.
/// Replace those call sites with `signal_exit_code(&status)`.
///
/// # Examples
///
/// ```
/// # #[ cfg( unix ) ]
/// # {
/// use std::process::Command;
/// use claude_runner_core::signal_exit_code;
///
/// // A process that exits 0 → 0
/// let status = Command::new( "true" ).status().unwrap();
/// assert_eq!( signal_exit_code( &status ), 0 );
///
/// // A process that exits 1 → 1
/// let status = Command::new( "false" ).status().unwrap();
/// assert_eq!( signal_exit_code( &status ), 1 );
/// # }
/// ```