You are not logged in.

#1 2010-12-21 13:47:40

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Run vlock during suspend/hibernate?

Hi all, I'm trying to get my laptop to lock as it's being suspended.  Here's what I've tried so far:

/etc/pm/sleep.d/10-vlock

#!/bin/bash

case $1 in
  suspend | hibernate)
    /usr/bin/vlock -an &
  ;;
esac

Which does indeed lock all tty's as desired, but my laptop never actually goes to sleep.  The sleep LED blinks, but that's it.  I can't actually unlock at this point, I need a hard reboot.  It's also locking as root, but that was expected and something I can deal with later. smile

I realize that I could have it run during resume/thaw, however that's not quite ideal for me, as it does allow some access and visibility to my workspace during resume, if only for a short time.

Thanks for any help.

Last edited by MkFly (2010-12-21 13:49:14)

Offline

#2 2010-12-21 16:09:07

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

I'm suffering the same problem and never really fixed it. Some special mechanism in vlock seems to block some aspects of the system.

But changing your script to:

#!/bin/bash

case $1 in
  resume | thaw)
    /usr/bin/vlock -an &
  ;;
esac

should lock the screen, after waking your computer. For this, I would also suggest, that you rename it to "/etc/pm/sleep.d/99-vlock", beacuse this way it's the first script that gets executed after the wake-up.

You might also wan't to substitute the lines inside the script's case switch with the follwing lines, to avoid seeing the screen for a short flash, before it gets locked:

suspend | hibernate)
  fgconsole > /tmp/console.pm
  chvt 45
;;
resume | thaw)
  /usr/bin/vlock -an
  chvt `cat /tmp/console.pm`
  rm -f /tmp/console.pm
;;

But hopefully someone will enlighten us two, what in vlock causes the problem, and how to really fix it.

Offline

#3 2010-12-23 02:28:51

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

@ber_t,

Thanks! That's a lot nicer than what I was using. But why is 99 the first to be executed and not 00?

Is there a way to temporarily disable manual VT switching?  So that way even when the system is resumed, a person can't just switch back to my workspace during that small window before vlock kicks in?

Offline

#4 2010-12-23 19:52:04

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

MkFly wrote:

Thanks! That's a lot nicer than what I was using. But why is 99 the first to be executed and not 00?

From the pm-suspend man-page:
/etc/pm/sleep.d, /usr/lib/pm-utils/sleep.d Programs in these directories (we call them hooks) are combined and executed in C sort order before suspend and hibernate with as argument 'suspend' or 'hibernate'. Afterwards they are called in reverse order with argument 'resume' and 'thaw' respectively.

MkFly wrote:

Is there a way to temporarily disable manual VT switching?  So that way even when the system is resumed, a person can't just switch back to my workspace during that small window before vlock kicks in?

I don't know how to disable vt switching, but it's not really necessary. I've tried to switch back to the original console before vlock gets started and it seems to be impossible. And even if a person succeeds in doing so, he will see your screen only for a very short time, because vlock gets started almost immediately.

Offline

#5 2010-12-23 20:35:29

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

ber_t wrote:

Afterwards they are called in reverse order with argument 'resume' and 'thaw' respectively.

Ah.

ber_t wrote:

I don't know how to disable vt switching, but it's not really necessary. I've tried to switch back to the original console before vlock gets started and it seems to be impossible.

I managed to do it the first time I tried.  Resumed, hit Ctrl+Alt+F7, and there was my workspace.  True, it was only there for less than a second, but I'd still like to remove the possibility.

Offline

#6 2010-12-24 17:47:14

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

The only possibility I've found is to write a C program using the ioctl VT_LOCKSWITCH or VT_PROCESS mechanism. vlock btw is using VT_PROCESS.
But using such a tool would make it impossible to use vlock with the '-n' switch, because it requires vlock to be able to switch consoles.

So, if you really need it, then you have to write your own vlock replacement. It's not that hard, it only took me about two hours, the last time I've tried it.

Offline

#7 2011-01-09 07:49:47

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

Thanks ber_t, I may end up doing just that.  Let me know if you have any other insights or ideas into this one!

Offline

#8 2011-01-09 13:47:36

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

I used some of my freetime last week to study vlocks source and to find a fix for its hibernate/suspend issue. After failing at that, I used the rest of the time to write a decent alternative to vlock: https://github.com/muennich/physlock (it's also in the AUR).

