GPG: Encrypt data from pipe for certain time, then stop
If you put the timeout
in the middle of the pipeline, then gpg
will exit cleanly:
cat /dev/ttyACM0 | timeout ${TIMEOUT} cat | gpg -e -r ${RECIPIENT} > ${OUT_FILE}
I can't fully explain this, but I believe it is due to the way pipeline errors (signals) are handled / propagated.
Note: I've asked this question to try to understand this better.
Note that even using the following will fail:
$ timeout 5 cat < /dev/urandom | gpg -e -r ${RECIPIENT} > myfile.gpg
gpg: Terminated caught ... exiting
Terminated