diff options
author | Karel Zak | 2015-04-14 11:52:06 +0200 |
---|---|---|
committer | Karel Zak | 2015-04-14 11:52:06 +0200 |
commit | f8c0152970221261c52f6604e9e7963b478ebd95 (patch) | |
tree | 512705140f6eebee384c0e008645d0b8b3ab5092 /tests/functions.sh | |
parent | unshare: allow persisting mount namespaces (diff) | |
parent | travis: install socat >= 1.7.2 (diff) | |
download | kernel-qcow2-util-linux-f8c0152970221261c52f6604e9e7963b478ebd95.tar.gz kernel-qcow2-util-linux-f8c0152970221261c52f6604e9e7963b478ebd95.tar.xz kernel-qcow2-util-linux-f8c0152970221261c52f6604e9e7963b478ebd95.zip |
Merge branch 'tests-logger' of https://github.com/rudimeier/util-linux
* 'tests-logger' of https://github.com/rudimeier/util-linux:
travis: install socat >= 1.7.2
tests: add subtests for invalid logger devive
tests: logger/errors does not use --no-act
tests: logger, validate written socket data
tests: logger with socat device
tests: simplify common logger options
logger: --stderr and --no-act turn "auto-errors" on
Diffstat (limited to 'tests/functions.sh')
-rw-r--r-- | tests/functions.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/functions.sh b/tests/functions.sh index e74a11cb5..6f786e797 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -652,3 +652,32 @@ function ts_resolve_host { test -n "$tmp" || return 1 echo "$tmp" | sort -R | head -n 1 } + +# listen to unix socket (background socat) +function ts_init_socket_to_file { + local socket=$1 + local outfile=$2 + local pid="0" + + ts_check_prog "socat" + rm -f "$socket" "$outfile" + + socat -u UNIX-LISTEN:$socket,fork,max-children=1,backlog=128 \ + STDOUT > "$outfile" & + pid=$! + + # check for running background process + if [ "$pid" -le "0" ] || ! kill -s 0 "$pid"; then + ts_skip "unable to run socat" + fi + # wait for the socket listener + if ! socat -u /dev/null UNIX-CONNECT:$socket,retry=30,interval=0.1; then + kill -9 "$pid" + ts_skip "timeout waiting for socket" + fi + # check socket again + if ! socat -u /dev/null UNIX-CONNECT:$socket; then + kill -9 "$pid" + ts_skip "socket stopped listening" + fi +} |