It's not complete yet, for instance it lacks the possibility to disable sysrq, but I'm using it for quite some time now and never had any problem. Feel free to try it and please contact me, if you experience any trouble.

Offline

#9 2011-01-11 06:28:43

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

ber_t wrote:

I used some of my freetime last week to study vlocks source and to find a fix for its hibernate/suspend issue. After failing at that, I used the rest of the time to write a decent alternative to vlock: https://github.com/muennich/physlock (it's also in the AUR).

It's not complete yet, for instance it lacks the possibility to disable sysrq, but I'm using it for quite some time now and never had any problem. Feel free to try it and please contact me, if you experience any trouble.

Awesome, I'll be testing that out this weekend (or maybe this week if time permits).  I'm sure I can learn something from your code.

Offline

#10 2011-01-12 00:57:43

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

Ah, I think I misread your post.  I thought you had written a vlock alternative that would let us lock and then suspend/hibernate, appears not to be the case. sad

Though I actually like your unlocking procedure better (U for user and R for root).

Offline

#11 2011-01-12 09:12:46

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

Well, it's fixing your initial problem: locking your laptop while it's being suspended.
So you could use it inside a sleep.d-script similiar to that from your first post:

/etc/pm/sleep.d/10-physlock

#!/bin/bash

case $1 in
  suspend | hibernate)
    /usr/sbin/physlock -d
  ;;
esac

Offline

#12 2011-01-12 17:14:44

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

ber_t wrote:

Well, it's fixing your initial problem: locking your laptop while it's being suspended.
So you could use it inside a sleep.d-script similiar to that from your first post:

/etc/pm/sleep.d/10-physlock

#!/bin/bash

case $1 in
  suspend | hibernate)
    /usr/sbin/physlock -d
  ;;
esac

Just gave that a go, it's giving me the same results as vlock.  Consoles lock just fine, but the laptop never goes to sleep.

EDIT: That does work, very nice! Thanks. smile

There's two problems (one was an existing problem I had with vlock):

1. If I lock my screen with physlock, or resume from sleep but leave the consoles locked, I'd like to let the computer go back to sleep by closing the lid on my laptop.  If I close it now while it's locked, the sleep LED starts blinking (indicating it's trying to sleep), but it never gets there.

2. I have some scripts in /etc/pm/sleep.d that I run during resume/thaw, but I only want them to run after the screen is unlocked.  With vlock, that worked, because it seemed to be waiting for vlock to finish/exit before continuing on with the scripts.

Thanks again for sharing, ber_t.

Last edited by MkFly (2011-01-12 17:26:39)

Offline

#13 2011-01-13 09:31:04

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Run vlock during suspend/hibernate?

You can only get one problem solved. If you want to lock the computer before it goes to suspend, than you have to use physlock with the -d switch. I have written a small suspend script, so I don't use pm-suspend myself. But I did get it to suspend on a lid-close event while the screen is locked. Here is an equivalent sleep.d-script, which might solve your 1st problem:

/etc/pm/sleep.d/10-physlock

#!/bin/bash

case $1 in
  suspend | hibernate)
    if ! pidof physlock > /dev/null; then
      /usr/sbin/physlock -d
    fi
  ;;
esac

If you want to solve your 2nd problem, than you have to stick with vlock and use it in a 99-... sleep.d-script just like the one in my first post, but without running vlock in the background. Of course, you could also use physlock in this scenario, but without the -d switch.

But it wouldn't be Linux, if you couldn't solve both of your problems with a very hackish workaround, right? Use the script from above and also create the following:

/etc/pm/sleep.d/99-physlock-block

#!/bin/bash

case $1 in
  resume | thaw)
    while pidof physlock > /dev/null; do
      sleep 1
    done
  ;;
esac

It just blocks all other resume/thaw actions in sleep.d/ until the computer gets unlocked. But again, I consider this a dirty workaround!

Offline

#14 2011-01-13 17:48:21

MkFly
Member
From: Mars
Registered: 2009-12-10
Posts: 141

Re: Run vlock during suspend/hibernate?

Yeah, I think I'll skip the dirty part. smile But thanks for the idea of using pidof, that should work great.

EDIT: With pidof checking to see if physlock is already running, everything works great and as-expected.  Even if I manually lock, then close the lid, suspend/resume works great. big_smile

Last edited by MkFly (2011-01-13 22:31:36)

Offline

Board footer

Powered by FluxBB