groff-commit
[Top][All Lists]
Advanced

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

[groff] 10/10: [tests]: Fix potential problem(s) in trap handler.


From: G. Branden Robinson
Subject: [groff] 10/10: [tests]: Fix potential problem(s) in trap handler.
Date: Mon, 19 Dec 2022 21:50:51 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 59efbfc364daee11af9207a3fc79675b6f5bfc25
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Dec 19 19:06:05 2022 -0600

    [tests]: Fix potential problem(s) in trap handler.
    
    * src/roff/groff/tests/smoke-test_html_device.sh: Move call of `cleanup`
      function from end of script to after the tests that generate temporary
      files have been run, and before script possibly exits with status 77
      to skip some checks.  Within trap handler, mask trapped signals while
      running handler.
    
      (cleanup): Reset trap dispositions to default after removing files;
      once the temporary files are gone, we no longer need a trap handler.
      One might already be running however, and this ensures that its
      "suicide" ("kill -s INT $$") will succeed.
    
    This delicate dance is why I try not to create temporary files in test
    scripts.  But grohtml does it for us, so we have to cope.  (Not so
    temporary, in fact--you have to keep them around if you want to view the
    HTML document produced.)
    
    (To test this stuff, add a "sleep" built-in before the "cleanup" in the
    main logic of the script, and kill it.)
---
 ChangeLog                                      | 14 ++++++++++++++
 src/roff/groff/tests/smoke-test_html_device.sh |  6 ++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d8ba0ea27..349632c87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2022-12-19  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [tests]: Fix potential problem(s) in trap handler.
+
+       * src/roff/groff/tests/smoke-test_html_device.sh: Move call of
+       `cleanup` function from end of script to after the tests that
+       generate temporary files have been run, and before script
+       possibly exits with status 77 to skip some checks.  Within trap
+       handler, mask trapped signals while running handler.
+       (cleanup): Reset trap dispositions to default after removing
+       files; once the temporary files are gone, we no longer need a
+       trap handler.  One might already be running however, and this
+       ensures that its "suicide" ("kill -s INT $$") will succeed.
+
 2022-12-18  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [mdoc]: Support `FT` register.
diff --git a/src/roff/groff/tests/smoke-test_html_device.sh 
b/src/roff/groff/tests/smoke-test_html_device.sh
index 63fb27a8b..efdaa0449 100755
--- a/src/roff/groff/tests/smoke-test_html_device.sh
+++ b/src/roff/groff/tests/smoke-test_html_device.sh
@@ -29,9 +29,10 @@ wail () {
 
 cleanup () {
   rm -f grohtml-[0-9]*-[12].png
+  trap - HUP INT QUIT TERM
 }
 
-trap 'trap - HUP INT QUIT TERM; cleanup; kill -s INT $$' \
+trap 'trap "" HUP INT QUIT TERM; cleanup; kill -s INT $$' \
   HUP INT QUIT TERM
 
 input='.TS
@@ -53,6 +54,8 @@ echo "checking production of inline image for eqn(1) 
equation" >&2
 output=$(echo "$input" | "$groff" -e -Thtml)
 echo "$output" | grep -q '<img src="grohtml-[0-9]\+-2.png"' || wail
 
+cleanup
+
 # We can't run remaining tests if the environment doesn't support UTF-8.
 test "$(locale charmap)" = UTF-8 || exit 77 # skip
 
@@ -71,7 +74,6 @@ echo "checking -C -k -Thtml" >&2
 printf "\('a" | "$groff" -C -k -Thtml | grep -qx '<p>&aacute;</p>' \
   || wail
 
-cleanup
 test -z "$fail"
 
 # vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]