]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
profile/systemd-osc-context: Acknowledge uncertainty
authorChris Lindee <chris.lindee+github@gmail.com>
Mon, 16 Feb 2026 06:47:15 +0000 (00:47 -0600)
committerChris Lindee <chris.lindee+github@gmail.com>
Mon, 16 Feb 2026 09:15:51 +0000 (03:15 -0600)
Bash does not provide an easy way to discern if an exit status came from
a signal, or was a legitimate non-zero exit (i.e. a failure).  It can be
done, by using job control or by invoking another program; however, such
approaches require modifying the command entered by a user and are, thus,
invasive and risky.

Since an exit status of 129 on a command could either indicate it exited
cleanly with `exit(129)` or was interrupted by `SIGHUP`, the osc context
should report both possibilities, to acknowledge our uncertainty.  Given
we have no idea what happened, besides an unsuccessful exit, the exit is
described as `exit=failure`.

Moreover, discerning between an `interrupt` and a `crash` with a command
likely involves categorizing every signal.  It is fairly obvious `SIGINT`
is an interrupt and also obvious, IMO, that `SIGSEGV` is a crash.  Avoid
the complication (and potential disagreements) by using the encompassing,
generic value — one that remains true if no signal occurred.

References:
 [0] https://stackoverflow.com/a/66431355

profile.d/80-systemd-osc-context.sh

index c7a556f66adbf94415287bcf5c6c6a729837a29a..df7f93afa3a2522d9c4f0efe7f29a9a3bff48a36 100644 (file)
@@ -44,7 +44,7 @@ __systemd_osc_context_precmdline() {
     # Close previous command
     if [ -n "${systemd_osc_context_cmd_id:-}" ]; then
         if [ "$systemd_exitstatus" -gt 128 ] && systemd_signal=$(kill -l "$systemd_exitstatus" 2>&-); then
-            printf "\033]3008;end=%s;exit=interrupt;signal=SIG%s\033\\" "$systemd_osc_context_cmd_id" "$systemd_signal"
+            printf "\033]3008;end=%s;exit=failure;status=%s;signal=SIG%s\033\\" "$systemd_osc_context_cmd_id" "$systemd_exitstatus" "$systemd_signal"
         elif [ "$systemd_exitstatus" -ne 0 ]; then
             printf "\033]3008;end=%s;exit=failure;status=%s\033\\" "$systemd_osc_context_cmd_id" $((systemd_exitstatus))
         else