Re: dash 0.5.11.2: somehow falsely waits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello on a Monday.

Steffen Nurpmeso wrote in
 <20201220014300.8lXtI%steffen@xxxxxxxxxx>:
 |There is another issue with at least dash (the others not yet
 |tested).  I cloned the git repo and it is still present at
 |6ba88b3ed28fb4b52f20b730194c4ad3d8aad037.
 |
 |With the original test script of what is in "Re: dash 0.5.11.2,
 |busybox sh 1.32.0, FreeBSD 12.2 sh: spring TTOU but should not
 |i think" the sleeper will randomly wake too early for whatever
 |reason.  The sleeper is:
 |
 |  i=
 |  trap 'i=1' USR1 # "reaper (actually a notify timer only) is up"
 |  (
 |      parent=${$}
 |      sleeper= int=0 hot=0
 |      trap '' EXIT HUP QUIT CHLD
 |      trap 'exit 0' INT
 |      trap '
 |         int=1 hot=1
 |         [ -n "${sleeper}" ] && kill -TERM ${sleeper} >/dev/null 2>&1
 |      ' USR1
 |      trap '
 |         int=1 hot=0
 |         [ -n "${sleeper}" ] && kill -TERM ${sleeper} >/dev/null 2>&1
 |      ' USR2
 |      trap '
 |         [ -n "${sleeper}" ] && kill -TERM ${sleeper} >/dev/null 2>&1
 |         echo "Stopping job reaper"
 |         exit 0
 |      ' TERM
 |
 |      # traps are setup, notify parent that we are up and running
 |      kill -USR1 ${parent} >/dev/null 2>&1
 |
 |      while :; do
 |         int=0
 |         /bin/sleep ${JOBWAIT} &
 |         sleeper=${!}
 |         wait ${sleeper}
 |         sleeper=
 |         [ "${int}${hot}" = 01 ] && kill -USR1 ${parent} >/dev/null 2>&1
 |      done
 |   ) </dev/null & #>/dev/null 2>&1 &
 |   JOBREAPER=${!}

What seems to work absolutely reliable on Linux is

   i=
   trap 'i=1' USR1 # "reaper (actually a notify timer only) is up"
   (
      parent=${$}
      sleeper=
      trap '' EXIT HUP QUIT CHLD
      trap 'exit 0' INT
      trap '
         (
            trap 'exit 1' TERM
            /bin/sleep ${JOBWAIT}
            kill -USR1 ${parent} >/dev/null 2>&1
         ) </dev/null &
         sleeper=${!}
      ' USR1
      trap '
         [ -n "${sleeper}" ] && kill -TERM ${sleeper} >/dev/null 2>&1
         sleeper=
      ' USR2
      trap '
         [ -n "${sleeper}" ] && kill -TERM ${sleeper} >/dev/null 2>&1
         echo "Stopping job reaper"
         exit 0
      ' TERM

      # traps are setup, notify parent that we are up and running
      kill -USR1 ${parent} >/dev/null 2>&1

      while :; do
         sleep >/dev/null 2>&1
      done
   ) </dev/null & #>/dev/null 2>&1 &
   JOBREAPER=${!}

Unfortunately this causes all sorts of trouble on a lot of other
shells on Solaris at least, with and without backgrounding the
sleeper and waiting on it in the USR1 trap.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux