On Wed, Feb 08, 2023 at 04:03:04PM +0100, to...@tuxteam.de wrote:
> On Wed, Feb 08, 2023 at 09:31:00AM -0500, Stefan Monnier wrote:
> > >> $ cat opt/bin/hibernate.sh
> > >> mate-screensaver-command -l      # Activates screensaver and locks
> > >>                                   the screen
> > >> sudo systemctl hybrid-sleep      # Hibernate and suspend the system. This
> > >>                                   will trigger activation of
> > >>                                   the special target unit
> > >>                                   hybrid-sleep.target.
> > [...]
> > > So it's not clear which command is causing the ssh client to hang.
> > 
> > Maybe it's simply that `hybrid-sleep` is fast enough to stop the network
> > before the SSH command completes?

Ooof.  If that's the case, then the race conditions are in the exact
opposite direction of where I was looking.  This is where having input
from people with laptop experience is priceless.

It's not trivial to fix, either, because the command in question is
being done with sudo.  We don't know how the sudo authentication is
being done (because we weren't TOLD).  If it's reading a password from
the keyboard, then the whole sudo can't be backgrounded.  But maybe
something like this would suffice:

sudo sh -c '(sleep 1; systemctl hybrid-sleep) >>"$1" 2>&1 &' x "$log"

or

sudo sh -c '(sleep 1; systemctl hybrid-sleep) >/dev/null 2>&1 &'

Of course, the sleep duration may need to be adjusted.

> Or perhaps it is synchronous and waits until successful ;-)

Can't rule it out, but the man page is VERY emphatic about that not
being true.  That would be a pretty major bug (deviation from documented
behavior).

Reply via email to