]> git.draconx.ca Git - liblbx.git/commitdiff
Work around shell redirection bug on HP-UX /bin/sh.
authorNick Bowler <nbowler@draconx.ca>
Sun, 26 Sep 2021 06:05:26 +0000 (02:05 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 26 Sep 2021 06:05:26 +0000 (02:05 -0400)
On HP-UX /bin/sh, when "read" is used in a subshell with redirections,
it seems that some of the input gets dropped on the floor.  For example:

  % cat >test.txt <<'EOF'
  hello
  world
EOF
  % ( exec 3<test.txt; read a <&3; read b <&3; echo $a $b )
  hello

In TEST_CHECK_PAM_MD5, we hit this bug because AT_CHECK runs its
commands in a subshell, and as a result some of the image data is
lost after reading the header and verification fails.

Work around the issue by performing only a single AT_CHECK with a
single redirection.

tests/moo2data.at

index e47ccf4e64b13dc3326519976f4f56f6fa66e39c..326763a6cc4d1d7ee27f844ff86cb223bd0775f6 100644 (file)
@@ -74,19 +74,17 @@ dnl
 dnl Compute and validate the MD5 hash over the plane data from a PAM image.
 dnl Additional arguments specify PAM header fields that should be checked.
 m4_define([TEST_CHECK_PAM_MD5],
-[exec 3<$1; AT_CHECK([pam_check_header <&3 \
-  m4_map_args_sep([m4_apply([m4_car], m4_split(], [))], [ ], m4_shift2($@))
-status=$?
-echo $pam_TUPLTYPE >$1.tt
-exit $?], [0],[m4_map_args([m4_n], m4_shift2($@))])
-AT_CHECK([test_md5sum <&3 >$1.md5])
-exec 3<&-
-
-# For reliable verification of images with transparency, we must have a known
-# constant colour value for transparent pixels.  We can use netpbm tools to
-# zero out those pixels.  For affected image formats, if we cannot normalize
-# the transparent pixels we have to skip the test if verification would fail.
-
+[AT_CHECK([:; { pam_check_header m4_map_args_sep(
+  [m4_apply([m4_car], m4_split(], [))], [ ], m4_shift2($@)) &&
+  echo $pam_TUPLTYPE >$1.tt &&
+  test_md5sum >$1.md5; } <$1], [0], [m4_map_args([m4_n], m4_shift2($@))])
+dnl AT_CHECK([test_md5sum <&3 >$1.md5])
+dnl exec 3<&-
+
+dnl For reliable verification of images with transparency, we must have a known
+dnl constant colour value for transparent pixels.  We can use netpbm tools to
+dnl zero out those pixels.  For affected image formats, if we cannot normalize
+dnl the transparent pixels we have to skip the test if verification would fail.
 md5_reliable=true
 read pam_TUPLTYPE <$1.tt
 AS_CASE([$pam_TUPLTYPE],