Ive got "Interrupted system call" message and dont really know why to be honest. My homework is to write server script who uses fifo to communicate with client script, basically it works but I dont know how to get rid of this message. Will appreciate for any suggestion.
My server script:
#!/bin/bash
server=serwerfifo
if [[ "$1" ]]; then
if [[ ! -p $1 ]]; then
echo "Reader(klient) not running"
else
echo $(expr $2 + $2) > $1 &
fi
else
trap "" SIGHUP SIGTERM SIGCHLD
trap "exit 0" SIGUSR1
if [[ ! -p $server ]]; then
mkfifo $server
fi
while true
do
if read line < $server; then
$0 $line &
fi
done
fi
Message appears when interpreter rich this line:
if read line < $server; then
With respect to the EINTR -- you're making your code unnecessarily prone to race conditions by re-opening the FIFO repeatedly. Don't do that more often than you have to -- use a single handle until the writer closes (and thus you get an EOF).
while :; do # if we hit end-of-FIFO, then loop around and try to reopen
while read -r line; do
"$0" "$line" &
done < "$server"
done
Note that the < "$server"
is on the loop, not on the read
, so if you have multiple lines written by your writer, those multiple lines will be read by the reader before it closes the FIFO.
The other pertinent thing here is your use of background processes making events asynchronous (and thus their ordering non-deterministic). You really can get a completely legitimately interrupted syscall, particularly when you have open and close operations happening at hard-to-predict times: a UNIX kernel is allowed to tell userland that it needs to retry what it's doing (and that another attempt will succeed). That's not an error, it's a legitimate and permissible result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With