Subject: Re: [PATCH 4/8] doc: simplify the handling of interruptions

From: Felipe Contreras <[email-masked]>
Date: Thu, 13 May 2021 01:10:18 -0500

Junio C Hamano wrote:
> Felipe Contreras <[email-masked]> writes:
> 
> > +"${args[@]}" -o "$out" "$1" ||
> > +{ rm -f "$out"; false; }
> 
> It would be so nice if this worked, but here is what I saw in a
> quick-and-dirty experiment:
> 
>     $ f hoi || rm hoi ;# wait a bit and hit ^C
> 
> So, I suspect it unfortunately may not work well.

That's because the interrupt signal is not caught.

This works:

  sh -c 'echo foo >"$1" && trap "exit 1" INT && sleep 20' test hoi || rm hoi

And so does this:

  #!/bin/sh

  ruby - hoi <<EOF || rm hoi
  File.write(ARGV[0], 'foo')
  begin
    sleep(10)
  rescue Exception
    exit(1)
  end
  EOF

Both asciidoc and asciidoctor trap the signal.

> We need to get 2/8 redone without bash-ism,

Yes, if we agree this approach is indeed desirable I can do that.

Cheers.

-- 
Felipe Contreras