From 0e690391d53c57905783b0633562654d1025f508 Mon Sep 17 00:00:00 2001 From: lllusion3469 <31420484+lllusion3469@users.noreply.github.com> Date: Thu, 24 May 2018 15:02:31 +0200 Subject: [PATCH 1/2] Change atom.sh not to spawn a sleep process every second on --wait As sleep(1) is not a bash builtin, every second a new process is spawed. To prevent this, the POSIX read can be used instead. Since it is (required to be) a bash builtin, it is immediately killed along with bash unlike a longer running sleep would be. In case stdin is e.g. /dev/null for whatever reason (this would break EDITOR=nano), sleep is still kept to prevent a tight loop. --- atom.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/atom.sh b/atom.sh index cd28dd334..a58893bdc 100755 --- a/atom.sh +++ b/atom.sh @@ -149,6 +149,7 @@ trap 'on_die' SIGQUIT SIGTERM # If the wait flag is set, don't exit this process until Atom tells it to. if [ $WAIT ]; then while true; do + read sleep 1 done fi From e3628fcf0251a27a12db8a96c02aa08c8343e5d0 Mon Sep 17 00:00:00 2001 From: lllusion3469 <31420484+lllusion3469@users.noreply.github.com> Date: Tue, 29 May 2018 22:37:15 +0200 Subject: [PATCH 2/2] Use a named pipe instead of the tty Works even if stdin is not a terminal. Some programs can replace a fifo with a named pipe, which would break this. For example: rsync without --specials --- atom.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/atom.sh b/atom.sh index a58893bdc..13ff85a61 100755 --- a/atom.sh +++ b/atom.sh @@ -148,8 +148,16 @@ trap 'on_die' SIGQUIT SIGTERM # If the wait flag is set, don't exit this process until Atom tells it to. if [ $WAIT ]; then + WAIT_FIFO="$ATOM_HOME/.wait_fifo" + while true; do + [ -f "$WAIT_FIFO" ] && rm "$WAIT_FIFO" + [ ! -p "$WAIT_FIFO" ] && mkfifo "$WAIT_FIFO" + read < "$WAIT_FIFO" || break + sleep 1 # prevent a tight loop + done + + # fall back to sleep while true; do - read sleep 1 done fi