LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-05-2016, 06:01 PM   #1
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Rep: Reputation: 202Reputation: 202Reputation: 202
-current: how to suspend when closing the lid on the laptop?


Dipping my toes into current for the first time, and (almost)everything is going great!
Went from 14.2 updated install to current with last updates on Thu Jul 28 19:44:25 UTC 2016 per changelog.

No desktop environment installed (no KDE, no XFCE), running xmonad.
Goal:suspend to ram on laptop lid close; resume to screen locked by xscreensaver on lid open.
How far I got:I can suspend to ram sucessfully. Upon resume , no locked screen, and second suspend kicks in after resume. :-(
Configs:
Code:
[root@~]# cat /etc/acpi/events/lid 
event=button/lid
action=/etc/acpi/events/s2ram.sh
Code:
[root@~]# cat /etc/acpi/events/s2ram.sh
#!/bin/sh
/usr/bin/xscreensaver-command -lock && /usr/sbin/pm-suspend
Code:
[root@~]# ls -lahs /etc/acpi/events/s2ram.sh
4.0K -rwxr-xr-x 1 root root 72 Aug  5 14:20 /etc/acpi/events/s2ram.sh*
Running sh /etc/acpi/events/s2ram.sh by itself via command line works as expected, and with NO second suspend. How is it not being called correctly from action=/etc/acpi/events/s2ram.sh ???
 
Old 08-05-2016, 06:54 PM   #2
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 5,539

Rep: Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287Reputation: 3287
I'm guessing it executes both of them, since there is event action in there. When events happen, I assume the acpi program will run everything in that directory, and it uses the event and action attributes to determine what needs to be run.

I would suggest moving your s2ram.sh script to /usr/local/bin/, and then just reference that in your action section under your lid handler.
 
Old 08-05-2016, 07:11 PM   #3
OldHolborn
Member
 
Registered: Jul 2012
Distribution: Slackware
Posts: 173

Rep: Reputation: 148Reputation: 148
You might find you have events under lid

On my netbook I have an events chain

button/lid/LID/open
button/lid/LID/close

lid alone would trigger on either opening or closing as would lid/LID

You need to break it down further still

eg ( I dump it all in acpi_handler.sh )


Code:
logger ACPI Event $1 $2 $3 $4 $5

case "$1" in
  button)
    case "$2" in
      lid)
        case "$3" in
          LID)
            case $4 in
              close)
                logger LID CLOSED
                /etc/acpi/hibernate.sh
                ;;
              open)
                logger LID OPEN $4 $5 is not defined
                ;;
              *)
                logger LID WOBBLE $1 $2 $3 $4 $5 is not defined!!!
                ;;
Yes, it is rather horrible to read, this is an excerpt, the whole thing is worse...

But it should give you an idea of how it breaks down

On closing and reopening and restarting, this appears in the logs ( I don't have it set to automatically restart )

root: ACPI Event button lid LID close
root: LID CLOSED
kernel: [966054.172087] ACPI: Preparing to enter system sleep state S4
kernel: [966054.173027] ACPI : EC: EC stopped
kernel: [966054.233404] ACPI : EC: EC started
kernel: [966054.298493] ACPI: Waking up from system sleep state S4
kernel: [966054.435051] rtc_cmos 00:01: System wakeup disabled by ACPI
root: ACPI Event PNP0C14:00 000000bc 00000000
root: ACPI group PNP0C14:00 / action 000000bc is not defined
root: ACPI Event button lid LID open
root: LID OPEN open is not defined

Yes, there is redundant stuff in there, I was learning it myself, eg $5 was only because I wanted as much info as possible, not seen any in this position yet. And the wobble? well I hope never to!

Last edited by OldHolborn; 08-05-2016 at 07:16 PM. Reason: code tags
 
Old 08-05-2016, 07:45 PM   #4
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Original Poster
Rep: Reputation: 202Reputation: 202Reputation: 202
bassmadrigal,
Very strange. Your suggestion worked initially. I restarted /etc/rc.d/rc.rc.acpid and it worked perfectly. Then I rebooted, got into X11, and nothing happened when I closed the lid. Laptop stayed powered on.

OldHolborn,
Thanks for that suggestion. I'll give it a try as soon as I stop crying inside.
Three days of researching this and I'm just about to lose it...
 
Old 08-05-2016, 09:34 PM   #5
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Original Poster
Rep: Reputation: 202Reputation: 202Reputation: 202
OldHolborn,
As with bassmadrigal's suggestion, your solution seemed to work initially.
Here's my current config state (which does not suspend on close).
With the /etc/acpi/events/lid file as so:
Code:
event=button/lid
action=/usr/local/bin/s2ram.sh
...I would get the second suspend, so I removed it and have now only:

Code:
[root@~]# cat /etc/acpi/acpi_handler.sh 
#!/bin/sh
# Default acpi script that takes an entry for all actions

IFS=${IFS}/
set $@

logger ACPI Event $1 $2 $3 $4 $5

case "$1" in
  button)
    case "$2" in
      lid)
        case "$3" in
          LID)
            case $4 in
              close)
                logger LID CLOSED
                /usr/local/bin/s2ram.sh
                ;;
              open)
                logger LID OPEN $4 $5 is not defined
                ;;
              *)
                logger LID WOBBLE $1 $2 $3 $4 $5 is not defined!!!
                ;;
esac
and
Code:
[root@~]# cat /usr/local/bin/s2ram.sh 
#!/bin/sh
/usr/bin/xscreensaver-command -lock && /usr/sbin/pm-suspend
In this state, nothing happens when lid is closed.
May I just say: "This is horribly frustrating"
I really expected this to be a trivial item on this the 71st day of Confusion in the YOLD 3182!
EDIT: I'm not married to the acpi daemon... if there are any other ways aside from installing XFCE and running it's "power manager" in the background, I am open to them!

Last edited by STDOUBT; 08-05-2016 at 09:35 PM.
 
Old 08-05-2016, 09:48 PM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 5,052

Rep: Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773Reputation: 1773
Quote:
Upon resume , no locked screen, and second suspend kicks in after resume
I saw this a while back and am still using the acpihandler.sh script that I posted then.
 
Old 08-06-2016, 12:51 AM   #7
aldorgan
LQ Newbie
 
Registered: Jul 2016
Posts: 15

Rep: Reputation: Disabled
create file /etc/acpi/events/lid

Code:
event=button/lid (LID)
action=/usr/sbin/pm-suspend
this works for me under no Desktop Enviroment, i'm running i3-wm
 
Old 08-06-2016, 01:37 AM   #8
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Original Poster
Rep: Reputation: 202Reputation: 202Reputation: 202
allend,
I tried your /etc/acpi/acpi_handler.sh script modified for my environment (pm-suspend instead of hibernate), but for whatever reason, it did nothing.

aldorgan, I have tried your solution and many variations, and it works perfectly to suspend my laptop, but when I open the lid, there is no xscreensaver lock, which I want to make work upon resume from suspend. Otherwise, anyone can open my suspended laptop and access my system.

I appreciate the suggestions!
Still looking for other options.
 
Old 08-06-2016, 04:08 AM   #9
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 14.2 + Multilib
Posts: 1,427

Rep: Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834Reputation: 834
OldHolborn --

There are four case .. in statements but no closing esac statements in the script you posted below.

Are there more lines for your script ?

Thanks.

-- kjh


Quote:
Originally Posted by OldHolborn View Post
Code:
logger ACPI Event $1 $2 $3 $4 $5

case "$1" in                    # case statement #1
  button)
    case "$2" in                # case statement #2
      lid)
        case "$3" in            # case statement #3
          LID)
            case $4 in          # case statement #4
              close)
                logger LID CLOSED
                /etc/acpi/hibernate.sh
                ;;
              open)
                logger LID OPEN $4 $5 is not defined
                ;;
              *)
                logger LID WOBBLE $1 $2 $3 $4 $5 is not defined!!!
                ;;

Last edited by kjhambrick; 08-06-2016 at 04:12 AM. Reason: snip another line
 
Old 08-06-2016, 10:55 AM   #10
OldHolborn
Member
 
Registered: Jul 2012
Distribution: Slackware
Posts: 173

Rep: Reputation: 148Reputation: 148
Yep

Code:
#!/bin/sh
# Default acpi script that takes an entry for all actions

IFS=${IFS}/
set $@

logger ACPI Event $1 $2 $3 $4 $5

case "$1" in
  button)
    case "$2" in
      lid)
        case "$3" in
          LID)
            case $4 in
              close)
                logger LID CLOSED
                /etc/acpi/hibernate.sh
                ;;
              open)
                logger LID OPEN $4 $5 is not defined
                ;;
              *)
                logger LID WOBBLE $1 $2 $3 $4 $5 is not defined!!!
                ;;
            esac
            ;;
        esac    
        ;;
      power) 
        /sbin/init 0
        ;;
      mute)
        su `ps aux | grep [Pp]ulseaudio | awk '{print $1}'` -c 'amixer set Master toggle'
        logger mute button
        ;; 
      sleep)
        logger SLEEP button pressed
        /etc/acpi/suspend.sh
        ;;
      volumeup)
        su `ps aux | grep [Pp]ulseaudio | awk '{print $1}'` -c 'pactl set-sink-volume 0 +5%'
        logger volume up button
        ;;
      volumedown)
        su `ps aux | grep [Pp]ulseaudio | awk '{print $1}'` -c 'pactl set-sink-volume 0 -5%'
        logger vulume down buttona
        ;;
      *) logger "ACPI action $2 is not defined"
         ;;
    esac
    ;;
  *)
    logger "ACPI group $1 / action $2 is not defined"
    ;;
esac
And hibernate.sh itself

Oh!

Code:
#!/bin/sh

#dbus-send --system --print-reply --dest="org.freedesktop.UPower" \
#       /org/freedesktop/UPower org.freedesktop/UPower.Hibernate

/usr/sbin/pm-hibernate
I really should have put a comment in as to why I did that...

Answer.. fluxbox

Last edited by OldHolborn; 08-06-2016 at 11:08 AM. Reason: answer
 
Old 08-06-2016, 01:25 PM   #11
OldHolborn
Member
 
Registered: Jul 2012
Distribution: Slackware
Posts: 173

Rep: Reputation: 148Reputation: 148
just seeing if I could get it to work...

I note you have xmonad in your Distributions tag so things will be a little different

xscreensaver needs to be running so add ( before the exec ) to your .fluxbox/startup
xscreensaver -nosplash &

The command to lock must be done as the same user and acpi is root so my suspend.sh now reads

Code:
su `ps aux | grep [x]screensaver | awk '{print $1}'` -c '/usr/bin/xscreensaver-command -lock &' &&  /usr/sbin/pm-suspend
resume from hibernate has to pass through luks password so no need to enter two passwords there

Please bear this in mind...
https://www.jwz.org/xscreensaver/faq.html#no-ctl-alt-bs
 
Old 08-06-2016, 08:41 PM   #12
STDOUBT
Member
 
Registered: May 2010
Location: Stumptown
Distribution: Slackware -current 32bit!
Posts: 537

Original Poster
Rep: Reputation: 202Reputation: 202Reputation: 202
Solved

OK. I figured out a solution that Works On My Machine™ even after a reboot!
(Well, resume is a tad bit slower than I'm used to, but I chalk that up to my move from a 7200RPM HDD to a 5400RPM HDD).
I used the acpi_listen command to discover what the system sees when the laptop lid is closed and then opened. It reported "button/lid LID close" and "button/lid LID open".
So, here are the files involved:
/etc/acpi/events/lid_close:
Code:
event=button/lid LID close
action=/usr/sbin/pm-suspend
/etc/acpi/events/lid_open:
Code:
event=button/lid LID open
action=/etc/pm/sleep.d/66screenlock &
/etc/pm/sleep.d/66screenlock (must be executable):
Code:
#!/bin/bash
#
# 66screenlock: lock screen at suspend with xscreensaver
#

IS_ACTIVE="$( pidof /usr/bin/xscreensaver )"

 case $1 in
    hibernate)
        # not required.
        ;;
    suspend)
        # check if xscreensaver is running. if not, just skip on.
        if [ -z "$IS_ACTIVE" ]
        then :
        else
             # run the lock command as the user who owns xscreensaver process,
             # and not as root, which won't work.
             su "$( ps aux | grep xscreensaver | grep -v grep | grep $IS_ACTIVE | awk '{print $1}' )" \
             -c "/usr/bin/xscreensaver-command -lock" &
        fi
        ;;
    thaw)
        # not required.
        ;;
    resume)
        # not required.
        ;;
    *) exit $NA
        ;;
 esac
I do not know if "/etc/pm/sleep.d/66screenlock" needs to be in that directory or even be named "66screenlock".
That's just how I found it on some random Gentoo forum so there we have it!
Happy Again!
 
1 members found this post helpful.
Old 08-07-2016, 12:47 AM   #13
Paulo2
Member
 
Registered: Aug 2012
Distribution: Slackware64 -current (started with 13.37(32))
Posts: 413

Rep: Reputation: 126Reputation: 126
sometime ago I had the habit not start X and do things on the console,
so instead push the power button and close the lid to turn off (not suspend),
I used to run this line in background and just close the lid.
while true;do [[ $(cat /proc/acpi/button/lid/LID0/state ) =~ closed ]] && shutdown -h now;sleep 5;done&
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Slackware 14.2 - how to suspend when closing the lid on the laptop? aldorgan Slackware 8 09-06-2016 12:27 AM
logind.conf not working, closing lid will not suspend laptop 4art4 Linux - Laptop and Netbook 3 08-18-2015 07:26 PM
Hp 15 laptop with Mint 17- closing lid Suspend) dose not reduce power usage abbarnett Linux - Laptop and Netbook 1 10-03-2014 03:48 PM
[SOLVED] how can I prevent my laptop from suspend or hibernate when closing its lid? TroN-0074 Linux - Newbie 8 03-31-2012 10:35 AM
How to suspend on lid closing? jerrybasham Linux - Laptop and Netbook 4 06-29-2007 01:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration