Skip to content

Commit

Permalink
Refactor simplify Process::Status#exit_reason on Unix (#15288)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Dec 20, 2024
1 parent 7e48069 commit f0185ee
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/process/status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,30 @@ class Process::Status
@exit_status & 0xC0000000_u32 == 0 ? ExitReason::Normal : ExitReason::Unknown
end
{% elsif flag?(:unix) && !flag?(:wasm32) %}
# define __WIFEXITED(status) (__WTERMSIG(status) == 0)
if signal_code == 0
case exit_signal?
when Nil
ExitReason::Normal
elsif signal_exit?
case Signal.from_value?(signal_code)
when Nil
ExitReason::Signal
when .abrt?, .kill?, .quit?
ExitReason::Aborted
when .hup?
ExitReason::TerminalDisconnected
when .term?
ExitReason::SessionEnded
when .int?
ExitReason::Interrupted
when .trap?
ExitReason::Breakpoint
when .segv?
ExitReason::AccessViolation
when .bus?
ExitReason::BadMemoryAccess
when .ill?
ExitReason::BadInstruction
when .fpe?
ExitReason::FloatException
else
ExitReason::Signal
end
when .abrt?, .kill?, .quit?
ExitReason::Aborted
when .hup?
ExitReason::TerminalDisconnected
when .term?
ExitReason::SessionEnded
when .int?
ExitReason::Interrupted
when .trap?
ExitReason::Breakpoint
when .segv?
ExitReason::AccessViolation
when .bus?
ExitReason::BadMemoryAccess
when .ill?
ExitReason::BadInstruction
when .fpe?
ExitReason::FloatException
else
# TODO: stop / continue
ExitReason::Unknown
ExitReason::Signal
end
{% else %}
raise NotImplementedError.new("Process::Status#exit_reason")
Expand Down

0 comments on commit f0185ee

Please sign in to comment.