scripts/check-local-headers.sh: Verify there is input (don't hang).

Message ID 54890AA3.4040706@redhat.com
State Superseded
Headers

Commit Message

Carlos O'Donell Dec. 11, 2014, 3:08 a.m. UTC
  If you have a failed build, and run `make check` it could hang forever
in check-local-headers.sh because the awk script waits reading stdin
if the input shell glob expands to nothing (missing input).

We have three options, close stdin, more awk to detect missing input
or more shell. I chose the latter, but we could probably fix this with
`exec 0>&-` in the shell if anyone objects to using find/grep or more
awk.

Tested on x86_64 with a broken build directory.

OK to checkin?

2014-12-10  Carlos O'Donell  <carlos@redhat.com>

	* scripts/check-local-headers.sh: Verify there is input.
  

Comments

Andreas Schwab Dec. 11, 2014, 8:30 a.m. UTC | #1
"Carlos O'Donell" <carlos@redhat.com> writes:

> We have three options, close stdin, more awk to detect missing input
> or more shell. I chose the latter, but we could probably fix this with
> `exec 0>&-` in the shell if anyone objects to using find/grep or more
> awk.

Just redirect from /dev/null.

Andreas.
  
Joseph Myers Dec. 11, 2014, 2:22 p.m. UTC | #2
On Wed, 10 Dec 2014, Carlos O'Donell wrote:

> If you have a failed build, and run `make check` it could hang forever
> in check-local-headers.sh because the awk script waits reading stdin
> if the input shell glob expands to nothing (missing input).
> 
> We have three options, close stdin, more awk to detect missing input
> or more shell. I chose the latter, but we could probably fix this with
> `exec 0>&-` in the shell if anyone objects to using find/grep or more
> awk.

We have consensus to redirect test input from /dev/null (unless a test 
needs input from some other file, of course).  See bug 14753.
  

Patch

diff --git a/scripts/check-local-headers.sh b/scripts/check-local-headers.sh
index 9bffed3..5404e4b 100755
--- a/scripts/check-local-headers.sh
+++ b/scripts/check-local-headers.sh
@@ -25,6 +25,13 @@  cd "$objpfx"
 # OK if *.os is missing.
 shopt -s nullglob
 
+# Don't hang in awk reading stdin if there is no input to the test.
+# The most likely cause of this failure is a build failure.
+if ! find . -regex '.*\.o[sS]*\.d' | grep -q '.*\.o[sS]*\.d'; then
+    echo "FAIL: No input files to read."
+    exit 1
+fi
+
 # Search all dependency files for file names in the include directory.
 # There are a few system headers we are known to use.
 # These include Linux kernel headers (asm*, arch, and linux),