Re: systemd service causing bash to miss signals?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 19, 2022 at 08:25:32PM +0300, Mantas Mikul??nas wrote:
> Pipelines somewhat rely on the kernel delivering SIGPIPE to the writer as
> soon as the read end is closed. So if you have `foo | head -1`, then as
> soon as head reads enough and exits, foo gets killed via SIGPIPE.

In my case:

  cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 64|head -1

'fold' _is_ getting the SIGPIPE.  It won't get killed if it has a handler.

> But as
> most systemd-managed services aren't shell interpreters, systemd marks
> SIGPIPE as "ignored" when starting the service process, so that if the
> service is somehow tricked into opening a pipe that a user has mkfifo'd, at
> least the kernel can't be tricked into killing the service. You can opt out
> of this using IgnoreSIGPIPE=.

Ah, based on your explanation, I see this, which almost exactly
matches my situation.

  https://stackoverflow.com/a/44376786

For me, key takeway:

  However, when the pipeline is run under systemd, systemd sets the
  default action for SIGPIPE to SIG_IGN, which makes the processes
  in the pipeline ignore the signal.

For the archives, I can confirm that putting IgnoreSIGPIPE=false under
[Service] indeed allows my example to work correctly.

-- 
Brian Reichert				<reichert@xxxxxxxxxxx>
BSD admin/developer at large	



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux