Package: socat
Version: 1.7.2.4-2
Severity: normal
Tags: upstream

When socat is terminated by a signal that it catches (e.g. SIGTERM),
it exits with status 128+signum (socat_signal() -> diag_exit() ->
_diag_exit() -> Exit() -> exit()).

Though 128+signum is a convention used by common shells to set $?
for processes killed by a signal, it's not actually the same;
wait() on such a process returns different statuses.

I noticed this when I tried to use socat in a systemd service. When
terminating it properly (i.e. via SIGTERM), systemd would
(correctly) describe it as "failed":

  Active: failed (Result: exit-code)
  Process: 1096 ExecStart=/usr/bin/socat [...] (code=exited, status=143)

rather than "dead" as it does after proper termination:

  Active: inactive (dead)
  Process: 20422 ExecStart=/some/other/program (code=killed, signal=TERM)

The usual way to achieve the correct behaviour, i.e. acting on a
signal and then terminating as if by the signal, is to restore the
handler to SIG_DFL, then raise() the signal again.

This would require small changes to the intermediate functions
listed above, and maybe manual calling atexit() functions, but
should otherwise be a rather easy fix.

-- System Information:
Debian Release: 8.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 
'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/8 CPU cores)
Locale: LANG=de_DE, LC_CTYPE=de_DE (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages socat depends on:
ii  libc6        2.19-18+deb8u1
ii  libssl1.0.0  1.0.1k-3+deb8u2
ii  libwrap0     7.6.q-25

socat recommends no packages.

socat suggests no packages.

-- no debconf information

Reply via email to