diff mbox series

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

Message ID 20210512222803.508446-5-felipe.contreras@gmail.com (mailing list archive)
State Superseded
Headers show
Series doc: asciidoc cleanups | expand

Commit Message

Felipe Contreras May 12, 2021, 10:27 p.m. UTC
There's no need to have an intermediary file.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/asciidoc-helper.sh | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Junio C Hamano May 13, 2021, 5:19 a.m. UTC | #1
Felipe Contreras <felipe.contreras@gmail.com> 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 () { echo foo >"$1" && sleep 20 && echo bar >>"$1"; }
    $ f hoi ;# wait sufficiently long
    $ cat hoi
    foo
    bar
    $ f hoi ;# wait a bit and hit ^C
    ^C
    $ cat hoi
    foo
    $ rm hoi
    $ f hoi || rm hoi ;# wait a bit and hit ^C
    ^C
    $ cat hoi
    foo

So, I suspect it unfortunately may not work well.

We need to get 2/8 redone without bash-ism, but it would not affect
the correctness of this step, I would think, whether this is done in
bash or implemented in a plain vanilla POSIX shell.

Thanks.
Felipe Contreras May 13, 2021, 6:10 a.m. UTC | #2
Junio C Hamano wrote:
> Felipe Contreras <felipe.contreras@gmail.com> 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.
diff mbox series

Patch

diff --git a/Documentation/asciidoc-helper.sh b/Documentation/asciidoc-helper.sh
index ae16cf9288..8dbe4fc372 100755
--- a/Documentation/asciidoc-helper.sh
+++ b/Documentation/asciidoc-helper.sh
@@ -13,6 +13,5 @@  while [ $# -gt 1 ]; do
 	shift
 done
 
-rm -f "$out+" "$out" &&
-"${args[@]}" -o "$out+" "$1" &&
-mv "$out+" "$out"
+"${args[@]}" -o "$out" "$1" ||
+{ rm -f "$out"; false; }