Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 Dec 2023 21:15:11 +0100
From:      Steffen Nurpmeso <steffen@sdaoden.eu>
To:        freebsd-hackers@freebsd.org
Subject:   Fwd: Re: devd lid close event
Message-ID:  <20231204201511.u5fSPsTx@steffen%sdaoden.eu>

next in thread | raw e-mail | index | archive | help

--- Forwarded from Steffen Nurpmeso <steffen@sdaoden.eu> ---
Date: Mon, 04 Dec 2023 21:04:14 +0100
Author: Steffen Nurpmeso <steffen@sdaoden.eu>
From: Steffen Nurpmeso <steffen@sdaoden.eu>
To: "Dr. Amr Osman" <dr3mro@gmail.com>
Subject: Re: devd lid close event
Message-ID: <20231204200414.4PxUD8iy@steffen%sdaoden.eu>

Dr. Amr Osman wrote in
 <CAEYFr1C-f+KX99wJ21qKy8pA2D4btuJNUaX-mJStcYstNDa8uQ@mail.gmail.com>:
 |The issue now is that is activates twice, as the devd notify happens twice
 |Tried pgrep the slock but it always launches slock twice

Well for one (i have no freebsd around to truly test this) it
might be necessary to background the thing in order not to block.
(This is what i need to do on Linux, for example i now do

  volume() {
          (
          cd /
          /root/bin/volume.sh "$1"
          ) </dev/null >/dev/null 2>&1 &
  }

so that i neither have a CWD in a path of a mounted volume that
may go away upon LID close etc.  Also, due to a bug, i got piles
of dozens / hundreds of jobs in the queue, which can only be
avoided by moving the ACPI job to the background, aka by
daemonizing it.  (That it then is reparented to init/process 1 is
something i still have to think about.))

And second, if all else fails, you may need to enwrap it in
a shell script, maybe even with file locking.  (flock(1).)
Ie, my zzz.sh does in the main path

  # Neutralize $PWD to avoid umount(8) etc problems
  cd /

  if [ -f /run/.zzz.run ]; then
          logger -s -t /root/bin/zzz.sh "recursively invoked"
          exit 0
  fi
  : > /run/.zzz.run
  trap 'rm -f /run/.zzz.*' EXIT
  trap 'trap "" HUP INT QUIT TERM; exit 1' HUP INT QUIT TERM

  down_stuff
  down_check
  down_main

  [ $# -eq 0 ] && once= || once=y

  while :; do
          [ -n "$once" ] && lid_is_open && break
          once=y
          down_off
          lid_exists || break
          sleep $SLEEP &
          wait $!
  done

  # Sleep a bit to let it settle
  ( sleep .5 ) >/dev/null 2>&1
  up_main
  sleep 1
  up_stuff

Ciao,

--steffen
 -- End forward <20231204200414.4PxUD8iy@steffen%sdaoden.eu>

--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)
|
| Only in December: lightful Dubai COP28 Narendra Modi quote:
|  A small part of humanity has ruthlessly exploited nature.
|  But the entire humanity is bearing the cost of it,
|  especially the inhabitants of the Global South.
|  The selfishness of a few will lead the world into darkness,
|  not just for themselves but for the entire world.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20231204201511.u5fSPsTx>