Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
acpi event control scripts running as root?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
mrodrigues
n00b
n00b


Joined: 26 Jan 2015
Posts: 7

PostPosted: Wed Feb 11, 2015 2:13 am    Post subject: acpi event control scripts running as root? Reply with quote

I'm using acpi to act on events from media keys like, mute, volumeup, volumedown, etc. I had it all working by adding some entries to /etc/acpi/default.sh. I recently added controls for brightness, and they work, but my volume control has stopped working. If I run the default.sh script manually as my regular user it works, so I suspect the problem is it's being run as root by acpi. However, I'm not sure what changed to cause this.

Permissions on both the vol.sh and backlight.sh scripts are identical.

Here's my configs/scripts:

/etc/acpi/actions/vol.sh:
Code:
#!/bin/sh
step=5

case $1 in
   -) amixer set Master $step-;;
   +) amixer set Master $step+;;
   t) amixer set Master toggle;;
esac


/etc/acpi/actions/backlight.sh:
Code:
#!/bin/bash
bldb='/sys/class/backlight/intel_backlight/brightness'
step=25
current=`cat $bldb`
new=$current
if [ "$1" == "up" ];then
   new=$(($current + $step))
elif [ "$1" == "down" ];then
   new=$(($current - $step))
fi
if [ $new -le 0 ];then
   new=0
fi
echo $new > $bldb
current=`cat $bldb`


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

set $*

group=${1%%/*}
action=${1#*/}
device=$2
id=$3
value=$4

log_unhandled() {
   logger "ACPI event unhandled: $*"
}

case "$group" in
   button)
      case "$action" in
         power)
            /etc/acpi/actions/powerbtn.sh
            ;;

         # if your laptop doesnt turn on/off the display via hardware
         # switch and instead just generates an acpi event, you can force
         # X to turn off the display via dpms.  note you will have to run
         # 'xhost +local:0' so root can access the X DISPLAY.
         lid)
            #xset dpms force off
            case "$id" in
               close) hibernate-ram;;
               open) :;;
               *) uhd $*;;
            esac
            ;;
         volumeup)
            /etc/acpi/actions/vol.sh +
            ;;
         volumedown)
            /etc/acpi/actions/vol.sh -
            ;;
         mute)
            /etc/acpi/actions/vol.sh t
            ;;
         *)   log_unhandled $* ;;
      esac
      ;;

   ac_adapter)
      case "$value" in
         # Add code here to handle when the system is unplugged
         # (maybe change cpu scaling to powersave mode).  For
         # multicore systems, make sure you set powersave mode
         # for each core!
         #*0)
         #   cpufreq-set -g powersave
         #   ;;

         # Add code here to handle when the system is plugged in
         # (maybe change cpu scaling to performance mode).  For
         # multicore systems, make sure you set performance mode
         # for each core!
         #*1)
         #   cpufreq-set -g performance
         #   ;;

         *)   log_unhandled $* ;;
      esac
      ;;
   video)
      case "$action" in
         brightnessdown)
            /etc/acpi/actions/backlight.sh down
         ;;
         brightnessup)
            /etc/acpi/actions/backlight.sh up
         ;;
         *)   log_unhandled $* ;;
      esac
      ;;

         

   *)   log_unhandled $* ;;
esac
Back to top
View user's profile Send private message
Schnulli
Guru
Guru


Joined: 25 Jun 2010
Posts: 320
Location: Bremen DE

PostPosted: Fri Feb 13, 2015 1:08 am    Post subject: Reply with quote

interesting !
when i use my "small keyboard" and turn down the volume, its dead even i turn it louder, only chance to get it again working is using alsa-mixer in a console window to get the sound back.... seems to me like a bug somewhere ;)

Someone remembers the CPP trouble with sound??? Something that points in that direction?
Back to top
View user's profile Send private message
mrodrigues
n00b
n00b


Joined: 26 Jan 2015
Posts: 7

PostPosted: Fri Feb 13, 2015 2:43 am    Post subject: Reply with quote

I'm pretty sure it's a permissions thing. If I open alsamixer as root I can see the keys working. If I run alsamixer or pavucontrol as my user, the volume stays where it is. I think I might just have to change the command to mute and change the volume on a different mixer, but it worked before.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Fri Feb 13, 2015 8:58 am    Post subject: Re: acpi event control scripts running as root? Reply with quote

mrodrigues ... its probably simpler to do the following:

Code:
   volumeup)
      /usr/bin/amixer set Master 5%+
      ;;
   volumedown)
      /usr/bin/amixer set Master 5%-
      ;;
   mute)
      /usr/bin/amixer -q set Master toggle
      ;;

As for your backlight.sh ... any reason why you didn't use the one I provided previously?

best ... khay
Back to top
View user's profile Send private message
mrodrigues
n00b
n00b


Joined: 26 Jan 2015
Posts: 7

PostPosted: Sat Feb 14, 2015 1:16 am    Post subject: Re: acpi event control scripts running as root? Reply with quote

khayyam wrote:
mrodrigues ... its probably simpler to do the following:

Code:
   volumeup)
      /usr/bin/amixer set Master 5%+
      ;;
   volumedown)
      /usr/bin/amixer set Master 5%-
      ;;
   mute)
      /usr/bin/amixer -q set Master toggle
      ;;

As for your backlight.sh ... any reason why you didn't use the one I provided previously?

best ... khay


Turns out I had the card configured for Digital output. I switched to Analog and it started working again. Thanks for the simplified setup.

As for the backlight, I didn't know you had previously provided one. I assume you're referencing the thread here: https://forums.gentoo.org/viewtopic-t-1008722-view-previous.html?sid=30c210749954d580202a59c565fed3df

Your script looks better, thanks!
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Sat Feb 14, 2015 10:06 am    Post subject: Re: acpi event control scripts running as root? Reply with quote

mrodrigues wrote:
Turns out I had the card configured for Digital output. I switched to Analog and it started working again. Thanks for the simplified setup.

mrodrigues ... you're welcome ... and pleased you solved it.

mrodrigues wrote:
As for the backlight, I didn't know you had previously provided one. I assume you're referencing the thread here: [...] Your script looks better, thanks!

hehe ... I didn't know I had such a good memory ... I wasn't actually sure it was you. Anyhow, again, you're welcome.

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum