/usr/share/acpi-support/power-funcs is in acpi-support-base 0.142-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | # a micro library of helper functions for the power scripts
umask 022
PATH=$PATH:/usr/bin/X11
POWERSTATE=/var/lib/acpi-support/powerstate
# getXuser: get the user for the specified X display, or if none is
# specified, then the user for whatever X display we find.
# input: $displaynum: the X display to query
# output: $XAUTHORITY: the path to the xauth data used for connecting to the
# detected X display.
# $XUSER: the username of the user who owns the display.
getXuser() {
local plist display uid user startx pid userhome IFS
if [ "$displaynum" ]; then
display=":$displaynum"
else
display=.+
fi
user=
if [ -x /usr/bin/ck-list-sessions ]; then
uid=$(ck-list-sessions | awk 'BEGIN { unix_user = ""; } /^Session/ { unix_user = ""; } /unix-user =/ { gsub(/'\''/,"",$3); unix_user = $3; } /x11-display = '\'$display\''/ { print unix_user; exit (0); } /x11-display = '\'$display.0\''/ { print unix_user; exit (0);}')
if [ "$uid" ]; then
IFS=:
set -- $(getent passwd $uid)
user=$1
unset IFS
fi
fi
if [ -z "$user" ]; then
plist=$(pinky -fw) || pwf_error "pinky lost"
while read l; do
set -- $l
eval lastpp=\$$#
for ds in $2 $lastpp; do
case $ds in
$display)
user=$1
break
;;
esac
done
[ -z "$user" ] || break
for ds in $2 $lastpp; do
case $ds in
$display.0)
user=$1
break
;;
esac
done
[ -z "$user" ] || break
done <<-EOF
$plist
EOF
fi
if [ -z "$user" ]; then
startx=$(pgrep -n startx || :)
[ -z "$startx" ] || user=$(ps -o user --no-headers $startx || :)
fi
if [ x"$user" != x ]; then
for pid in `ps -U "$user" -o pid=`; do
if grep -z -q XAUTHORITY /proc/$pid/environ; then
XAUTHORITY="$(grep -z XAUTHORITY /proc/$pid/environ | cut -d= -f2-)"
export XAUTHORITY
break
fi
done
if [ -z "$XAUTHORITY" ]; then
userhome="$(getent passwd "$user" | cut -d: -f6)"
XAUTHORITY="$userhome/.Xauthority"
export XAUTHORITY
fi
else
export XAUTHORITY=
fi
XUSER="$user"
export XUSER
}
# getXconsole: get the information for the active X console, if any.
# calls getXuser to get information related to the logged-in user.
# input: none
# output: $XAUTHORITY: the path to the xauth data used for connecting to the
# detected X display.
# $DISPLAY: the X display
# $XUSER: the username of the user who owns the display.
getXconsole() {
local displaynum
displaynum=$(ck-list-sessions | awk 'BEGIN { active = 0; } /^Session/ { active = 0; } /active = TRUE/ { active = 1; } active && /x11-display = '\':.+\''/ { gsub(/'\':*'/,"",$3); print $3; exit (0); }')
if [ -z "$displaynum" ]; then
console=`fgconsole`;
displaynum=`ps t tty$console | sed -n -re 's,.*/Xorg .*:([0-9]+).*,\1,p'`
fi
if [ "$displaynum" ]; then
DISPLAY=":$displaynum"
export DISPLAY
getXuser
fi
}
# getState side effect: sets global variable STATE
getState() {
/usr/bin/on_ac_power
if [ $? -eq 1 ]; then
STATE=BATTERY
else
STATE=AC
fi
}
#check our state has actually changed
checkStateChanged() {
local OLDSTATE
# do we have our state stashed?
# XXX: if vaiable STATE is unset, set it to the null string
: ${STATE=${STATE:-}}
# XXX: make sure variable STATE has a non-null value
[ "$STATE" ] || getState
if [ -f "$POWERSTATE" ]; then
# XXX: unset or empty variable STATE and an existing but empty POWERSTATE file
# and the function will probably have undesired side effects
read OLDSTATE <$POWERSTATE || :
if [ "$STATE" = "$OLDSTATE" ]; then
exit 0
else
#stash the new state
# XXX: unset or empty variable STATE, will create an empty POWERSTATE file
echo "$STATE" > $POWERSTATE
fi
else
#we need to stash the new state
# XXX: unset or empty variable STATE, will create an empty POWERSTATE file
echo "$STATE" > $POWERSTATE
fi
}
HDPARM='/sbin/hdparm -q'
LIDSTATE=/var/lib/acpi-support/lidstate
|