If we get both a filename and a pipe, prefer the filename.
For example, this will show the contents of /etc/passwd:
$ echo hello | moar /etc/passwd
Before this change, it displayed "hello" on a page.
diff --git m/reader.go m/reader.go
index 339de9c..2427094 100644
--- m/reader.go
+++ m/reader.go
@@ -12,6 +12,7 @@ import (
"regexp"
"strings"
"sync"
+ "time"
)
// Reader reads a file into an array of strings.
@@ -54,9 +55,18 @@ func _ReadStream(stream io.Reader, reader *Reader, fromFilter *exec.Cmd) {
return
}
- // FIXME: Can Wait()ing here stall? Should we release the lock while Wait()ing?
+ // Give the filter a little time to go away
+ timer := time.AfterFunc(2*time.Second, func() {
+ fromFilter.Process.Kill()
+ })
+
err := fromFilter.Wait()
+ timer.Stop()
+
if reader.err == nil {
+ // NOTE: This could mean that our Wait()ing on the filter above
+ // timed out.
+ //
// FIXME: Add filter stderr contents to the error reported here
reader.err = err
}
diff --git test.sh test.sh
index 677c5db..6d0b6b9 100755
--- test.sh
+++ test.sh
@@ -3,7 +3,7 @@
set -e -o pipefail
# Unit tests first
-go test github.com/walles/moar/m
+go test -timeout 20s github.com/walles/moar/m
# Ensure we can cross compile
# NOTE: Make sure this list matches the one in release.sh
Change-Id: I3847aaa0942588c2d4129c7b2967d1d10aa95035