pmud-0.10.orig/0040775000076400007640000000000007407403111013275 5ustar schmitzschmitzpmud-0.10.orig/CVS/0040775000076400007640000000000007405355740013744 5ustar schmitzschmitzpmud-0.10.orig/CVS/Root0100664000076400007640000000006307405355520014602 0ustar schmitzschmitzsleemburg@cvs.apmud.sourceforge.net:/cvsroot/apmud pmud-0.10.orig/CVS/Repository0100664000076400007640000000000607405355520016033 0ustar schmitzschmitzapmud pmud-0.10.orig/CVS/Entries0100664000076400007640000000253307405355740015300 0ustar schmitzschmitz/BUGS/1.1.1.1/Fri Dec 7 11:31:44 2001// /Batmon/1.1.1.1/Fri Dec 7 11:31:43 2001// /CHANGES/1.1.1.1/Fri Dec 7 11:31:50 2001// /COPYING/1.1.1.1/Fri Dec 7 11:31:52 2001// /INSTALL/1.1.1.1/Fri Dec 7 11:31:47 2001// /Makefile/1.1.1.1/Fri Dec 7 11:31:48 2001// /README/1.1.1.1/Fri Dec 7 11:31:43 2001// /THANKS/1.1.1.1/Fri Dec 7 11:31:52 2001// /TODO/1.1.1.1/Fri Dec 7 11:31:46 2001// /apm.h/1.1.1.1/Fri Dec 7 11:31:50 2001// /batmon.8/1.1.1.1/Fri Dec 7 11:31:50 2001// /fblevel.8/1.1.1.1/Fri Dec 7 11:31:50 2001// /fblevel.c/1.1.1.1/Fri Dec 7 11:31:50 2001// /mailinglist/1.1.1.1/Fri Dec 7 11:31:53 2001// /makerpm/1.1.1.1/Fri Dec 7 11:31:50 2001// /pmu.h/1.1.1.1/Fri Dec 7 11:31:48 2001// /pmud.8/1.1.1.1/Fri Dec 7 11:31:44 2001// /pmud.c/1.1.1.1/Fri Dec 7 11:31:46 2001// /pmud.h/1.1.1.1/Fri Dec 7 11:31:44 2001// /pmud.rc/1.1.1.1/Fri Dec 7 11:31:44 2001// /pmud.spec/1.1.1.1/Fri Dec 7 11:31:48 2001// /power.conf/1.1.1.1/Fri Dec 7 11:31:46 2001// /pwrctl/1.1.1.1/Fri Dec 7 11:31:53 2001// /pwrctl-local/1.1.1.1/Fri Dec 7 11:31:48 2001// /snooze.8/1.1.1.1/Fri Dec 7 11:31:47 2001// /snooze.c/1.1.1.1/Fri Dec 7 11:31:47 2001// /tcp.c/1.1.1.1/Fri Dec 7 11:31:48 2001// /tcp.h/1.1.1.1/Fri Dec 7 11:31:48 2001// /wakebay.c/1.1.1.1/Fri Dec 7 11:31:50 2001// /xmouse.8/1.1.1.1/Fri Dec 7 11:31:50 2001// /xmouse.c/1.1.1.1/Fri Dec 7 11:31:48 2001// D pmud-0.10.orig/CVS/Entries.Log0100664000076400007640000000002007405355740016005 0ustar schmitzschmitzA D/contrib//// pmud-0.10.orig/Makefile0100664000076400007640000000251707406743533014755 0ustar schmitzschmitz# $Id: Makefile,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $ # # $Log: Makefile,v $ # Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg # Initial CVS import of the unreleased pmud-0.8 to apmud (new project name # because of a name clash at sourceforge.net). # # Revision 1.5 2000/10/09 14:16:25 stephan # updated for pmud-0.7.1 # # Revision 1.4 2000/05/11 14:56:29 stephan # pmud 0.6 changes # # Revision 1.3 2000/03/09 12:54:35 stephan # added tcp # # Revision 1.2 2000/01/06 13:51:52 stephan # rm -> rm -f # # Revision 1.1 2000/01/06 13:48:19 stephan # Initial revision # CFLAGS = -Wall -O2 PROGS= pmud snooze wakebay fblevel xmouse all: $(PROGS) pmud: pmud.c pmud.h pmu.h $(CC) $(CFLAGS) -o pmud pmud.c snooze: snooze.c tcp.o tcp.h $(CC) $(CFLAGS) -o snooze snooze.c tcp.o wakebay: wakebay.c $(CC) $(CFLAGS) -o wakebay wakebay.c fblevel: fblevel.c $(CC) $(CFLAGS) -o fblevel fblevel.c xmouse: xmouse.c $(CC) $(CLAGS) -o xmouse xmouse.c -L/usr/X11R6/lib -lX11 tcp.o: tcp.c tcp.h $(CC) $(CFLAGS) -c tcp.c install: install -c pmud /sbin install -c snooze /sbin install -c wakebay /sbin install -c fblevel /sbin install -c xmouse /usr/X11R6/bin install -c Batmon /usr/bin install -c -D pwrctl /etc/power/pwrctl cp pmud.rc /etc/rc.d/init.d/pmud ln -s /sbin/snooze /usr/bin/apm chkconfig --add pmud clean: rm -f $(PROGS) *.o pmud-0.10.orig/BUGS0100664000076400007640000000011207404124240013747 0ustar schmitzschmitzPlease send bugs/request/questions to Thanks, Stephan pmud-0.10.orig/Batmon0100775000076400007640000002660207407055432014457 0ustar schmitzschmitz#!/usr/bin/wish -f # Copyright 1999 Paul Mackerras # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version # 2 of the License, or (at your option) any later version. # # $Id: Batmon,v 1.1.1.1 2001/12/07 11:31:43 sleemburg Exp $ # # $Log: Batmon,v $ # Revision 1.1.1.1 2001/12/07 11:31:43 sleemburg # Initial CVS import of the unreleased pmud-0.8 to apmud (new project name # because of a name clash at sourceforge.net). # # Revision 1.1 2000/01/06 13:48:19 stephan # Initial revision # global c bgcolor proc thermometer {tx0 ty0 scale max} { global c tscale titem txitem set y0 [expr {$ty0 + $scale * $max}] $c create line $tx0 $ty0 $tx0 $y0 -width 9 -capstyle round -fill black $c create oval [expr $tx0-7] $y0 [expr $tx0+7] [expr $y0+14] \ -fill red set titem [$c create line $tx0 [expr $y0+7] $tx0 $y0 -width 7 -fill red] set tscale $scale for {set t 0} {$t <= $max} {incr t 10} { set y [expr {$y0 - $scale * $t}] .c create text [expr $tx0+10] $y -text $t -anchor w \ -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* } set txitem [.c create text [expr $tx0+1] [expr $y0+20] -anchor n] } proc smallabel {x y text} { global c $c create text $x $y -anchor nw -text $text \ -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* } proc settherm {val} { global c tscale titem txitem set was [$c coords $titem] set x [lindex $was 0] set y0 [lindex $was 1] set newy [expr {$y0 - 7 - $tscale * $val}] $c coords $titem $x $y0 $x $newy $c itemconf $txitem -text $val } proc bargauge {id x0 y0 len scale off min max tick color} { global c bscale$id bitem$id bxitem$id bmax$id bcolor$id boff$id byt$id set yb [expr {$y0 + $len}] .c create line $x0 [expr $y0-2] $x0 [expr $yb+2] -width 15 set bitem$id [.c create line $x0 $yb $x0 $y0 -width 11 -fill $color] set bscale$id $scale set boff$id $off for {set v $min} {$v <= $max} {incr v $tick} { set y [expr {$yb - $scale * ($v - $off)}] .c create text [expr $x0+12] $y -text $v -anchor w \ -font -Adobe-Helvetica-Bold-R-Normal--*-100-*-*-*-*-*-* } set bxitem$id [.c create text [expr $x0+2] [expr $yb+8] -anchor n] set bmax$id $max set bcolor$id $color set byt$id $y0 } proc setgauge {id val {val2 {}}} { global c bscale$id bitem$id bxitem$id bmax$id bcolor$id bgcolor boff$id global byt$id set s [set bscale$id] set o [set boff$id] set i [set bitem$id] set was [$c coords $i] set x [lindex $was 0] set y0 [lindex $was 1] set yt [set byt$id] if {$val == ""} { global byt$id $c itemconf $i -fill $bgcolor set y $yt } else { if {$val < $o} {set val $o} $c itemconf $i -fill [set bcolor$id] set y [expr {round($y0 - $s * ($val - $o))}] if {$y < $yt} {set y $yt} } $c coords [set bitem$id] $x $y0 $x $y if {$val2 == {}} {set val2 $val} $c itemconf [set bxitem$id] -text $val2 } proc indicator {id x y w h color text} { global c iitem$id icolor$id set iitem$id [$c create rectangle $x $y [expr $x+$w] [expr $y+$h] \ -width 2 -fill $color] set t [$c create text [expr $x+$w/2] [expr $y+$h/2] -anchor c -text $text] set icolor$id $color } proc setindic {id val} { global c iitem$id icolor$id set i [set iitem$id] if $val { $c itemconf $i -fill [set icolor$id] } else { $c itemconf $i -fill black } } # The current best guess about the values we read from the PMU on the 3400, # based on measurements and observations on my 3400 with LiIon battery: # # The line we get from pmud is # flags vbat hstemp battemp current chargeused switches # # Flags is a set of 8 bits, in binary, which we number left-to-right # from 0 to 7. (Flag 0 is 0x80 in the byte we get from the PMU.) # Flag 0 indicates a LiIon battery (conjecture) # Flag 1 indicates that the `chargeused' field is valid. # It gets set when the battery is fully charged and reset when # the PMU is charging the battery. # Flag 2 indicates that the battery is fully charged. # Flag 5 indicates that the battery is present. # Flag 6 indicates that the battery is being charged. # Flag 7 indicates that the AC is connected. # # The vbat field gives the battery voltage. My current best estimate # is that the actual battery voltage is vbat * 0.0265 + 7.2665 V. # # The hstemp field is the temperature of the CPU heatsink in Celsius. # The battemp field is the temperature of the battery in Celsius. # # The current field gives the rate of power consumption in some unknown # units. This field is valid only when running from the battery. It # seems to freeze when running off the AC mains. # # The chargeused field integrates the current field while running # off the battery. It resets to 0 when the battery is fully charged. # A current of x increases the chargeused field by x in 252.6 seconds. # It ranges from 0 for a fully charged battery to around 6500 when flat. proc readbat_3400 {f} { global c chargei bgcolor curri btempi ctempi tli set line [gets $f] puts $f "" flush $f if {[llength $line] < 6} return set flags [lindex $line 0] for {set i 0} {$i < 8} {incr i} { set flag$i [string index $flags $i] } setindic bpres $flag5 setindic ac $flag7 if {$flag6} { $c itemconf $chargei -fill red } else { $c itemconf $chargei -fill $bgcolor } set current [lindex $line 4] set tl {} set switches [lindex $line 6] if {$flag5} { # battery is installed set braw [lindex $line 1] set v [expr {$braw * 0.0265 + 7.2665}] setgauge bat $v [expr {round($v*10) / 10.0}] # estimate charge used from voltage if {!$flag7} { # running off battery, compensate for drop at high current if {$current > 200} { set braw [expr {$braw + ($current - 200) * 0.15}] } } elseif {$flag6} { set braw [expr {$braw - 10}] } set i [expr {(330 - $braw) / 10.0}] set j [expr int($i)] if {$j <= 0} { set charge 0 } elseif {$j >= 21} { set charge 6500 } else { set xx [lrange \ { 0 275 850 1680 2325 2765 3160 3500 3830 4115 4360 4585 4795 4990 5170 5340 5510 5710 5930 6150 6370 6500 } $j [expr $j+1]] set charge [lindex $xx 0] set xx [expr {[lindex $xx 1] - $charge}] set charge [expr {$charge + ($i - $j) * $xx}] } set charge [expr {round(1000 - $charge / 6.5) / 10.0}] if {$flag1} { set pcharge [lindex $line 5] if {$pcharge > 6500} {set pcharge 6500} set pcharge [expr {round(1000 - $pcharge / 6.5) / 10.0}] if {$pcharge < $charge} {set charge $pcharge} } setgauge bchg $charge if {!$flag7 && $current > 0} { set timeleft [expr {int($charge * 274 / $current)}] set tl [format "%d:%.2d" [expr $timeleft/60] [expr $timeleft%60]] } } else { setgauge bat {} setgauge bchg {} } $c itemconf $tli -text $tl # settherm [lindex $line 2] for {set b 0} {$b < 8} {incr b} { setindic b$b [set flag$b] } $c itemconf $curri -text $current $c itemconf $ctempi -text [lindex $line 2] if {[string index $flags 5]} { $c itemconf $btempi -text [lindex $line 3] } else { $c itemconf $btempi -text {} } } # On the lombard, the line we get from pmud is # S {flags charge maxcharge ibat vbat} {(same for R batt)} # # Flags is a set of 3 bits, in binary, which we number left-to-right # from 0 to 2. (Flag 0 is 1 in the byte we get from the PMU.) # Flag 0 indicates that the AC is connected. # Flag 1 indicates that the battery is being charged. # Flag 2 indicates that the battery is present. # # The vbat field gives the battery voltage in millivolts maybe. # The ibat field gives the battery current, positive when charging. proc readbat_g3 {f} { global c chargei bgcolor curri volti tli acpower set line [gets $f] puts $f "" flush $f if {[llength $line] < 3 || [lindex $line 0] != "S"} return set lbat [lindex $line 1] set rbat [lindex $line 2] set lflags [lindex $lbat 0] set rflags [lindex $rbat 0] for {set i 0} {$i < 3} {incr i} { set lflag$i [string index $lflags $i] set rflag$i [string index $rflags $i] set flag$i [expr {[set lflag$i] | [set rflag$i]}] } setindic bpres $flag2 setindic ac $flag0 if {$flag1} { $c itemconf $chargei -fill red } else { $c itemconf $chargei -fill $bgcolor } set current {} set voltage {} set charge 0 if {$lflag2} { set charge [lindex $lbat 1] set current [lindex $lbat 3] set voltage [format "%.2f" [expr {[lindex $lbat 4]/1000.0}]] set q [expr {round([lindex $lbat 1]*1000.0 / [lindex $lbat 2]) / 10.0}] setgauge bchgl $q } else { setgauge bchgl {} } if {$rflag2} { set charge [expr {$charge + [lindex $rbat 1]}] set curr [lindex $rbat 3] if {$current == "" || abs($curr) > abs($current)} { set current $curr set voltage [format "%.2f" [expr {[lindex $rbat 4]/1000.0}]] } set q [expr {round([lindex $rbat 1]*1000.0 / [lindex $rbat 2]) / 10.0}] setgauge bchgr $q } else { setgauge bchgr {} } set tl {} if {!$flag0 && $current != "" && $current < 0} { set mins [expr {int($charge * 59.2 / -$current)}] set tl [format "%d:%.2d" [expr $mins/60] [expr $mins%60]] } $c itemconf $tli -text $tl $c itemconf $curri -text $current $c itemconf $volti -text $voltage if {$flag0 != $acpower} { global dpms_ac dpms_bat set acpower $flag0 set t [expr {$acpower? $dpms_ac: $dpms_bat}] if {$t != ""} { catch {exec /usr/X11R6/bin/xset dpms 0 0 $t} } } } proc dosleep {} { global batf puts $batf "sleep" flush $batf } set batf [socket localhost 879] set line [gets $batf] if {$line == ""} exit set c [canvas .c -width 90 -height 240] pack .c global bgcolor set bgcolor [.c cget -background] global acpower dpms_ac dpms_bat set acpower {} set dpms_ac 900 set dpms_bat 180 indicator ac 8 8 20 15 green AC indicator bpres 54 8 30 15 blue Batt global chargei set chargei [$c create line 29 15 53 15 -width 9 -fill $bgcolor -arrow last] set pmuvers [lindex $line 2] if {$pmuvers >= 10} { smallabel 6 33 "Left" smallabel 52 33 "Right" bargauge bchgl 18 55 100 1 0 0 100 20 green bargauge bchgr 61 55 100 1 0 0 100 20 green global curri volti tli smallabel 6 184 "Time left:" set tli [$c create text 85 184 -anchor ne] smallabel 6 200 "Current:" set curri [$c create text 85 200 -anchor ne] smallabel 6 216 "Voltage:" set volti [$c create text 85 216 -anchor ne] fileevent $batf read "readbat_g3 $batf" } elseif {$pmuvers == 9} { # 3400/2400/3500 .c conf -height 270 smallabel 6 33 "Charge" smallabel 52 33 "Voltage" bargauge bchg 18 55 100 1 0 0 100 20 green bargauge bat 63 55 100 15.4 10.5 11 17 1 blue for {set b 0} {$b < 8} {incr b} { indicator b$b [expr 7+$b*10] 255 10 10 \ [lindex {yellow white cyan orange orange blue red green} $b] "" } global curri btempi ctempi tli smallabel 6 184 "Time left:" set tli [$c create text 85 184 -anchor ne] smallabel 6 200 "Current:" set curri [$c create text 85 200 -anchor ne] smallabel 6 216 "CPU temp:" set ctempi [$c create text 85 216 -anchor ne] smallabel 6 232 "Bat temp:" set btempi [$c create text 85 232 -anchor ne] fileevent $batf read "readbat_3400 $batf" } else { puts "Unknown PMU version $pmuvers" exit } set lower .lower frame $lower -bd 2 -relief sunk button $lower.snooze -text "Sleep" -command dosleep pack $lower.snooze pack $lower -fill x pmud-0.10.orig/CHANGES0100664000076400007640000001123007407066176014302 0ustar schmitzschmitzpmud-0.9.1 -> pmud-0.10.1 - new: after closing lid, pwrctl is called with lid-closed after opening lid, pwrctl is called with lid-opened - new: -u flag. Use AF_UNIX sockets in stead of TCP. Note that Batmon does not support this. - new: beep just before sleep and right after waking and on errors. Code stolen from pcmcia-cs-3.1.30:cardmgr/cardmgr.c Author David Hinds and modified - update: fblevel.8 now indicates the minimum and maximum values, thanks to Paul J. Lucas pmud-0.8.1 -> pmud-0.9.1 - new: -K flag. Put machine in sleep when lid closed and no ac power. if lid closed and on ac power, then only power off screen - new: on close of lid or sleep, power off screen on wakeup and only if lid is opened, put screen power on - fixed: close all open file descriptors before running pwrctl - fixed: iBook2 jittery on trackpad, thanks to Joe Buczek - new: added fnset.c to contrib - fixed: set charging indication on either of both batteries, thanks to Seanano - fixed: DEVFS support, thanks to Chad Miller - fixed: %doc errors in pmud.spec, thanks to "Calum Selkirk" pmud-0.7.1 -> pmud-0.8.1 - new: -k flag if set then don't bring machine to sleep on close of lid pmud-0.7.1 -> pmud-0.7.1 - fixed: trackpad restore error after sleep pmud-0.6.1 -> pmud-0.7.1 - fixed: rpm.spec bug regarding creation of /dev/adb. - fixed: --facility bug; setting a different facility now works. - fixed: compile warning on initialising sigaction structures. - fixed: percentage calculation in apm structure with 2 batteries (Sean). - new: Added COPYING and THANKS. - new: pmud will try to get the trackpad settings just before sleep and will restore them right after waking up. - new: PowerBook 3400 APM support by Joseph P. Garcia. - new: Added wakebay by Joseph P. Garcia, modified pwrctl to use it. - hack: if pmu not supported and sleep is requested, then shutdown the machine so it will not burn or deplete the battery. pmud-0.5.1 -> pmud-0.6.1 - just before sleep pmud retrieves the fb backlight level and just after waking up, pmud restores the backlight level to this last known level. This enables you to use the offb (in BootX the 'No Video Driver is checked) and still have the backlight of the screen come up after a sleep. Note that the backlight level isn't set to the lowest level possible when you issue a sleep and use the offb (you can still see the windows), so even though it isn't the optimal situation you can now use it more comfortabel. Note that the -o flag disables this behaviour (you get the old situation back) for those that where glad that the display didn't come up after a sleep. Also see the fblevel tool on this. - new program 'xmouse'. To get and set X windows mouse settings. Just an utility. - BenH's trackpad utility is now included in the pmud distribution. - pmud rpm package now Provides 'apmd' to satisfy the wmapm requirement. - snooze accepts -s and -S flags for wmapm/apm compatibility, also /usr/bin/apm is a symbolic link to snooze. - pmud now supports 'pseudo-apm'. Code was derived from a patch send to me by BenH, whom got it from an anonymous person. Note that 'pseudo-apm' is not (yet) supported for PowerBook 3400 machines. Let me know if you need it. pmud-0.4.1 -> pmud-0.5.1 - pmud now calls "pwrctl wakeup {battery|ac}" right after wakingup from a nap - pwrctl accepts the "wakeup" parameter, idem for the pwrctl-local example - debugging syslog messages are only sent if the debug flag was supplied to pmud on startup. So there is no more constant sending of debugging messages to syslogd anymore. - pmud now calls "pwrctl warning battery" when it detects a low battery condition. This will trigger a wall or xmessage notification. - snooze now reads a line of data from pmud after the sleep call to avoid dropping the connection with pmud too fast. pmud-0.3-2 -> pmud-0.4.1 - The location of various files changed to /etc/power/* - Snooze now calls pmud, instead of putting the machine to sleep itself. Thus snooze get's all the benefits that pmud provides - Various bugfixes in pmud, most importantly: - avoid crash on SIGPIPE when a network connection disappears - avoid constant calling of pwrctl on a powerlevel change - display the correct machine type - Various modifications to pmud: - pwrctl is now called with 2 arguments (see pwrctl itself) - some rudimentary validation of the secureness of programs to run - Some iBook preparation for future development - Some pseudo apm preparation for future development - Modifications to the manual-pages pmud-0.10.orig/COPYING0100664000076400007640000004312707404124250014335 0ustar schmitzschmitz GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pmud-0.10.orig/INSTALL0100664000076400007640000000733507404124243014336 0ustar schmitzschmitzThis text describes how to install pmud and what configuration actions you might need to take after installation. New installation ---------------- Binary installation ------------------- As root copy the pmud*ppc.rpm package to /usr/src/redhat/RPMS/ppc/ Then issue the command: # rpm -iv /usr/src/redhat/RPMS/ppc/pmud*ppc.rpm If all went well, pmud is now installed. Source installation ------------------- As root copy the pmud*src.rpm package to /usr/src/redhat/SRPMS/ Then issue the command: # rpm -i /usr/src/redhat/SRPMS/pmud*src.rpm Next build the package with: # rpm -bb --rmsource /usr/src/redhat/SPEC/pmud*spec After a successfull build the binary package is put in /usr/src/redhat/RPMS/ppc/ Following this, you can continue the steps described in the 'Binary installation' section. Upgrade installation -------------------- Binary installation ------------------- As root copy the pmud*ppc.rpm package to /usr/src/redhat/RPMS/ppc/ Then issue the command: # rpm -Uv /usr/src/redhat/RPMS/ppc/pmud*ppc.rpm If all went well, pmud is now upgraded. Source installation ------------------- See the description at 'New installation'; 'Source installation'. Then continue as described here above at 'Binary installation'. Configuration ------------- You might want to edit the file /etc/sysconfig/power in order to set some startup flags for pmud. Then check with: [root@terra /root]# chkconfig --list pmud pmud 0:off 1:off 2:on 3:on 4:on 5:on 6:off if pmud starts at the levels you desire. If you want to change this, then please see: man chkconfig In /usr/doc/pmud*/ there is a pwrctl-local example script, which you might want to edit and put in /etc/power/ in order to have local actions performed on power events detected by pmud. The file /etc/power/pwrctl-local will never be upgraded on installation of new pmud releases. This is the file in which you can restore your trackpad settings, for example. As the second argument (new) is the current power source, you can issue commands when for example ac is disconnected (the second argument will be "battery" while the first will be one of {"minimum", "medium", "maximum"}. You (Adam Price ) could start Batmon if you see that you're running X on that moment ;-) Video issues ------------ If after a sleep your screen does not activate it's backlight, then you're not using the correct video driver. You can activate the backlight by pressing the contrast key of your screen (to a higher contrast). If you want to use automatic activation of the screen, then you'll need to use the (on powerbooks G3 that is, I don't know about 3400's) atyfb driver. To do this you'll need to uncheck the BootX 'no video driver' checkbox and to put the following kernel argument in the input box: video=atyfb:cmode:32,vmode:14 Then press 'save to prefs' if you want this always to happen. Now if the powerbook is in sleep and you'll press a key, the screen is also activated. Note that if you use the offb driver (The BootX 'no video driver' is checked) then the screen contents seems to desintegrate. You'll need to refresh youre X screen by the window manager's refresh option (put it in a menu) or the vty's by switching from the current vty to another and back. Files needed ------------ Pmud needs two files: crw-r--r-- 1 root root 56, 0 Mar 6 09:30 /dev/adb crw------- 1 root root 10, 154 Mar 6 09:30 /dev/pmu If one of them is not present (pmud-0.4 will install these for you if you use the binary rpm), then you can make them with: # mknod /dev/pmu c 10 154 # mknod /dev/adb c 56 0 Note that you'll need a kernel with powermanagement for the powerbook. Conclusion ---------- Have fun and less powerfailure crashes, Stephan Leemburg pmud-0.10.orig/batmon.80100664000076400007640000000210407404124246014646 0ustar schmitzschmitz .\" Copyright (c) 2000 Chad Miller .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" .\" $Log: batmon.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:50 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name .\" because of a name clash at sourceforge.net). .\" .\" Revision 1.1 2000/10/09 14:34:09 stephan .\" Initial revision .\" .\" .\" .Dd May 30, 2000 .Dt BATMON 8 .Os "pmud" .Sh NAME .Nm Batmon .Nd graphically displays status of Powerbook batteries .Sh SYNOPSIS .Nm Batmon .Sh DESCRIPTION .Nm Batmon allows one to view the status of batteries, as well as signal the Powerbook to enter sleep mode. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh FILES .nf /dev/pmu .fi .Sh AUTHOR Paul Mackerras. man page by Chad Miller . .Sh SEE ALSO .Xr pmud(8) pmud-0.10.orig/README0100664000076400007640000001065707404124237014171 0ustar schmitzschmitzThis is pmud - PMU daemon for Linux/PPC on Powerbooks. Copyright 2000 Stephan Leemburg At present this supports the PB2400/3400/3500, the 1999 G3 Powerbooks (aka "Lombard"), and the previous generation of G3 Powerbooks (aka "Wallstreet"). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. pmud is a system daemon, which is usefull only for Apple Macintosh Powerbooks. It constantly checks the Powermanagement unit to see if there is enough power left to continue. If power runs short, it will put the machine to sleep. This version was modified by me (Stephan Leemburg) mainly for own usage on a G3 Wallstreet Powerbook. Note that this version of pmud is inherently INSECURE, because every local user can issue a sleep request. The source is also not checked for possible buffer overflow attacks. As this deamon is usefull only on a Apple Powerbook, this is currently not viewed upon as something which needs immediate attention... If you're planning to use SIGPWR signals, please test this _before_ starting pmud with the -s flag. You can test powersignals by creating a file /etc/powerstatus with an F (the letter F) as it's sole contents. Then do # kill -SIGPWR 1 if you get an shutdown wall message, you're setup ok. To cancel shutdown - again - create the file /etc/powerstatus with a O (the uppercase o) as it's contents and again issue # kill -SIGPWR 1 you should again receive a wall, indicating shutdown has been cancelled. If this does not work, check the runlevels in /etc/inittab on the powerfail entry. Setting it to 012345 will probably work. The current source is still full of globals, which certainly is not something I like. This will get cleaned up in the future. Please note that any error you discover in pmud or the accompanying objects is probably my fault and not that of Paul Mackerras, so you can bother me with it. I need to work for my money so I may not always (if ever) respond directly to every question/comment made. Please have some consideration for this. For further information, please refer to the manual pmud(8). Newsgroups: Cc: Subject: Re: PowerUp/PowerDown Scripts in article slrn87ikca.o4.ami@greta.ami.home, Adam Price at ami@greta.ami.home wrote on 10-01-2000 04:40: >>> What do low power and medium power correspond to? Empty and full >>> battery (as opposed to AC)? ... > > Ooops. That should read "minimum power," not "low power." > ... Aha, well for pmud there are 2 powerlevels: 1 = on battery 2 = on AC but pwrctl discriminates between 3 powerlevels: 1 = minimum power 2 = medium power 3 = full power So that's kind of confusing (I'll build a manual page for pwrctl). When pmud detects a pmud-powerlevel (which actually should be named powersource) change, it will run pwrctl with an argument. This argument is the pwrctl-powerlevel. The default pwrctl-powerlevels for pmud are: pmud-powersource pwrctl-powerlevel __________________________________ 1 = on battery 1 = minimum power 2 = on AC 3 = full power These default relations can be overwritten by the contents of the file: /etc/powerlevels It's contents can be set by either telnetting to pmud on it's port (default is 879), like in the following example: [terra]stephan> telnet localhost 879 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. pmud 0.3 10 S {111 2263 3228 633 15719} {100} S {111 2263 3228 633 15719} {100} power 1 2 ^] telnet> c Connection closed. [terra]stephan> cat /etc/powerlevels 1 2 [terra]stephan> su Password: [root@terra pmud-0.3]# tail /var/log/messages Jan 11 09:33:49 terra pmud[324]: running /sbin/pwrctl 2 Or by just editting the file (with vi naturally!) and putting the desired pwrctl-powerlevels in the order on-battery on-AC in the file. Pmud will then use these levels as an argument to pwrctl on powersource changes. It will enable you to have pwrctl set the system to medium powerconsumption when on battery. Also when telnetting to pmud you can also issue the "sleep" command, which will give you the same effect as using snooze. So you can emulate snooze by using nc (netcat) and issuing sleep to pmud.... I hope this helps. I will update the manuals accordingly! -- Stephan Leemburg $Id: README,v 1.1.1.1 2001/12/07 11:31:43 sleemburg Exp $ pmud-0.10.orig/THANKS0100664000076400007640000000377007406746623014235 0ustar schmitzschmitzI would like te express my thanks to all these people for providing help in creating and updating the pmud package. If you think you should or should not be mentioned here and thus would like this list to be updated, please contact me at and I'll correct it as soon as possible. Thanks, -- Stephan THANK YOU TO: - "Donnie Lunder" - "HUDSON, L." - "Joseph N. Hall" - "Mike Hudson" - "Paul J. Lucas" - "Stan Cook" - Andre Berger - Andreas Tobler - Andrew Lumsdaine - Benjamin Herrenschmidt - Bryan Holland-Minkley - Cameron Andrews - Chad Miller - Christoph Ewering - Derek Homeier - Enrico Segre - Francois Felix Ingrand - Hugh Blemings - Jason Haas - Jefferson Provost - Jens Schmalzing - Jeremy Smith - Joseph Garcia - Luis Miguel - Michael Coyle - Michael Schmitz - Michel =?iso-8859-1?Q?D=E4nzer?= - Olaf Hering - Paul Mackerras - Robert Braeutigam - Robert Linnemann - Sam Powers - Seanano - Sergio Brandano - Tate Stephen SA - Wilhelm Fitzpatrick - john manoogian III - johnyates - lums@lsc.nd.edu - mpalczew@u.washington.edu - root - taz98@altern.org - vatsal@math.ubc.ca - Joe Buczek - "Calum Selkirk" (formerly unit@panix.com) pmud-0.10.orig/TODO0100664000076400007640000000034407406745146014003 0ustar schmitzschmitz- make libraries for the generic calls pmud makes to /dev/adb, /dev/pmu, etc. and clean up all utilities - Figure out the cdrom access problem after a sleep. This can hang the entire machine. It is a kernel thing, not pmud. pmud-0.10.orig/apm.h0100664000076400007640000000230707404124246014230 0ustar schmitzschmitz/* * wmapm.h -- Header file for WMAPM * * modified by Stephan Leemburg for use in pmud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file COPYING); if not, write to the * Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * */ typedef struct my_apm_info { const char driver_version[10]; int apm_version_major; int apm_version_minor; int apm_flags; int ac_line_status; int battery_status; int battery_flags; int battery_percentage; int battery_time; int using_minutes; } my_apm_info; pmud-0.10.orig/contrib/0040775000076400007640000000000007407637271014755 5ustar schmitzschmitzpmud-0.10.orig/contrib/CVS/0040775000076400007640000000000007405355741015405 5ustar schmitzschmitzpmud-0.10.orig/contrib/CVS/Root0100664000076400007640000000006307405355740016246 0ustar schmitzschmitzsleemburg@cvs.apmud.sourceforge.net:/cvsroot/apmud pmud-0.10.orig/contrib/CVS/Repository0100664000076400007640000000001607405355740017500 0ustar schmitzschmitzapmud/contrib pmud-0.10.orig/contrib/CVS/Entries0100664000076400007640000000021607405355741016735 0ustar schmitzschmitz/backlight.c/1.1.1.1/Fri Dec 7 11:31:53 2001// /trackpad/1.1.1.1/Fri Dec 7 11:31:55 2001// /trackpad.c/1.1.1.1/Fri Dec 7 11:31:54 2001// D pmud-0.10.orig/contrib/CVS/Entries.Log0100664000076400007640000000002507405355741017453 0ustar schmitzschmitzA D/fblevel_misc//// pmud-0.10.orig/contrib/fblevel_misc/0040775000076400007640000000000007407637330017403 5ustar schmitzschmitzpmud-0.10.orig/contrib/fblevel_misc/CVS/0040775000076400007640000000000007405355744020042 5ustar schmitzschmitzpmud-0.10.orig/contrib/fblevel_misc/CVS/Root0100664000076400007640000000006307405355741020701 0ustar schmitzschmitzsleemburg@cvs.apmud.sourceforge.net:/cvsroot/apmud pmud-0.10.orig/contrib/fblevel_misc/CVS/Repository0100664000076400007640000000003307405355741022132 0ustar schmitzschmitzapmud/contrib/fblevel_misc pmud-0.10.orig/contrib/fblevel_misc/CVS/Entries0100664000076400007640000000056707405355744021403 0ustar schmitzschmitz/AUTHORS/1.1.1.1/Fri Dec 7 11:31:57 2001// /COPYING/1.1.1.1/Fri Dec 7 11:31:57 2001// /Makefile/1.1.1.1/Fri Dec 7 11:31:57 2001// /README/1.1.1.1/Fri Dec 7 11:31:57 2001// /display_level/1.1.1.1/Fri Dec 7 11:31:57 2001// /display_level.conf/1.1.1.1/Fri Dec 7 11:31:55 2001// /gfblevel/1.1.1.1/Fri Dec 7 11:31:59 2001// /gfblevel.c/1.1.1.1/Fri Dec 7 11:31:56 2001// D pmud-0.10.orig/contrib/fblevel_misc/Makefile0100664000076400007640000000020607404124255021030 0ustar schmitzschmitzCC=gcc CFLAGS=-Wall `gtk-config --cflags` `gtk-config --libs` gfblevel: $(CC) $(CFLAGS) gfblevel.c -o $@ clean: rm -f gfblevel *~ pmud-0.10.orig/contrib/fblevel_misc/AUTHORS0100664000076400007640000000004707404124255020443 0ustar schmitzschmitzGord Peters pmud-0.10.orig/contrib/fblevel_misc/COPYING0100664000076400007640000004310507404124255020430 0ustar schmitzschmitz GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pmud-0.10.orig/contrib/fblevel_misc/README0100664000076400007640000000243007404124255020251 0ustar schmitzschmitzThis is a set of utilities which make using fblevel a bit easier. gfblevel is a GTK application which provides a GUI interface to fblevel, allowing easy control of the display backlight. Credit to Stephan Leemburg for the actual device access code. display_level is a shell script which can be used on system startup to restore a saved level for the display backlight. display_level.conf is the configuration file used by the display_level script. To build gfblevel: ------------------ Just type make. You'll need to have the gtk development libraries installed on your system. To install: ----------- Copy gfblevel to a directory in your path. display_level can be placed in the directory where your initialization scripts reside (/etc/init.d on Debian Linux systems or /etc/rc.d/init.d on Red Hat Linux systems) and display_level.conf should be placed in the /etc directory. Then, symbolic links should be made from the rc directories for each runlevel in which you want the display settings to be restored to the display_level script. Example (Debian Linux): ----------------------- Say you want display_level to be run in runlevel 2. Do the following on a Debian system: cp display_level /etc/init.d ln -s /etc/init.d/display_level /etc/rc2.d/S05display_level cp display_level.conf /etc pmud-0.10.orig/contrib/fblevel_misc/display_level0100775000076400007640000000065407404124255022161 0ustar schmitzschmitz#!/bin/sh # # Set the backlight level on boot FBLEVEL=/sbin/fblevel CFG=/etc/display_level.conf test -x $FBLEVEL || exit 0 if [ -f $CFG ]; then . $CFG fi case "$1" in start|force-reload|restart) echo -n "Setting display brightness: display_level" $FBLEVEL $LEVEL echo "." ;; stop) ;; *) echo "Usage: /etc/init.d/display_level {start|stop|restart|force-reload}" exit 1 esac exit 0 pmud-0.10.orig/contrib/fblevel_misc/display_level.conf0100664000076400007640000000001107404124253023063 0ustar schmitzschmitzLEVEL=13 pmud-0.10.orig/contrib/fblevel_misc/gfblevel.c0100664000076400007640000001147107404124254021327 0ustar schmitzschmitz/* * gfblevel - Graphical front end for fblevel which uses GTK * (www.gtk.org). This program doesn't require fblevel * to be installed. Credit to Stephan Leemburg for device * access code from fblevel. * * Copyright (C) 2001 Gord Peters * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) #include #else #include #endif #include #include #include #ifndef FBIOBLANK #define FBIOBLANK 0x4611 /* 0 or vesa-level+1 */ #endif #define BACKLIGHT_MIN 0 #define BACKLIGHT_MAX 15 static int fbfd_G= -1; static int pmufd_G= -1; /* Copied from fblevel */ static void fbon(int on) { ioctl(fbfd_G, FBIOBLANK, !on); } /* Copied from fblevel */ static int fblevel(int level) { ioctl(pmufd_G, (level < 0) ? PMU_IOC_GET_BACKLIGHT : PMU_IOC_SET_BACKLIGHT, &level); return level; } void fb_set_level(GtkAdjustment *adj) { fblevel((int)adj->value); } void fb_toggle_on_off(GtkWidget *widget, gpointer data) { if (GTK_TOGGLE_BUTTON(widget)->active) { fbon(1); } else { fbon(0); } } void create_window(int level) { GtkWidget *window; GtkWidget *box1, *box2; GtkWidget *button, *fboncb; GtkWidget *separator; GtkWidget *hscale; GtkWidget *label; GtkObject *adj1; /* Standard window-creating stuff */ window= gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect(GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC(gtk_main_quit), NULL); gtk_window_set_title(GTK_WINDOW (window), "gfblevel"); box1= gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER (window), box1); gtk_widget_show(box1); box2= gtk_hbox_new(FALSE, 10); gtk_container_set_border_width(GTK_CONTAINER (box2), 10); gtk_box_pack_start(GTK_BOX (box1), box2, TRUE, TRUE, 0); gtk_widget_show(box2); if (pmufd_G >= 0) { /* Create the label */ label= gtk_label_new("Brightness:"); gtk_box_pack_start(GTK_BOX(box2), label, TRUE, TRUE, 0); gtk_widget_show(label); /* Create the adjustment widget */ adj1= gtk_adjustment_new(level, BACKLIGHT_MIN, BACKLIGHT_MAX, 1.0, 1.0, 0.0); gtk_signal_connect(GTK_OBJECT (adj1), "value_changed", GTK_SIGNAL_FUNC (fb_set_level), NULL); hscale= gtk_hscale_new(GTK_ADJUSTMENT (adj1)); gtk_widget_set_usize(GTK_WIDGET (hscale), 200, 30); gtk_scale_set_digits(GTK_SCALE (hscale), 0); gtk_box_pack_start(GTK_BOX (box2), hscale, TRUE, TRUE, 0); gtk_widget_show(hscale); } if (fbfd_G >= 0) { /* fb on/off checkbox */ fboncb= gtk_check_button_new_with_label("on"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fboncb), TRUE); gtk_signal_connect(GTK_OBJECT (fboncb), "toggled", GTK_SIGNAL_FUNC (fb_toggle_on_off), NULL); gtk_box_pack_start(GTK_BOX (box2), fboncb, TRUE, TRUE, 0); gtk_widget_show(fboncb); } separator= gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX (box1), separator, FALSE, TRUE, 0); gtk_widget_show(separator); box2= gtk_vbox_new(FALSE, 10); gtk_container_set_border_width(GTK_CONTAINER (box2), 10); gtk_box_pack_start(GTK_BOX (box1), box2, FALSE, TRUE, 0); gtk_widget_show(box2); button= gtk_button_new_with_label("Quit"); gtk_signal_connect_object(GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(gtk_main_quit), NULL); gtk_box_pack_start(GTK_BOX (box2), button, TRUE, TRUE, 0); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); gtk_widget_grab_default(button); gtk_widget_show(button); gtk_widget_show(window); } int main(int argc, char **argv) { int level; pmufd_G= open("/dev/pmu", O_RDONLY); fbfd_G= open("/dev/fb0", O_RDONLY); if (pmufd_G < 0) perror("can't open /dev/pmu"); if (fbfd_G < 0) perror("can't open /dev/fb0"); if ((pmufd_G < 0) && (fbfd_G < 0)) { return 1; } level= fblevel(-1); gtk_init(&argc, &argv); create_window(level); gtk_main(); return 0; } pmud-0.10.orig/contrib/backlight.c0100664000076400007640000001117407404124251017034 0ustar schmitzschmitz/* backlight.c - set backlight level * * Michael Schmitz * * based on: cannibalized trackpad.c * * Tool for setting the PowerBook trackpad options on linux * * by benh * 2/13/99 * * Pieces from mousehack, from numerous contributors... * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #undef DEBUG_SCAN #define DEBUG_REPLY #undef DEBUG int fd; int pmu_fd; /* * we ignore write and read errors, or rather pass the error codes */ int send(unsigned char *y, int len) { int n; #ifdef DEBUG printf("send: "); for (n=0; n < len; n++) printf("0x%02x ",y[n]); printf("\n"); #endif n = write(fd, y, (size_t) len); return n; } int listen(unsigned char *y) { int n; n = read(fd, y, 80); #ifdef DEBUG printf("%d: ",n); if (n > 0) { int i; for (i=0; i < n; i++) printf("0x%02x ",y[i]); } printf("\n"); #endif return n; } /* * see drivers/macintosh/via-pmu.c */ void set_backlight_level(int id, int set) { unsigned char buf[16]; int n; #ifdef DEBUG printf("level set to: %d\n", set); #endif buf[0] = id; buf[1] = PMU_BACKLIGHT_BRIGHT; buf[2] = (set < 1 ? 0x7f : 0x4a - (set<<1) ); send(buf, 3); n = listen(buf+1); buf[0] = id; buf[1] = PMU_POWER_CTRL; buf[2] = PMU_POW_BACKLIGHT | (set < 1 ? PMU_POW_OFF : PMU_POW_ON); send(buf, 3); listen(buf); } /* * heuristics for finding the PMU: the first device that responds to a * extended battery status request is assumed to be the PMU */ int locate_pmu(void) { int i, id, n; unsigned char buf[16]; for (i=1; i<16; i++) { #ifdef DEBUG_SCAN printf("testing %d...\n", i); #endif buf[0] = i; buf[1] = 0x6b; send(buf, 2); n = listen(buf); if (n >= 8) { #ifdef DEBUG printf("found PMU at %d\n", id); #ifdef DEBUG_REPLY printf("%d: ",n); if (n > 0) { int j; for (j=0; j < n; j++) printf("0x%02x ",buf[j]); } printf("\n"); #endif #endif return i; } } return -1; } int main(int argc, char **argv) { int id, level, use_adb, set_level, quiet, usage, i, n; char devname[64]; char buf[80]; fd = open("/dev/adb", O_RDWR); if (fd <= 0) { perror("opening /dev/adb"); exit(EXIT_FAILURE); } id = -1; level = -1; use_adb = 0; set_level = 1; quiet = 0; usage = 0; if (argc >= 2) { if (argc > 2) { if (strcmp(argv[1], "-q") == 0) quiet = 1; else if (strcmp(argv[1], "-h") == 0) usage = 1; else if (strcmp(argv[1], "-a") == 0) use_adb = 1; level = atol(argv[2]); } else { if (strcmp(argv[1], "-h") == 0) usage = 1; else if (strcmp(argv[1], "-g") == 0) { level = 0; set_level = 0; } else level = atol(argv[1]); } } if (level < 0 || usage) { printf("usage: backlight [-g] | [-a]|[-q] \n"); printf(" -q quiet mode, using /dev/adb \n"); printf(" -a set backlight level, using /dev/adb \n"); printf(" -g read backlight level. using ioctl \n"); return 0; } id = locate_pmu(); if (id < 0) { printf("no PMU found !\n"); return 0; } #ifdef DEBUG_SCAN printf("PMU found at %d!\n", id); #endif #ifdef TEST_ADBDEV /* needs kernel patch ... */ close(fd); /* * 'raw' device; doesn't work for devices with assigned input * handler currently (bug in kernel driver) * 'buffered' device, however, doesn't work for devices * without handler attached ... */ sprintf(devname, "/dev/adb%d", id); fd = open(devname, O_RDWR); if (fd <= 0) { perror("opening device"); printf("Could not open %s\n", devname); exit(EXIT_FAILURE); } #endif if (!use_adb) { pmu_fd = open("/dev/pmu", O_RDWR); if (pmu_fd <= 0) { perror("opening device"); printf("Could not open device /dev/pmu \n"); exit(EXIT_FAILURE); } } if (set_level) { if (use_adb) { /* use /dev/adb write to talk to PMU */ set_backlight_level(id, level); } else { /* use /dev/pmu ioctl to talk to PMU */ if (ioctl(pmu_fd, PMU_IOC_SET_BACKLIGHT, &level) < 0) perror("PMU_IOC_SET_BACKLIGHT ioctl"); } if (!quiet) printf("Backlight set to level: %d\n", level); } else { /* use /dev/pmu ioctl to talk to PMU */ if (ioctl(pmu_fd, PMU_IOC_GET_BACKLIGHT, &level) < 0) perror("PMU_IOC_GET_BACKLIGHT ioctl"); printf("Backlight level: %d\n", level); } close(pmu_fd); close(fd); return 0; } pmud-0.10.orig/contrib/trackpad.c0100664000076400007640000000647507404124252016706 0ustar schmitzschmitz/* trackpad.c * * Tool for setting the PowerBook trackpad options on linux * * bye benh * 2/13/99 * * 3/17/99 - Minor Fix: usage display used to leave /dev/adb open * * Pieces from mousehack, from numerous contributors... * */ #include #include #include #include #include #include #include #include //#define DEBUG int fd; void send(unsigned char *y, int len) { int n; #ifdef DEBUG printf("send: "); for (n=0; n < len; n++) printf("0x%02x ",y[n]); printf("\n"); #endif n = write(fd, y, (size_t) len); if (n < len) { perror("writing /dev/adb"); close(fd); exit (EXIT_FAILURE); } } int listen(unsigned char *y) { int n; n = read(fd, y, 80); #ifdef DEBUG printf("listen (%d bytes): ",n); if (n >= 0) { int i; for (i=0; i < n; i++) printf("0x%02x ",y[i]); } printf("\n"); #endif if (n < 0) { perror("reading /dev/adb"); close(fd); exit(EXIT_FAILURE); } return n; } void set_program_mode(int id, int set) { unsigned char buf[16]; int n; #ifdef DEBUG printf("program mode set to: %d\n", set); #endif buf[0] = ADB_PACKET; buf[1] = ADB_READREG(id, 1); send(buf, 2); n = listen(buf+1); buf[0] = ADB_PACKET; buf[1] = ADB_WRITEREG(id, 1); buf[8] = set ? 0x0d : 0x03; send(buf, 1+n); listen(buf); buf[0] = ADB_PACKET; buf[1] = ADB_READREG(id, 2); send(buf, 2); n = listen(buf+1); } enum { mode_invalid = 0, mode_notap, mode_tap, mode_drag, mode_lock }; void set_trackpad(int id, int mode) { unsigned char buf[16]; set_program_mode(id, 1); #ifdef DEBUG printf("setting mode: %d\n", mode); #endif buf[0] = ADB_PACKET; buf[1] = ADB_WRITEREG(id, 2); buf[2] = (mode < mode_tap) ? 0x19 : 0x99; buf[3] = (mode < mode_drag) ? 0x14 : 0x94; buf[4] = 0x19; buf[5] = (mode < mode_lock) ? 0xb2 : 0xff; buf[6] = 0xb2; buf[7] = 0x8a; buf[8] = 0x1b; buf[9] = 0x50; send(buf, 10); listen(buf); set_program_mode(id, 0); { int i, n; for(i=0; i<4; i++) { printf("READREG(%d, %d) ", id, i); buf[0] = ADB_PACKET; buf[1] = ADB_READREG(id, i); send(buf, 2); n = listen(buf+1); } } } int locate_trackpad(void) { int i, n; for (i=1; i<16; i++) { unsigned char buf[16]; #ifdef DEBUG printf("testing %d...\n", i); #endif buf[0] = ADB_PACKET; buf[1] = ADB_READREG(i, 1); send(buf, 2); n = listen(buf); if ((n >= 4) && (buf[1] == 0x74) && (buf[2] == 0x70) && (buf[3] == 0x61) && (buf[4] == 0x64)) { #ifdef DEBUG printf("found trackpad at %d\n", i); #endif return i; } } return -1; } int main(int argc, char **argv) { int id; int mode = mode_invalid; if (argc >= 2) { if (strcmp(argv[1], "notap") == 0) mode = mode_notap; else if (strcmp(argv[1], "tap") == 0) mode = mode_tap; else if (strcmp(argv[1], "drag") == 0) mode = mode_drag; else if (strcmp(argv[1], "lock") == 0) mode = mode_lock; } if (mode == mode_invalid) { printf("usage: trackpad notap|tap|drag|lock\n"); return 0; } fd = open("/dev/adb", O_RDWR); if (fd < 0) { perror("opening /dev/adb"); exit(EXIT_FAILURE); } id = locate_trackpad(); if (id < 0) { printf("no trackpad !\n"); return 0; } set_trackpad(id, mode); close(fd); return 0; } pmud-0.10.orig/contrib/fnset.c0100600000076400007640000002000407406743140016207 0ustar schmitzschmitz#include #include #include #include #include #include #include #include #define PMU_GET_VERSION 0xea /* get pmu firmware version # */ #define PMU_VERSION_KEYLARGO 12 /* another guess */ #define PMU_VERSION_IBOOK PMU_VERSION_KEYLARGO const char *prog; int debug = 0; void usage() { fprintf(stderr, "Usage: %s [-hdfusb] [0|1]\n" " -h Help, this message.\n" " -d Turn debugging on.\n" " -f Force search and setting of bits for an unknown PMU.\n" " WARNING: may damage hardware.\n" " -s Set, function keys require modifier.\n" " Same as checking the box in MacOS.\n" " -u Unset, hot keys require modifier.\n" " Same as unchecking the box in MacOS.\n" " -v Verbose output.\n" " -b Brief, output adb register bit value only.\n" " 0 Set adb register bit to 0.\n" " May not be the same as the -u option.\n" " 1 Set adb register bit to 1.\n" " May not be the same as the -s option.\n" "No arguments displays the mode as if -v was used.\n", prog); } int put(int fd, unsigned char data[], size_t sz) { int n; if (debug) { int i; fprintf(stderr, "writing %ld bytes: {", sz); for (i = 0; i < sz; i++) { fprintf(stderr, " 0x%02x", data[i]); } fputs(" }\n", stderr); } n = write(fd, data, sz); if (n != sz) { if (n == -1) { fprintf(stderr, "%s: write(): %s\n", prog, strerror(errno)); } else { fprintf(stderr, "%s: write(): expected %ld got %ld\n", prog, sz, n); } return -1; } return n; } int get(int fd, unsigned char data[], size_t sz) { int n; n = read(fd, data, sz); if (n == -1) { fprintf(stderr, "%s: read(): %s\n", prog, strerror(errno)); return -1; } if (debug) { int i; fprintf(stderr, "read %ld bytes", n); if (n > 0) { fputs(": {", stderr); for (i = 0; i < n; i++) { fprintf(stderr, " 0x%02x", data[i]); } fputs(" }", stderr); } fputc('\n', stderr); } return n; } int pmu_version(int fd) { unsigned char data[32]; int n; data[0] = PMU_PACKET; data[1] = PMU_GET_VERSION; n = put(fd, data, 2); if (n == -1) { return -1; } n = get(fd, data, sizeof (data)); if (n == -1) { return -1; } if (n != 2) { fprintf(stderr, "%s: read(): expected 2 got %ld\n", prog, n); return -1; } return data[1]; } int show_regs(int fd, int id) { unsigned char data[16]; int i; fprintf(stderr, "=== reading all registers for device %d. ===\n", id); for (i = 0; i < 4; i++) { data[0] = ADB_PACKET; data[1] = ADB_READREG(id, i); put(fd, data, 2); get(fd, data, sizeof(data)); } fprintf(stderr, "=== done reading all registers for device %d. ===\n", id); return 1; } int find_device(int fd, int type, int bitpos, int *bit) { int i; int n; int ret = -1; unsigned char data[16]; for (i = 1; i < 16; i++) { if (debug) { fprintf(stderr, "probe adb device %d.\n", i); } data[0] = ADB_PACKET; data[1] = ADB_READREG(i, 1); n = put(fd, data, 2); if (n == -1) { return -1; } n = get(fd, data, sizeof (data)); if (n == -1) { return -1; } if ((n > 0) && (data[1] == type)) { if (ret > 0) { fprintf(stderr, "Ignoring other keyboard at %d\n", i); } else { if (debug) { fprintf(stderr, "Found keyboard at ADB id %d.\n", i); } ret = i; *bit = (data[2] & (1<> bitpos; if (debug) { show_regs(fd, ret); } } } } return ret; } int fnset(int fd, int id, int bitpos, int bit) { unsigned char data[4]; int n; /* get current state */ data[0] = ADB_PACKET; data[1] = ADB_READREG(id, 1); n = put(fd, data, 2); if (n == -1) { return 0; } n = get(fd, &data[1], sizeof (data) - 1); if (n == -1) { return 0; } /* write new state */ data[0] = ADB_PACKET; data[1] = ADB_WRITEREG(id, 1); /* keep data[2] the same */ data[3] = (data[3] & (~(1< 7) { fprintf(stderr, "%s: bit position must be 0-8.\n", prog); return 1; } break; case 'd': debug = 1; break; case 'f': force = 1; break; case 'h': usage(); return 0; break; case 's': if (bit != -1) { fprintf(stderr, "%s: conflicting arguments\n", prog); usage(); return 1; } bit = 0; break; case 'u': if (bit != -1) { fprintf(stderr, "%s: conflicting arguments\n", prog); usage(); return 1; } bit = 1; break; case 'b': if (verbose) { fprintf(stderr, "%s: conflicting arguments\n", prog); usage(); return 1; } brief = 1 ; break; case 'v': if (brief) { fprintf(stderr, "%s: conflicting arguments\n", prog); usage(); return 1; } verbose = 1 ; break; case '?': default: usage(); return 1; break; } } if (optind < argc) { if (bit != -1) { fprintf(stderr, "%s: conflicting arguments\n", prog); usage(); return 1; } if (argv[optind][0] == '1' && argv[optind][1] == '\0') { bit = 1; } else if (argv[optind][0] == '0' && argv[optind][1] == '\0') { bit = 0; } if (debug) { fprintf(stderr, "set bit to: optarg: %u\n", bit); } ++optind; } if (optind != argc) { fprintf(stderr,"%s: too many arguements\n", prog); return 1; } } if (bitpos && !force) { fprintf(stderr, "%: WARNING: use of bit offset other than 0 (-P option)" "requires force (-f option) since it may damage hardware!\n", prog); } fd = open(adb, O_RDWR); if (fd < 0) { fprintf(stderr, "%s: open(%s): %s\n", prog, adb, strerror(errno)); return 1; } pmu = pmu_version(fd); switch (pmu) { case PMU_VERSION_IBOOK: type = 0x04; break; default: fprintf(stderr, "unknown PMU version %d\n", pmu); if (force) { type = 0x04; fprintf(stderr, "forcing look up of type 0x%02x.\n", type); } else { close(fd); return 1; } break; case -1: close(fd); return 1; break; } id = find_device(fd, type, bitpos, &val); if (id == -1) { close(fd); return 1; } if (bit != -1) { if (bit != val) { if (debug) { fprintf(stderr, "Changing value from %d to %d.\n", val, bit); } if (!fnset(fd, id, bitpos, bit)) { if (debug) { fprintf(stderr, "Failed to set value to %d.\n", bit); } close(fd); return 1; } val = bit; } else { if (debug) { fputs("Value already correct, nothing to do.\n", stderr); } } } if (brief) { printf("%u\n", val); } else if (verbose) { if (val == 0) { printf("Set: Function keys require modifier.\n"); } else { printf("Unset: Hot keys require modifier.\n"); } } close(fd); return 0; } pmud-0.10.orig/fblevel.80100664000076400007640000000215307407064726015022 0ustar schmitzschmitz.\" Copyright (c) 2000 Stephan Leemburg .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" .\" $Log: fblevel.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:50 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name .\" because of a name clash at sourceforge.net). .\" .\" Revision 1.1 2000/05/11 14:52:40 stephan .\" Initial revision .\" .\" .Dd March 28, 2000 .Dt FBLEVEL 8 .Os "LinuxPPC pmud" .Sh NAME .Nm fblevel .Nd sets the display brightness level on a notebook .Sh SYNOPSIS .Nm fblevel .Op on .Op off .Op .Sh DESCRIPTION .Nm fblevel is a program, with which you can set the Framebuffer Backlight level on notebooks. The minimum level is 0 and the maximum is 31. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh FILES .nf /dev/fb .fi .Sh AUTHOR Stephan Leemburg . .Sh SEE ALSO .Xr pmud(8) pmud-0.10.orig/fblevel.c0100664000076400007640000000545707404124246015076 0ustar schmitzschmitz/* * ---------------------------------------------------------------------------- * fblevel - sets the fb device brightness level on Apple Powerbooks * * Copyright 2000 Stephan Leemburg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ---------------------------------------------------------------------------- * $Log: fblevel.c,v $ * Revision 1.1.1.1 2001/12/07 11:31:50 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.3 2001/11/09 10:55:29 stephan * use "pmu.h" * * Revision 1.2 2000/10/09 14:16:33 stephan * use /dev/fb0 in stead of /dev/fb * * Revision 1.1 2000/05/11 14:48:46 stephan * Initial revision * * ---------------------------------------------------------------------------- */ static char *rcsid = "@(#)$Id: fblevel.c,v 1.1.1.1 2001/12/07 11:31:50 sleemburg Exp $"; #include #include #include #include #include #include #include #include #include #include #include "pmu.h" #ifndef FBIOBLANK #define FBIOBLANK 0x4611 /* 0 or vesa-level+1 */ #endif static void fbon(int on); static int fblevel(int level); static void usage(char *program); int main(int argc, char **argv) { char *program = strrchr(*argv, '/'); program = program ? program + 1 : *argv; switch(argc) { case 1: printf("%d\n", fblevel(-1)); break; case 2: if(!strcasecmp(*++argv, "on") || !strcasecmp(*argv, "off")) fbon(strcasecmp(*argv, "off")); else { register char *p; for(p = *argv; *p && isdigit(*p); p++) ; if(*p) { usage(program); return 1; } (void) fblevel(atoi(*argv)); } break; default: usage(program); return 1; } return 0; } static void fbon(int on) { static int fd = -1; if(fd<0) { fd = open("/dev/fb0", O_RDONLY); if(fd<0) { perror("/dev/fb0"); return; } } (void)ioctl(fd, FBIOBLANK, !on); } static int fblevel(int level) { static int fd = -1; if(fd<0) { fd = open("/dev/pmu", O_RDONLY); if(fd<0) { perror("/dev/pmu"); return 0; } } ioctl(fd, level<0?PMU_IOC_GET_BACKLIGHT:PMU_IOC_SET_BACKLIGHT, &level); return level; } static void usage(char *program) { fprintf(stderr, "usage: %s [on|off|]\n" " on : powers display on\n" " off : powers display off\n" " : set display brightness to \n" " (level is an integer)\n" "no argument prints the current brightness level\n", program ); } pmud-0.10.orig/mailinglist0100664000076400007640000000304307404124251015533 0ustar schmitzschmitz"Donnie Lunder" "HUDSON, L." "Joseph N. Hall" "Mike Hudson" "Paul J. Lucas" "Stan Cook" Andre Berger Andreas Tobler Andrew Lumsdaine Benjamin Herrenschmidt Bryan Holland-Minkley Cameron Andrews Chad Miller Christoph Ewering Derek Homeier Enrico Segre Francois Felix Ingrand Hugh Blemings Jason Haas Jefferson Provost Jens Schmalzing Jeremy Smith Joseph Garcia Luis Miguel Michael Coyle Michael Schmitz Michel =?iso-8859-1?Q?D=E4nzer?= Olaf Hering Paul J. Lucas Paul Mackerras Robert Braeutigam Robert Linnemann Sam Powers Seanano Sergio Brandano Tate Stephen SA Wilhelm Fitzpatrick john manoogian III johnyates lums@lsc.nd.edu mpalczew@u.washington.edu root taz98@altern.org unit@panix.com vatsal@math.ubc.ca pmud-0.10.orig/makerpm0100664000076400007640000000117607404124246014664 0ustar schmitzschmitz[ `id -u` -ne 0 ] && { echo "Must be root to build RPM" exit 1 } rhdir=/usr/src/redhat cwd=`pwd` while read define var val do [ "$define" = "%define" ] && { case "$var" in version) version=$val ;; release) release=$val ;; esac } done < pmud.spec [ -z "$version" -o -z "$release" ] && { echo "cannot determine version or release" exit 1 } echo "pmud-${version}.${release}" cd .. || { echo "cannot cd .." exit 1 } base=`basename $cwd` tar czf ${rhdir}/SOURCES/pmud-${version}.${release}.tar.gz \ --exclude makerpm --exclude RCS $base cd ${rhdir}/SPECS cp -f ${cwd}/pmud.spec ./ rpm -ba --rmsource pmud.spec pmud-0.10.orig/pmu.h0100664000076400007640000000171007404124244014247 0ustar schmitzschmitz/* * $Id: pmu.h,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $ * * Definitions for talking to the PMU. The PMU is a microcontroller * which controls battery charging and system power on PowerBook 3400 * and 2400 models as well as the RTC and various other things. * * Copyright (C) 1998 Paul Mackerras. * * $Log: pmu.h,v $ * Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.4 2001/11/09 10:55:29 stephan * location of pmu.h changed * * Revision 1.3 2000/10/09 14:16:51 stephan * removed KEYLARGO defs * * Revision 1.2 2000/03/09 12:57:20 stephan * KEYLARGO for iBook definition * * Revision 1.1 2000/01/06 13:48:19 stephan * Initial revision * */ #include #define PMU_SMART_BATT 0x6f /* report smart battery state */ #define PMU_GET_VERSION 0xea /* get pmu firmware version # */ pmud-0.10.orig/pmud.80100664000076400007640000001210407406752070014340 0ustar schmitzschmitz.\" Copyright (c) 2000 Stephan Leemburg .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" .\" $Log: pmud.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:44 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name .\" because of a name clash at sourceforge.net). .\" .\" Revision 1.5 2000/10/09 14:17:02 stephan .\" mention defaults for -l and -m flags, explain /etc/power/levels .\" .\" Revision 1.4 2000/03/09 12:57:36 stephan .\" modified for pmud-0.4 .\" .\" Revision 1.3 2000/01/06 23:04:53 stephan .\" corrected some errors .\" .\" Revision 1.2 2000/01/06 22:52:31 stephan .\" changed -l and -m argument from minutes to seconds .\" .\" Revision 1.1 2000/01/06 13:48:19 stephan .\" Initial revision .\" .\" .Dd Februari 10, 2000 .Dt PMUD 8 .Os "LinuxPPC pmud" .Sh NAME .Nm pmud .Nd constantly checks the Powermanagement unit to see if there is enough power left to continue. .Sh SYNOPSIS .Nm pmud .Op Fl dhsvkK .Op Fl f Ar facility .Op Fl l Ar seconds .Op Fl m Ar seconds .Op Fl p Ar port .Sh DESCRIPTION .Nm Pmud is a system daemon, which is usefull only for Apple Macintosh Powerbooks. It constantly checks the Powermanagement unit to see if there is enough power left to continue. If power runs short, it will put the machine to sleep or issue a powerfail signal to .Nm init(8). It also detects if the lid is closed, after which the machine is put to sleep. The options are as follows: .Bl -tag -width Ds .It Fl d Enable debugging; this disables pmud of backgrounding. .It Fl f Ar facility Use .Ar facility for .Nm syslogd(8) messages. .It Fl h Print a help message. .It Fl k Do not put machine to sleep when the lid closes, but do power off the screen. .It Fl K As with -k but put the machine to sleep if running on batteries. .It Fl l Ar seconds the numbers .Ar seconds of power left which is considered to be a critical low level. When this level is reached and if this state remains for a determined period of time, the system is put to sleep or a powerfail signal is issued to .Nm init(8). The default is 420 seconds. .It Fl m Ar seconds The number of .Ar seconds a . Dq critical low power level has to endure in order to start sleeping or initiating a powerfail signal. The default is 15 seconds. .It Fl n Do not detach. Whit this option the daemon will not become a background process. .It Fl p Ar port Specifies the .Ar port on which .Nm pmud will listen to .Tn TCP/IP requests. This is used by .Nm Batmon. .Nm Pmud will only listen to requestes on the .Tn localhost address. .It Fl v Print the current RCS version Id of .El .Sh POWERSIGNALS When .Nm pmud is instructed to issue a powerfail signal to .Nm init(8) it will assume that .Nm init(8) has been correctly set up for powerfail and powerokwait signals. When the powerlevel drops beneath the treshold, .Nm pmud will write the file \fB/etc/powerstatus\fP and send .Tn SIGPWR to .Nm init(8). If power is restored (The AC Adapter is connected to mains) the file \fB/etc/powerstatus\fP is written again and onother .Tn SIGPWR is send to .Nm init(8) to indicate power has been restored. Before using this option, you should test your init-setup manually to verify if power-signal handling is correctly supported. .Sh CHANGE OF INPUT SOURCE .Nm Pmud will detect if the machine is running on battery or on the AC Adapter. It will also notice when this changes. When machine is running on battery and is switched to the AC Adapter - or vice versa - .Nm pmud will run the script \fB/etc/power/pwrctl\fP. This script will handle additional actions to be performed in order to gain maximum performance or minimal power consumption. The default script will only set hd spindown times, using .Nm hdparm(8). You can put local commands - like restoring trackpad settings after a sleep - in \fB/etc/power/pwrctl-local\fP. The arguments to .Nm pwrctl are passed through to .Nm pwrctl-local. This script is not distributed with the pmud-package and will therefore never be overwritten on upgrades. .Sh POWER POLICY On startup .Nm pmud will read the file \fB/etc/power/levels\fP. It initialises it's power policy with the values in this file. There are two numeric values in this file. The first value is the battery policy, the second value is the AC policy. Valid values are 1 (minimum power consumption), 2 (medium power consumption) and 3 (maximum power consumption). Obviously, minimum power consumption degrades the systems performance and vice versa. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh FILES .nf /dev/adb /dev/pmu /sbin/pmud /etc/power/pwrctl /etc/power/pwrctl-local /etc/power/levels /etc/powerstatus /etc/rc.d/init.d/pmud /etc/sysconfig/power .fi .Sh AUTHORS initial pmud package by Paul Mackerras and initial manual and changes to pmud-0.[34] by Stephan Leemburg . .Sh SEE ALSO .Xr init(8), .Xr hdparm(8), .Xr snooze(8) .Xr /usr/doc/pmud*/* pmud-0.10.orig/pmud.c0100664000076400007640000011077407407067161014430 0ustar schmitzschmitz/* * ---------------------------------------------------------------------------- * pmud - PMU daemon for Linux/PPC on Powerbooks. * At present this supports the PB2400/3400/3500, * the 1999 G3 Powerbooks (aka "Lombard"), and the * previous generation of G3 Powerbooks (aka "Wallstreet"). * * Copyright 1999 Paul Mackerras. * Heavily modified by Stephan Leemburg. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ---------------------------------------------------------------------------- * $Log: pmud.c,v $ * Revision 1.1.1.1 2001/12/07 11:31:46 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.12 2001/11/09 10:55:29 stephan * use "pmu.h" * * Revision 1.11 2001/11/09 10:47:30 stephan * added -k option for my Titanium * * Revision 1.10 2000/11/21 20:58:32 stephan * bugfix for transposed mouse/trackpad settings. Thanks Michael Schmitz! * * Revision 1.9 2000/10/09 14:17:24 stephan * reset trackpad settings * calculate percentage power correct with two batteries * fixed compile warning on sigaction initialising * powerbook 3400 APM support * on unsupported new machines, shutdown the machine in stead of sleep * facility commandline set now works * * Revision 1.8 2000/05/11 14:53:40 stephan * intro pseudo apm * * Revision 1.7 2000/03/25 21:25:13 stephan * wakeup argument to pwrctl * only debugging syslog messages when debugging is enabled * warning argument to pwrctl * * Revision 1.6 2000/03/09 13:25:33 stephan * some security checking in run_program * * Revision 1.5 2000/03/09 12:57:54 stephan * pmud-0.4 modifications: * o avoid SIGPIPE faults * o pmu type is now correctly printed * o powerlevel is now set on detection of change to avoid constant * calling of pwrctl on the first change * o arguments to pwrctl extended * o various other little things * * Revision 1.4 2000/01/11 09:01:30 stephan * display of machine type was wrong * * Revision 1.3 2000/01/06 22:52:31 stephan * changed -l and -m argument from minutes to seconds * * Revision 1.2 2000/01/06 13:48:19 stephan * part of pmud package * ---------------------------------------------------------------------------- */ static char *rcsid = "@(#)$Id: pmud.c,v 1.1.1.1 2001/12/07 11:31:46 sleemburg Exp $"; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pmu.h" #include "pmud.h" #include "apm.h" #define chk(x, mess) if (x) { syslog(LOG_ERR, mess); bye(EXIT_FAILURE,mess);} #define novm(p, what) if ((p) == 0) { \ syslog(LOG_ERR, "Couldn't allocate memory for "what); \ bye(EXIT_FAILURE, what); } #define INBSZ 128 #define OUTBSZ 128 #define STAT_OUTSTANDING 2 #define FLG_DEBUG (1<<0) #define FLG_SIGPWR (1<<1) #define FLG_SHUTDOWN (1<<2) #define FLG_NODETACH (1<<3) #define FLG_APM (1<<4) #define FLG_WARN (1<<5) #define FLG_NOOFFB (1<<6) #define FLG_NOLID (1<<7) #define FLG_NOACLID (1<<8) #define FLG_NOTCP (1<<9) #define TPS_TAP (1<<0) #define TPS_DRAG (1<<1) #define TPS_LOCK (1<<2) struct sockstate { int fd; int nstat; /* number of statuses we can send */ int inb_cnt; char inbuf[INBSZ]; int out_pending; char *outptr; char outbuf[OUTBSZ]; struct sockstate *next; struct sockstate **prevp; }; struct fd_info { void (*proc)(int, void *, int); void *arg; } *polli; #define ADBlisten 2 #define ADBtalk 3 #define ADB_DATA_LEN 32 typedef struct adbpacket_t { char preamble; char control; char data[ADB_DATA_LEN]; } adbpacket_t; struct my_apm_info apm; int lid_closed = 0; int pmu_fd; int adb_fd; int apm_fd; int fb0_fd; int pmu_version; int powermode; /* 0 for battery, 1 for AC */ int powerlevel = -1; /* current power level setting */ int powerlevels[2] = { 1, 3 }; /* settings for battery & AC */ int chloralhydrate; /* makes you sleepy */ int critical_time; /* # seconds of critically low power */ int critical_left = CRITICAL_TIMELEFT; /* # seconds of power left */ int critical_margin = CRITICAL_TIME; struct sockstate *all_sockets; struct timeval pmu_poll_time; char *apmfile = APM_FILE; char sock_welcome[64]; struct pollfd *polls; int ipoll_current; int nall_polls; int npolls; int flags = 0; int ntick; static int do_poll(unsigned); static int do_sigpower(char); static int get_pmu_version(void); static int open_apm(char *); static int pmu_op(unsigned char, unsigned char*, int, void*, int , const char*); static int send_socket(struct sockstate *, char *, int); static int sock_write(struct sockstate *, char *, int); static int usage(char *, int); static int get_trackpad_id(int); static int adb_program(int, int, int); static int get_trackpad_settings(int, int); static int set_trackpad_settings(int, int, int); static int adbread(int, char, char *, int); static int adbwrite(int, char, char, char, char *, int); static int validate_program(char *); static void add_fd(int, int, void (*proc)(int, void *, int), void *); static void apm_data(int, struct my_apm_info *); static void bye(int, const char*); static void conn_sock(int, void *, int); static void delete_socket(struct sockstate *); static void do_cmd(struct sockstate *); static void do_power(struct sockstate *, char *); static void do_signal(int); static void pmu_intr(int, void *, int); static void poll_init(void); static void poll_pmu(void); static void read_sock(int, void *, int); static void run_program(char *, char *, char *); static void send_more(int, void *, int); static void set_power(int, int); static void snooze(int); static void fbon(int); static void beep(unsigned int ms, unsigned int freq); int main(int ac, char **av) { struct timeval now, tleft; unsigned tms; int s, len, fl; struct sockaddr *sa; struct sockaddr_in sin; struct sockaddr_un sun; FILE *f; struct option options[] = { {"apm", 2, 0, 'a'}, {"debug", 0, 0, 'd'}, {"facility", 1, 0, 'f'}, {"help", 0, 0, 'h'}, {"critical-left", 1, 0, 'l'}, {"critical-margin", 1, 0, 'm'}, {"nolid", 0, 0, 'k'}, {"noaclid", 0, 0, 'k'}, {"nodetach", 0, 0, 'n'}, {"port", 1, 0, 'p'}, {"sigpower", 0, 0, 's'}, {"shutdown", 0, 0, 'S'}, {"af_unix", 0, 0, 'u'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; int opt; unsigned short port = PORT; int syslog_options = PMU_SYSLOG_OPTIONS; int facility = PMU_FACILITY; struct sigaction sigpipe = { {SIG_IGN}, {{0}}, SA_RESTART, 0 }; struct sigaction sigterm = {{do_signal}, {{0}}, SA_RESTART , 0 }; // there is a bug in basename() char *p = strrchr(*av, '/'); p = p ? p + 1 : *av; while((opt=getopt_long(ac,av, "a::df:hKkl:m:nop:sSuv", options,0))!=EOF) switch(opt) { case 'a': flags |= FLG_APM; if(optarg && *optarg) apmfile = optarg; break; case 'd': flags |= (FLG_DEBUG|FLG_NODETACH); syslog_options |= LOG_PERROR; break; case 'f': if(!strcasecmp(optarg, "daemon")) facility = LOG_DAEMON; else if(!strcasecmp(optarg, "user")) facility = LOG_USER; else if(!strcasecmp(optarg, "local0")) facility = LOG_LOCAL0; else if(!strcasecmp(optarg, "local1")) facility = LOG_LOCAL1; else if(!strcasecmp(optarg, "local2")) facility = LOG_LOCAL2; else if(!strcasecmp(optarg, "local3")) facility = LOG_LOCAL3; else if(!strcasecmp(optarg, "local4")) facility = LOG_LOCAL4; else if(!strcasecmp(optarg, "local5")) facility = LOG_LOCAL5; else if(!strcasecmp(optarg, "local6")) facility = LOG_LOCAL6; else if(!strcasecmp(optarg, "local7")) facility = LOG_LOCAL7; else return usage(p, EXIT_FAILURE); break; case 'K': flags |= FLG_NOACLID; case 'k': flags |= FLG_NOLID; break; case 'l': critical_left = atoi(optarg); break; case 'm': critical_margin = atoi(optarg); break; case 'n': flags |= FLG_NODETACH; break; case 'o': flags |= FLG_NOOFFB; break; case 'p': port = atoi(optarg); break; case 's': flags |= FLG_SIGPWR; break; case 'S': flags |= FLG_SHUTDOWN|FLG_SIGPWR; break; case 'u': flags |= FLG_NOTCP; break; case 'v': printf("%s\n", rcsid); return 0; case 'h': default : return usage(p, opt == 'h' ? EXIT_SUCCESS:EXIT_FAILURE); } openlog(p, syslog_options, facility); if(sigaction(SIGTERM, &sigterm, 0)) bye(EXIT_FAILURE, "could not install SIGTERM handler"); if(sigaction(SIGPIPE, &sigpipe, 0)) bye(EXIT_FAILURE, "could not install SIGPIPE handler"); syslog(LOG_INFO, "%s [treshold = %d, margin = %d] started", p, critical_left, critical_margin ); if(!validate_program(POWERLEVEL_SCRIPT)) bye(EXIT_FAILURE, POWERLEVEL_SCRIPT " is insecure, cannot start"); poll_init(); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "opening " ADB_FILE); adb_fd = open(ADB_FILE, O_RDWR); chk(adb_fd < 0, "Couldn't open " ADB_FILE); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "opening " PMU_FILE); pmu_fd = open(PMU_FILE, O_RDWR); if(pmu_fd < 0) pmu_fd = open(PMU_DEVFS_FILE, O_RDWR); chk(pmu_fd < 0, "Couldn't open " PMU_FILE " or " PMU_DEVFS_FILE); chk(fcntl(pmu_fd, F_GETFL, &fl) < 0, "fcntl(F_GETFL)"); fl |= O_NONBLOCK; chk(fcntl(pmu_fd, F_SETFL, &fl) < 0, "fcntl(F_SETFL)"); add_fd(pmu_fd, POLLIN, pmu_intr, NULL); fb0_fd = open(FB0_FILE, O_RDONLY); chk(fb0_fd < 0, "Couldn't open " FB0_FILE); if(!(flags&FLG_NOTCP)) { s = socket(PF_INET, SOCK_STREAM, 0); chk(s < 0, "Couldn't create socket"); sin.sin_family = AF_INET; sin.sin_port = htons(port); sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); len = sizeof(sin); sa = (struct sockaddr*)&sin; } else { s = socket(PF_UNIX, SOCK_STREAM, 0); chk(s < 0, "Couldn't create socket"); sun.sun_family = AF_UNIX; strcpy(sun.sun_path, SOCKET_FILE); chk(fchmod(s, 0600) < 0, "Couldn't change socket mode"); len = sizeof(sun); sa = (struct sockaddr*)&sun; } chk(bind(s, sa, len) < 0, "bind socket"); chk(listen(s, 5) < 0, "socket listen"); add_fd(s, POLLIN|POLLPRI, conn_sock, NULL); chk(getsockname(s, sa, &len) < 0, "getsockname"); if(!get_pmu_version()) bye(EXIT_FAILURE, "incorrect PMU version"); if(flags&FLG_APM) { #if 0 if(pmu_version == PMU_VERSION_3400) { flags &= ~FLG_APM; syslog(LOG_WARNING, "no apm support for 3400 present"); } else #endif apm_fd = open_apm(apmfile); } sprintf(sock_welcome, "pmud %s %d\n", PMUD_VERSION, pmu_version); if(!(flags&FLG_NODETACH)) { int pid = fork(); chk(pid < 0, "Couldn't fork"); if (pid > 0) bye(0, "parent exiting [note PID]"); chdir("/"); setsid(); close(0); close(1); close(2); } if ((f = fopen(POWER_FILE, "r")) != 0) { fscanf(f, "%d %d", &powerlevels[0], &powerlevels[1]); fclose(f); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "powerlevels from %s: %d %d", POWER_FILE, powerlevels[0], powerlevels[0] ); if(powerlevels[0] < 1 || powerlevels[0] > 3) { syslog(LOG_ERR, "invalid powerlevel (%d)" " for battery: setting to minimum", powerlevels[0] ); powerlevels[0] = 1; } if(powerlevels[1] < 1 || powerlevels[1] > 3) { syslog(LOG_ERR, "invalid powerlevel (%d)" " for AC: setting to maximum", powerlevels[1] ); powerlevels[1] = 2; } } if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "starting monitoring loop"); gettimeofday(&pmu_poll_time, NULL); for(chloralhydrate = 0; ; ) { gettimeofday(&now, NULL); if (!timercmp(&pmu_poll_time, &now, >)) poll_pmu(); if (chloralhydrate) { if(flags&FLG_SHUTDOWN) { if(do_sigpower('F')) sleep(120); } else snooze(powermode); chloralhydrate = 0; critical_time = 0; continue; } gettimeofday(&now, NULL); timersub(&pmu_poll_time, &now, &tleft); tms = tleft.tv_sec * 1000 + tleft.tv_usec / 1000 + 1; if(lid_closed) { unsigned char switches; if(pmu_op(PMU_GET_COVER,0,0,&switches,1,"switch req")<0) switches = 1; lid_closed = switches & 1; if(!lid_closed) { fbon(1); run_program(POWERLEVEL_SCRIPT, "lid-opened", ac ? "ac" : "battery" ); } } if(!do_poll(tms)) bye(EXIT_FAILURE, "could not poll PMU"); } } static int validate_program(char *p) { struct stat sb; if(p && *p && !stat(p, &sb)) { if(!sb.st_uid // owned by root && !(sb.st_mode & 022)) // only writeable by root return 1; } return 0; } static void poll_init(void) { nall_polls = 10; polls = malloc(nall_polls * sizeof(struct pollfd)); novm(polls, "poll table"); polli = malloc(nall_polls * sizeof(struct fd_info)); novm(polli, "poll info table"); npolls = 0; } static void add_fd( int fd, int events, void (*proc)(int, void *, int), void *arg ) { if (npolls >= nall_polls) { nall_polls = npolls + 10; polls = realloc(polls, nall_polls * sizeof(struct pollfd)); polli = realloc(polli, nall_polls * sizeof(struct fd_info)); } polls[npolls].fd = fd; polls[npolls].events = events; polls[npolls].revents = 0; polli[npolls].proc = proc; polli[npolls].arg = arg; ++npolls; } static void rem_fd(int fd, int events) { int i; for (i = 0; i < npolls; ++i) if (polls[i].fd == fd && polls[i].events == events) break; if (i >= npolls) return; for (--npolls; i < npolls; ++i) { if (i == ipoll_current) --ipoll_current; polls[i] = polls[i+1]; polli[i] = polli[i+1]; ++i; } } static int do_poll(unsigned to) { int i, nr; nr = poll(polls, npolls, to); if (nr < 0) { if (errno == EINTR) return 1; syslog(LOG_ERR, "poll (%m)"); return 0; } for (i = 0; i < npolls && nr > 0; ++i) { ipoll_current = i; if (polls[i].revents) { if (polls[i].revents & POLLNVAL) rem_fd(polls[i].fd, polls[i].events); else polli[i].proc(polls[i].fd, polli[i].arg, polls[i].revents); --nr; } i = ipoll_current; } return 1; } static int usage(char *name, int ret) { printf("usage: %s [args]\n\n" "\twhere [args] is:\n\n" "\t-a [] : emulate an apm file in \n" "\t-d : enable debugging text; this flag implicitly\n" "\t sets the -n flag to prevent backgrounding.\n" "\t-f : use for syslogd(8) messages.\n" "\t-h : this text.\n" "\t-k : do not detect lid close\n" "\t-K : do not detect lid close when on AC\n" "\t-l : the numbers of power left which\n" "\t is considered to be a critical low level.\n" "\t-m : the number of a critical low (see\n" "\t the -l flag) power level has to endure in\n" "\t order to enable sleeping|shutdown.\n" "\t-n : do not detach. With this option the daemon\n" "\t will not become a background process.\n" "\t-p : listen on for requestes.\n" "\t-s : send SIGPWR to init(8) on low power level;\n" "\t this does not put the machine to sleep as\n" "\t another SIGPWR needs to be send to init(8)\n" "\t when power is restored.\n" "\t-S : same as -s, but also send SIGPWR on every\n" "\t sleep request or closing of the lid\n" "\t-u : communicate through a AF_UNIX socket;\n" "\t-v : print the version string of %s.\n\n" "\tfor the following flags, you can also use long-flags\n\n" "\t-a [] : --apm []\n" "\t-d : --debug\n" "\t-f : --facility \n" "\t-h : --help\n" "\t-k : --nolid\n" "\t-K : --noaclid\n" "\t-l : --critical-left \n" "\t-m : --critical-margin \n" "\t-p : --port \n" "\t-s : --sigpower\n" "\t-v : --version\n", name, name ); return ret; } static int pmu_op( unsigned char cmd, unsigned char *par, int npar, void *res, int minres, const char *desc ) { unsigned char data[32]; int i, n; if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "pmu_op(0x%02x, ..., %s)\n", cmd, desc ? desc : "" ); data[0] = 6; /* packet for PMU */ data[1] = cmd; for (i = 0; i < npar; ++i) data[i+2] = par[i]; chk(write(adb_fd, data, npar+2) < 0, desc); n = read(adb_fd, data, sizeof(data)); chk(n < 0, desc); if (n < minres + 1 || data[0] != 0) { syslog(LOG_ERR, "huh? %d bytes from PMU:", n); for (i = 0; i < n; ++i) syslog(LOG_ERR, " %.2x", data[i]); return -1; } if (minres > 0) memcpy(res, data+1, minres); return n - 1; } static int get_pmu_version(void) { unsigned char vers; char *version[] = { "unknown (and unsupported)", // 0 "unknown (and unsupported)", // 1 "unknown (and unsupported)", // 2 "unknown (and unsupported)", // 3 "unknown (and unsupported)", // 4 "unknown (and unsupported)", // 5 "unknown (and unsupported)", // 6 "unknown (and unsupported)", // 7 "unknown (and unsupported)", // 8 "2400/3400/3500", // 9 "G3 Wallstreet", // 10 "1999 G3 Lombard", // 11 "iBook/G3 Pismo/G4 Titanium", // 12 "Wow, later than an Titanium! ;-)" // > 12 }; #define max_version (sizeof(version)/sizeof(char*)) static char env[16]; if (pmu_op(PMU_GET_VERSION, 0, 0, &vers, 1, "version req") < 0) bye(1, "could not determine PMU version"); pmu_version = abs(vers) > max_version ? max_version - 1 : vers; printf("PMU version %d: %s\n", vers, version[pmu_version]); syslog(LOG_INFO, "PMU version %d: %s", vers, version[pmu_version]); switch(vers) { case PMU_VERSION_3400: case PMU_VERSION_WALLSTREET: case PMU_VERSION_LOMBARD: case PMU_VERSION_KEYLARGO: break; #ifdef PMU_VERSION_UNSUPPORTED case PMU_VERSION_UNSUPPORTED: /* HACK: shut the machine down when lid is closed */ syslog(LOG_WARNING, "Sleep for this PMU unsupported: " "will shutdown the machine on sleep request"); flags |= FLG_SIGPWR; break; #endif default: return 0; } /* set an environment variable for pwrctl script to use */ sprintf(env, "PMUVERSION=%d", vers); putenv(env); return 1; } static void poll_pmu(void) { struct sockstate *ss, *ssnext; int n, pwr, vb, i; char status[64]; unsigned char switches; struct timeval now; int timeleft = -1; static int state = 0; int charging = 0; if (pmu_op(PMU_GET_COVER, 0, 0, &switches, 1, "switch req") < 0) return; if (pmu_version == PMU_VERSION_3400) { /* use extended battery request (6b) */ float j; unsigned char reply[8]; int pcharge, charge=0; int current=0; float lrange[] = { 0.0, 275.0, 850.0, 1680.0, 2325.0, 2765.0, 3160.0, 3500.0, 3830.0, 4115.0, 4360.0, 4585.0, 4795.0, 4990.0, 5170.0, 5340.0, 5510.0, 5710.0, 5930.0, 6150.0, 6370.0, 6500.0 }; if (pmu_op(PMU_BATTERY_STATE, 0, 0, reply, 8, "batt state") < 0) return; pwr = reply[0] & 1; /* AC indicator */ charging = reply[0] & 2; vb = (reply[1] << 8) + reply[2]; /* battery voltage */ for (i = 0; i < 8; ++i) status[i] = ((reply[0] >> (7 - i)) & 1) + '0'; sprintf(status+8, " %d %d %d %d %d %x\n", vb, reply[3], reply[4], reply[5], (reply[6] << 8) + reply[7], switches); if (!pwr) { if (reply[5] > 200) vb += (int)((reply[5] - 200) * 0.15); } else if (charging) vb -= 10; j = (330 - vb) / 10.0; i = (int) (j); if (i <= 0) charge = 0; else if (i >= 21) charge = 6500; else charge = (lrange[i+1]-lrange[i])*(j-(float)i)+lrange[i]; charge = (1000 - charge / 6.5) / 10; if (reply[0]&0x40) { pcharge = (reply[6] << 8) + reply[7];//pcharge if (pcharge > 6500) pcharge = 6500; pcharge = (1000 - pcharge / 6.5) / 10; if (pcharge < charge) charge = pcharge; } current=reply[5]; if (!pwr && (current > 0)) timeleft = (int)((charge * 274) / current) * 60; apm.battery_percentage = charge; if (apm.battery_percentage > 100) apm.battery_percentage = 100; } else { /* wallstreet/lombard, use smart battery request (6f) */ signed short batt[5], batt1, batt2; unsigned char par; int i, j; int charge, current; char *p = status; *p++ = 'S'; pwr = 0; charge = current = 0; batt1 = batt2 = 0; for (i = 0; i < 2; ++i) { par = i + 1; if (pmu_op(PMU_SMART_BATT, &par, 1, batt, sizeof(batt), "smart battery req") < 0) return; *p++ = ' '; *p++ = '{'; for (j = 0; j < 3; ++j) *p++ = ((batt[0] >> j) & 1) + '0'; pwr |= batt[0] & 1; if (batt[0] & 4) { /* have a battery */ charge += batt[1]; current += batt[3]; for (j = 1; j < 5; ++j) { sprintf(p, " %d", batt[j]); p += strlen(p); } if(!i) { batt1 = batt[1]; batt2 = batt[2]; /* * charging flag valid and * charging battery? */ charging = batt[0] & 0x02; } else { batt1 += batt[1]; batt2 += batt[2]; /* * charging flag valid and * charging battery? */ charging |= batt[0] & 0x02; } apm.battery_percentage = batt1 * 100; apm.battery_percentage /= batt2 ? batt2 : 1; } *p++ = '}'; } *p++ = '\n'; *p = 0; if (current < 0) timeleft = charge * 3552 / -current; } /* apm pseudo info */ if(flags&FLG_APM) { apm.apm_flags = 0; apm.ac_line_status = pwr; apm.battery_time = pwr ? 0 : timeleft; apm.using_minutes = 0; if(apm.battery_percentage <= APM_CRITICAL) { apm.battery_status = 0x02; apm.battery_flags = 0x04; } else if(apm.battery_percentage <= APM_LOW) { apm.battery_status = 0x01; apm.battery_flags = 0x02; } else { apm.battery_status = 0x00; apm.battery_flags = 0x01; } if(charging) { apm.battery_status = 0x03; apm.battery_flags |= 0x08; } } n = strlen(status); for (ss = all_sockets; ss != 0; ss = ssnext) { ssnext = ss->next; if (ss->nstat >= STAT_OUTSTANDING) continue; switch (send_socket(ss, status, n)) { case 1: ++ss->nstat; break; case -1: delete_socket(ss); break; } } if ((switches & 1) != 0) { if(!lid_closed) { lid_closed=1; fbon(0); run_program(POWERLEVEL_SCRIPT, "lid-closed", pwr ? "ac" : "battery" ); } if(!(flags&FLG_NOLID) || (!pwr && (flags&FLG_NOACLID))) { syslog(LOG_INFO, "lid closed: request sleep"); chloralhydrate = 1; /* lid is closed, go to sleep */ } } if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "timeleft = %d", timeleft); if (!pwr && timeleft >= 0 && timeleft < critical_left) { apm.battery_status = 2; /* critical */ beep(BEEP_TIME, BEEP_WARN); if(!(state&FLG_SIGPWR)) { if((critical_time == 5 || critical_time >= critical_margin) && !(state&FLG_WARN)) { run_program(POWERLEVEL_SCRIPT, "warning", "battery" ); state |= FLG_WARN; } if (++critical_time >= critical_margin) { beep(BEEP_TIME, BEEP_WARN); syslog(LOG_CRIT, "battery critically low: %s\n", flags&FLG_SIGPWR ? "sending SIG_PWR to init" : "request system sleep" ); if((flags&FLG_SIGPWR) && do_sigpower('F')) state |= FLG_SIGPWR; else chloralhydrate = 1; } else if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "critical margin not " "reached %d : %d", critical_time, critical_margin ); } } else { critical_time = 0; if(state&FLG_SIGPWR) { state &= ~FLG_SIGPWR; do_sigpower('O'); } state &= ~FLG_WARN; } powermode = pwr; if (powerlevels[pwr] != powerlevel) { set_power(powerlevels[pwr], powermode); powerlevel = powerlevels[pwr]; } gettimeofday(&now, NULL); ++pmu_poll_time.tv_sec; if (timercmp(&pmu_poll_time, &now, <)) { pmu_poll_time = now; ++pmu_poll_time.tv_sec; } if(flags&FLG_APM) { if(apm_fd < 0) apm_fd = open_apm(apmfile); if(apm_fd >= 0) apm_data(apm_fd, &apm); } } static void pmu_intr(int fd, void *arg, int ev) { unsigned char intr[16]; int i, n; char str[8]; n = read(fd, intr, sizeof(intr)); if (n <= 0) { if (n < 0) syslog(LOG_ERR, "read pmu (%m)"); rem_fd(fd, POLLIN); return; } switch (intr[0]) { case 0x80: /* tick interrupt */ if (n != 1) break; ++ntick; return; case 4: /* PC card eject button */ if (n < 3 || intr[2] < 1 || intr[2] > 2) break; if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "eject of PC card noticed"); sprintf(str, "%d", intr[2] - 1); run_program("/sbin/cardctl", "eject", str); return; } if(flags&FLG_DEBUG) { syslog(LOG_INFO, "PMU interrupt:"); for (i = 0; i < n; ++i) syslog(LOG_INFO, " %.2x", intr[i]); } } static int send_socket(struct sockstate *ss, char *p, int nb) { int n; if (ss->out_pending != 0) return 0; n = sock_write(ss, p, nb); if (n < 0) return -1; if ((nb -= n) > 0) { memcpy(ss->outbuf, p + n, nb); ss->outptr = ss->outbuf; ss->out_pending = nb; add_fd(ss->fd, POLLOUT, send_more, ss); } return 1; } static void send_more(int fd, void *arg, int ev) { struct sockstate *ss = arg; int n; if (ss->out_pending == 0) return; n = sock_write(ss, ss->outptr, ss->out_pending); if (n < 0) { /* oops, looks bad */ delete_socket(ss); return; } ss->outptr += n; ss->out_pending -= n; if (ss->out_pending == 0) rem_fd(fd, POLLOUT); } static int sock_write(struct sockstate *ss, char *ptr, int nb) { int n; n = write(ss->fd, ptr, nb); if (n < 0) { if (errno == EWOULDBLOCK || errno == EAGAIN) n = 0; else syslog(LOG_ERR, "write socket (%m)"); } return n; } static void conn_sock(int fd, void *arg, int ev) { int fe, fl; struct sockstate *ss; fe = accept(fd, NULL, 0); chk(fcntl(fe, F_GETFL, &fl) < 0, "fcntl(F_GETFL)"); fl |= O_NONBLOCK; chk(fcntl(fe, F_SETFL, &fl) < 0, "fcntl(F_SETFL)"); ss = malloc(sizeof(*ss)); if (ss == 0) { syslog(LOG_ERR, "warning: no space for socket state\n"); close(fe); return; } memset(ss, 0, sizeof(*ss)); ss->fd = fe; ss->next = all_sockets; ss->prevp = &all_sockets; if (all_sockets != 0) all_sockets->prevp = &ss->next; all_sockets = ss; add_fd(fe, POLLIN, read_sock, ss); send_socket(ss, sock_welcome, strlen(sock_welcome)); } static void delete_socket(struct sockstate *ss) { rem_fd(ss->fd, POLLIN); rem_fd(ss->fd, POLLOUT); close(ss->fd); *ss->prevp = ss->next; free(ss); } static void read_sock(int fd, void *arg, int ev) { struct sockstate *ss = arg; int n; int c = ss->inb_cnt; char *p; n = read(fd, ss->inbuf + c, sizeof(ss->inbuf) - c - 1); if (n <= 0) { if (n < 0) { if (errno == EWOULDBLOCK || errno == EAGAIN) return; if (errno != ECONNRESET) syslog(LOG_ERR, "read socket (%m)"); } delete_socket(ss); return; } ss->inbuf[c + n] = 0; p = strchr(&ss->inbuf[c], '\n'); c += n; if (p == 0) { if (c < sizeof(ss->inbuf) - 1) { ss->inb_cnt = c; return; } } else { c = p - ss->inbuf; *p++ = 0; } if (c > 0 && ss->inbuf[c-1] == '\r') ss->inbuf[c-1] = 0; do_cmd(ss); c = 0; if (p != 0 && *p != 0) { c = strlen(p); memmove(ss->inbuf, p, c); } ss->inb_cnt = c; } static void do_cmd(struct sockstate *ss) { char *p, *q; for (p = ss->inbuf; isspace(*p); ++p) ; if (*p == 0) { /* acknowledgement of status */ if (ss->nstat) --ss->nstat; return; } for (q = p; *q != 0 && !isspace(*q); ++q) ; if (*q != 0) for (*q++ = 0; isspace(*q); ++q) ; if (strcmp(p, "sleep") == 0) { syslog(LOG_INFO, "initiating user requested sleep"); chloralhydrate = 1; /* go to sleep */ } else if (strcmp(p, "power") == 0) do_power(ss, q); } static void do_power(struct sockstate *ss, char *args) { int p1, p2; char str[32]; FILE *f; switch (sscanf(args, "%d %d", &p1, &p2)) { case -1: case 0: sprintf(str, "%d %d\n", powerlevels[0], powerlevels[1]); send_socket(ss, str, strlen(str)); return; case 1: powerlevels[powermode] = p1; break; case 2: powerlevels[0] = p1; powerlevels[1] = p2; break; } f = fopen(POWER_FILE, "w"); if (f != 0) { if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "writing %d %d to %s", powerlevels[0], powerlevels[1], POWER_FILE ); fprintf(f, "%d %d\n", powerlevels[0], powerlevels[1]); fclose(f); } else syslog(LOG_ERR, "Couldn't store power settings in " POWER_FILE); if (powerlevels[powermode] != powerlevel) { set_power(powerlevels[powermode], powermode); powerlevel = powerlevels[powermode]; } } static void set_power(int level, int ac) { run_program(POWERLEVEL_SCRIPT, level == 1 ? "minimum" : level == 2 ? "medium" : level == 3 ? "maximum" : "error", ac ? "ac" : "battery" ); } static void snooze(int ac) { int ts = 0; /* initialized to stop gcc from complaining */ int level; int id; if(!(flags&FLG_NOOFFB)) (void) ioctl(pmu_fd, PMU_IOC_GET_BACKLIGHT, &level); fbon(0); lid_closed=1; id = get_trackpad_id(adb_fd); if(id >= 0) ts = get_trackpad_settings(adb_fd, id); beep(BEEP_TIME, BEEP_OK); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "calling sync()"); sync(); run_program(POWERLEVEL_SCRIPT, "sleep", ac ? "ac" : "battery"); syslog(LOG_INFO, "going to sleep"); if (ioctl(pmu_fd, PMU_IOC_SLEEP, 0) < 0) syslog(LOG_ALERT, "cannot put system to sleep! (%m)"); else syslog(LOG_INFO, "system awake again"); beep(BEEP_TIME, BEEP_OK); if(id >= 0) set_trackpad_settings(adb_fd, id, ts); gettimeofday(&pmu_poll_time, NULL); run_program(POWERLEVEL_SCRIPT, "wakeup", ac ? "ac" : "battery"); if(!(flags&FLG_NOOFFB)) (void) ioctl(pmu_fd, PMU_IOC_SET_BACKLIGHT, &level); } /* * This is very insecure.... */ static void run_program(char *prog, char *a1, char *a2) { pid_t pid; int status = 0; static int maxfiles = 0; if(!maxfiles) { struct rlimit l; if(!getrlimit(RLIMIT_NOFILE, &l)) maxfiles = l.rlim_cur; } syslog(LOG_INFO, "running %s %s %s", prog, a1 ? a1 : "", a1 && a2 ? a2 : "" ); if(!validate_program(prog)) { syslog(LOG_ALERT, "refuse to run insecure %s", prog); return; } pid = fork(); if (pid == 0) { char *argv[4]; register int i; for(i=0; i < maxfiles; i++) close(i); /* stdin, stdout and stderr to /dev/null */ open("/dev/null", O_RDONLY); open("/dev/null", O_WRONLY); open("/dev/null", O_WRONLY); argv[0] = prog; argv[1] = a1; argv[2] = a2; argv[3] = 0; execv(prog, argv); exit(99); } waitpid(pid, &status, 0); if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) syslog(LOG_ERR, "%s exited with code %d\n", prog, WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) syslog(LOG_ERR, "%s got signal %d\n", prog, WTERMSIG(status)); } static void do_signal(int signum) { char msg[32]; sprintf(msg, "catched signal %d", signum); bye(signum == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE, msg); } static int do_sigpower(char level) { int fd = open(POWERSTATUS_FILE, O_RDWR|O_TRUNC|O_CREAT); if(fd < 0) { syslog(LOG_ALERT, "open of %s failed (%m) reverting to sleep", POWERSTATUS_FILE ); flags &= ~FLG_SIGPWR; return 0; } write(fd, &level, 1); close(fd); return !kill(1, SIGPWR); } static void bye(int ret, const char *msg) { if(ret) beep(BEEP_TIME, BEEP_ERR); syslog(ret == EXIT_SUCCESS ? LOG_INFO : LOG_ERR, "daemon stopped (%s)", msg && *msg ? msg : "no additional information" ); exit(ret); } static int open_apm(char *file) { int fd; struct stat sb; if(!file || !*file) { syslog(LOG_ERR, "open_apm: no apmfile specified"); return -1; } errno = 0; if(!stat(file, &sb) && !S_ISFIFO(sb.st_mode)) { syslog(LOG_ERR, "apmfile '%s' exists, but is not a FIFO", file); return -1; } if(errno == ENOENT && mkfifo(file, 0644)) { syslog(LOG_ERR, "error creating '%s': %m", file); return -1; } fd = open(file, O_WRONLY|O_NONBLOCK); return fd; } static void apm_data(int fd, struct my_apm_info *apm) { char data[128]; if(fd < 0 || !apm) return; if(apm->battery_time >= APM_THRESHOLD) { apm->battery_time /= 60; apm->using_minutes = 1; } snprintf(data, sizeof(data), "%s %s %x %x %x %x %d%% %d %s\n", PMUD_SERVICE, PMUD_VERSION, apm->apm_flags, apm->ac_line_status, apm->battery_status, apm->battery_flags, apm->battery_percentage, apm->battery_time, apm->using_minutes ? "min" : "sec" ); (void) write(fd, data, strlen(data)); } static int get_trackpad_id(int fd) { int n; int id = -1; register int i; if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "polling adb for trackpad"); /* always poll all devices, someone might have attached a mouse * while sleeping and thus maybe address relocation occured */ for (i=1; i<0x10; i++) { unsigned char buf[9]; if(adbwrite(fd, i, 1, ADBtalk, 0, 0) <= 0) continue; n = adbread(fd, i, buf, sizeof(buf)); /* must read tpad */ if(n >= 5 && buf[1] == 't' && buf[2] == 'p' && buf[3] == 'a' && buf[4] == 'd') { id = i; break; } } if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "found %s trackpad (id = %d)", id < 0 ? "no" : "a", id ); return id; } static int get_trackpad_settings(int fd, int id) { int nr; int settings = 0; unsigned char buf[9]; if(adb_program(fd, id, 1) < 0) return 0; if(adbwrite(fd, id, 2, ADBtalk, 0, 0) <= 0) { syslog(LOG_ERR, "get.get adbwrite: %m"); return -1; } nr = adbread(fd, id, buf, sizeof(buf)); if(nr >= 5) { settings |= buf[1] == 0x99 ? TPS_TAP : 0; settings |= buf[2] == 0x94 ? TPS_DRAG : 0; settings |= buf[4] == 0xff ? TPS_LOCK : 0; } adb_program(fd, id, 0); if(flags&FLG_DEBUG) syslog(LOG_DEBUG, "trackpad settings %stap %sdrag %slock", settings & TPS_TAP ? "" : "no", settings & TPS_DRAG ? "" : "no", settings & TPS_LOCK ? "" : "no" ); return settings; } static int set_trackpad_settings(int fd, int id, int settings) { int nr; int tries = 5; unsigned char buf[9]; if(adb_program(fd, id, 1) < 0) return 0; while(tries--) { if(adbwrite(fd, id, 2, ADBtalk, 0, 0) <= 0) { syslog(LOG_ERR, "set.get adbwrite: %m"); continue; } nr = adbread(fd, id, buf, sizeof(buf)); if(nr < 5) continue; buf[1] = settings & TPS_TAP ? 0x99 : 0x19; buf[2] = settings & TPS_DRAG ? 0x94 : 0x14; buf[4] = settings & TPS_LOCK ? 0xff : 0xb2; /* * Fix iBook2 jittery trackpad after wake from sleep * This was taken from drivers/macintosh/adbhid.c * and is part of how the trackpad is initialized. */ if(nr>6) buf[6] = 0x0d; if(adbwrite(fd, id, 2, ADBlisten, buf+1, nr) <= 0) { syslog(LOG_ERR, "set.set adbwrite: %m"); continue; } nr = adbread(fd, id, buf, sizeof(buf)); } adb_program(fd, id, 0); if(flags&FLG_DEBUG) { syslog(LOG_DEBUG, "requested settings %stap %sdrag %slock", settings & TPS_TAP ? "" : "no", settings & TPS_DRAG ? "" : "no", settings & TPS_LOCK ? "" : "no" ); settings = get_trackpad_settings(fd, id); } return 0; } static int adb_program(int fd, int id, int on) { int nr; int tries = 5; unsigned char buf[16]; while(tries--) { if(adbwrite(fd, id, 1, ADBtalk, 0, 0) <= 0) { syslog(LOG_ERR, "program.get adbwrite: %m"); continue; } nr = adbread(fd, id, buf, sizeof(buf)); if(nr < 8) continue; buf[7] = on ? 0x0d : 0x03; errno=0; if((nr=adbwrite(fd, id, 1, ADBlisten, buf+1, nr-1)) < 0) { syslog(LOG_ERR, "program.set adbwrite: %m (%d)", nr); continue; } return adbread(fd, id, buf, sizeof(buf)); } return -1; } static int adbwrite(int fd, char id, char reg, char op, char *data, int size) { adbpacket_t packet; packet.preamble = ADB_PACKET; switch(op) { case ADBlisten: packet.control = ADB_WRITEREG(id, reg); break; case ADBtalk: packet.control = ADB_READREG(id, reg); break; default: syslog(LOG_ERR, "adbwrite: unknown op = (%d)", op); return -1; } if(size < 0 || size > ADB_DATA_LEN) { syslog(LOG_ERR, "adbwrite: invalid data lenght = (%d)", size); return -1; } if(size) memcpy(packet.data, data, size); return write(fd, &packet, size + 2); } static int adbread(int fd, char id, char *data, int size) { int nr; adbpacket_t packet; char *raw = ((char*)&packet)+1; packet.preamble = (id << 4); do { nr = read(fd, raw, sizeof(packet) - 1); if(nr <= 0) return nr; } while((packet.control & 0xf0) != (id<<4)); if(nr > 0) memcpy(data, raw, size >= nr ? size : nr); return nr; } static void fbon(int on) { ioctl(fb0_fd, FBIOBLANK, !on); } static void beep(unsigned int ms, unsigned int freq) { int arg; static int fd = -1; if (fd < 0) { fd = open(CONSOLE_FILE, O_RDWR); if (fd < 0) return; } arg = (ms << 16) | freq; ioctl(fd, KDMKTONE, arg); usleep(ms*1000); } pmud-0.10.orig/pmud.h0100664000076400007640000000450207407056563014430 0ustar schmitzschmitz/* * $Id: pmud.h,v 1.1.1.1 2001/12/07 11:31:44 sleemburg Exp $ * * definitions for pmud - PMU daemon for Linux/PPC on Powerbooks. * * Copyright 1999 Paul Mackerras, Stephan Leemburg. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * $Log: pmud.h,v $ * Revision 1.1.1.1 2001/12/07 11:31:44 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.4 2000/05/11 14:54:24 stephan * pmud 0.6 changes * * Revision 1.3 2000/03/09 18:58:53 stephan * path of powerstatus was incorrectly prepended with /etc/power * * Revision 1.2 2000/03/09 13:00:25 stephan * paths changed, some apm definitions for future work. * * Revision 1.1 2000/01/06 13:48:19 stephan * Initial revision * */ #ifndef HDR_PMUD_H #define HDR_PMUD_H #include #define PMUD_VERSION "0.10" #define PMU_FILE "/dev/pmu" #define PMU_DEVFS_FILE "/dev/misc/pmu" #define ADB_FILE "/dev/adb" #define FB0_FILE "/dev/fb0" #define POWERDIR "/etc/power" #define POWERLEVEL_SCRIPT POWERDIR "/pwrctl" #define POWER_FILE POWERDIR "/levels" #define SOCKET_FILE POWERDIR "/control" #define CONSOLE_FILE "/dev/console" #ifndef POWERSTATUS_FILE #define POWERSTATUS_FILE "/etc/powerstatus" #endif #define PORT 879 #define PMU_VERSION_3400 9 #define PMU_VERSION_WALLSTREET 10 /* a (good) guess */ #define PMU_VERSION_LOMBARD 11 #define PMU_VERSION_KEYLARGO 12 /* another guess */ #define PMU_FACILITY LOG_DAEMON #define PMU_SYSLOG_OPTIONS (LOG_CONS|LOG_PID) #define PMUD_SERVICE "pmud" #ifndef APM_FILE #define APM_FILE POWERDIR "/apm" #endif #define APM_FAKEFLAGS 0x02 #define APM_CRITICAL 10 #define APM_LOW 30 #define APM_THRESHOLD 600 /* * Go to sleep if we have <= this many seconds of battery power remaining * * 7 minutes seems the best time for my G3 Wallstreet Powerbook (Stephan) */ #define CRITICAL_TIMELEFT 420 /* Require power to be critically low for this many seconds before sleeping */ #define CRITICAL_TIME 15 #define BEEP_TIME 150 #define BEEP_OK 1000 #define BEEP_WARN 2000 #define BEEP_ERR 4000 #endif /* HDR_PMUD_H */ pmud-0.10.orig/pmud.rc0100775000076400007640000000156707404124240014601 0ustar schmitzschmitz#! /bin/sh # # pmud Power Manager daemon for Apple powerbooks # # chkconfig: 2345 40 60 # description: pmud is a daemon which periodically polls the PMU \ # (power manager) and performs functions such as enabling \ # or disabling devices appropriately when the power source \ # changes. # processname: pmud # config: /etc/powerlevels # pidfile: /var/run/pmud.pid # Source function library. . /etc/rc.d/init.d/functions # Source power daemon options [ -f /etc/sysconfig/power ] && . /etc/sysconfig/power # See how we were called. case "$1" in start) echo -n "Starting pmud daemon: " daemon pmud $PMUD_FLAGS echo touch /var/lock/subsys/pmud ;; stop) echo -n "Stopping pmud daemon: " killproc pmud echo rm -f /var/lock/subsys/pmud ;; status) status pmud ;; *) echo "Usage: pmud {start|stop|status}" exit 1 esac exit 0 pmud-0.10.orig/pmud.spec0100664000076400007640000000435607407067315015137 0ustar schmitzschmitz%define version 0.10 %define release 1 Name: pmud Distribution: LinuxPPC June 1999 and 2000 Version: %version Release: %release Summary: Power Manager daemon for Apple powerbooks Source: pmud-%{version}.%{release}.tar.gz Copyright: GPL Group: Utilities/System Packager: Stephan Leemburg BuildRoot: /var/tmp/pmud-%{version}.%{release}-buildroot Provides: apmd Prereq: chkconfig ExclusiveArch: ppc %description pmud is a daemon which periodically polls the PMU (power manager) and performs functions such as enabling or disabling devices appropriately when the power source changes. It can also be instructed to signal init(8) that a power- failure has occured. %prep %setup %build make %install rm -fr $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/sbin mkdir -p $RPM_BUILD_ROOT/usr/X11R6/bin mkdir -p $RPM_BUILD_ROOT/usr/bin mkdir -p $RPM_BUILD_ROOT/etc/power mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d mkdir -p $RPM_BUILD_ROOT/etc/sysconfig mkdir -p $RPM_BUILD_ROOT/usr/man/man8 install -c pmud $RPM_BUILD_ROOT/sbin install -c wakebay $RPM_BUILD_ROOT/sbin install -c pwrctl $RPM_BUILD_ROOT/etc/power install -c snooze $RPM_BUILD_ROOT/sbin install -c fblevel $RPM_BUILD_ROOT/sbin install -c xmouse $RPM_BUILD_ROOT/usr/X11R6/bin install -c Batmon $RPM_BUILD_ROOT/usr/bin install -m 0644 power.conf $RPM_BUILD_ROOT/etc/sysconfig/power cp pmud.rc $RPM_BUILD_ROOT/etc/rc.d/init.d/pmud cp pmud.8 $RPM_BUILD_ROOT/usr/man/man8 cp snooze.8 $RPM_BUILD_ROOT/usr/man/man8 cp fblevel.8 $RPM_BUILD_ROOT/usr/man/man8 cp batmon.8 $RPM_BUILD_ROOT/usr/man/man8 cp xmouse.8 $RPM_BUILD_ROOT/usr/man/man8 %clean rm -rf $RPM_BUILD_ROOT %pre [ -c /dev/pmu ] || { echo "creating /dev/pmu" mknod /dev/pmu c 10 154 } [ -c /dev/adb ] || { echo "creating /dev/adb" mknod /dev/adb c 56 0 } %post ln -s /sbin/snooze /usr/bin/apm /sbin/chkconfig --add pmud %files %defattr(-,root,root) /sbin/pmud /sbin/snooze /sbin/wakebay /sbin/fblevel /usr/X11R6/bin/xmouse /usr/bin/Batmon /etc/power/pwrctl /etc/rc.d/init.d/pmud /etc/sysconfig/power %doc TODO %doc BUGS %doc README %doc INSTALL %doc CHANGES %doc THANKS %doc pwrctl-local %doc contrib %doc /usr/man/man8/pmud.8* %doc /usr/man/man8/snooze.8* %doc /usr/man/man8/fblevel.8* %doc /usr/man/man8/batmon.8* %doc /usr/man/man8/xmouse.8* pmud-0.10.orig/power.conf0100664000076400007640000000237407404124242015305 0ustar schmitzschmitz# ----------------------------------------------------------------------------- # Specify the pmud start flags here, you can use the following flags: # ----------------------------------------------------------------------------- # -d : enable debugging text; this flag implicitly # sets the -n flag to prevent backgrounding. # -f : use for syslogd(8) messages. # -h : this text. # -l : the numbers of power left which # is considered to be a critical low level. # -m : the number of a critical low (see # the -l flag) power level has to endure in # order to enable sleeping|shutdown. # -n : do not detach. With this option the daemon # will not become a background process. # -p : listen on for requestes. # -s : send SIGPWR to init(8) on low power level; # this does not put the machine to sleep as # another SIGPWR needs to be send to init(8) # when power is restored. # -v : print the version string of pmud. # # see also pmud(8) # ----------------------------------------------------------------------------- PMUD_FLAGS= pmud-0.10.orig/pwrctl0100775000076400007640000001204507407066302014544 0ustar schmitzschmitz#!/bin/bash # ----------------------------------------------------------------------------- # $Id: pwrctl,v 1.1.1.1 2001/12/07 11:31:53 sleemburg Exp $ # # This script is invoked by pmud to configure the system for a # given power level. The desired level is indicated by the first # argument and can take the following values: # # minimum = minimum power # medium = medium power # maximum = full power # sleep = prepare for sleep # wakeup = system woke up after a sleep # warning = low battery condition detected, issue a warning to users # # the second argument gives the current power source, and can take the # following values: # # ac # battery # # This script is invoked when the AC power is connected or disconnected, # and also immediately after sleep. If the script /etc/power/pwrctl-local # is present and executable, it will be called by this script before the # main body of this script is executed. If pwrctl-local returns 1, then # the main body of this script is NOT executed, in all other cases the # main body of this script will be executed. # # Note that if you leave pwrctl-local writable by others than root (which # should be the owner) you have created a serious security hole! # # You can edit this file, but it's better to edit /etc/power/pwrctl-local # as that file will not be overwritten on upgrades. # ----------------------------------------------------------------------------- # $Log: pwrctl,v $ # Revision 1.1.1.1 2001/12/07 11:31:53 sleemburg # Initial CVS import of the unreleased pmud-0.8 to apmud (new project name # because of a name clash at sourceforge.net). # # Revision 1.6 2000/12/12 08:56:57 stephan # support for iBook and Pismo (same as other G3's) # # Revision 1.5 2000/10/09 14:33:40 stephan # wakebay added # # Revision 1.4 2000/05/11 14:54:45 stephan # pmud 0.6 changes # # Revision 1.3 2000/03/25 21:26:32 stephan # pmud-0.5 changes # # Revision 1.2 2000/03/09 13:01:50 stephan # formatting and call to pwrctl-local # # Revision 1.1 2000/01/06 13:48:19 stephan # Initial revision # ----------------------------------------------------------------------------- logger=/usr/bin/logger localfun=/etc/power/pwrctl-local function do_warn() { local msg="Low battery, system will go down..." ( /usr/X11R6/bin/xmessage -center -timeout 15 "$msg" || \ /usr/bin/wall "$msg" ) & } function pwrctl_G3() { case "$1" in minimum) # min power, set disk to spin down after 1 minute hdparm -p -S 12 /dev/hda ;; medium) hdparm -p -S 12 /dev/hda ;; maximum) case "$2" in ac) # on mains, do not spin down hdparm -p -S 0 /dev/hda ;; *) # on battery, set disk to spin down after 5 minute hdparm -p -S 60 /dev/hda ;; esac ;; warning) do_warn ;; lid-closed) ;; lid-opened) ;; sleep) ;; wakeup) [ -f /proc/sys/dev/cdrom/info ] && { device=$(cat /proc/sys/dev/cdrom/info | ( IFS=":" while read var val do [ "$var" = "drive name" ] && { echo $val break } done )) [ ! -z "$device" ] && { /sbin/wakebay /dev/${device} } } ;; *) $logger -p daemon.error -t pwrctl "$0: invalid arg $1" ;; esac } # ----------------------------------------------------------------------------- # On the 3400, for minimum power, we put the CPU into nap mode # (rather than doze mode) when it is idle. This reduces power # consumption but means that DMA is no longer cache coherent. # Therefore we have to disable DMA, including the ethernet. # We also turn the ethernet off during sleep. # ----------------------------------------------------------------------------- function pwrctl_3400() { case "$1" in minimum) ifconfig eth0 down hdparm -d0 -S 12 /dev/hda hdparm -d0 /dev/hdc echo 1 >/proc/sys/kernel/powersave-nap ;; medium) echo 0 >/proc/sys/kernel/powersave-nap hdparm -d1 -p -S 12 /dev/hda hdparm -d1 /dev/hdc ifconfig eth0 up ;; maximum) echo 0 >/proc/sys/kernel/powersave-nap case "$2" in ac) # on mains, do not spin down hdparm -d1 -p -S 0 /dev/hda ;; *) # on battery, set disk to spin down after 5 minute hdparm -d1 -p -S 60 /dev/hda ;; esac hdparm -d1 /dev/hdc ifconfig eth0 up ;; warning) do_warn ;; sleep) ifconfig eth0 down ;; wakeup) ifconfig eth0 up ;; *) $logger -p daemon.error -t pwrctl "$0: invalid arg $1" ;; esac } # ----------------------------------------------------------------------------- # main # ----------------------------------------------------------------------------- [ -x $localfun ] && { $logger -p daemon.info -t pwrctl "calling $localfun $*" $localfun $* case $? in 0) $logger -p daemon.debug -t pwrctl "continuing with main" ;; 1) $logger -p daemon.debug -t pwrctl "skipping main" exit 0 ;; *) $logger -p daemon.error -t pwrctl "error in $localfun" ;; esac } case "$PMUVERSION" in 9) pwrctl_3400 $1 $2 ;; 1[012]) pwrctl_G3 $1 $2 ;; *) $logger -p daemon.error -t pwrctl "no function for PMU $PMUVERSION" ;; esac >>/var/log/pwrctls 2>&1 exit 0 pmud-0.10.orig/pwrctl-local0100775000076400007640000000437207407066343015645 0ustar schmitzschmitz#!/bin/bash # ----------------------------------------------------------------------------- # $Id: pwrctl-local,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $ # # This script is invoked by pwrctl to configure the system for a # given power level. The desired level is indicated by the first # argument, which can have the following values: # # minimum = minimum power # medium = medium power # maximum = full power # sleep = prepare for sleep # wakeup = system woke up after a sleep # warning = low battery condition detected, issue a warning to users # # the second argument gives the current power source, and can take the # following values: # # ac # battery # # # This script can be invoked by pwrctl when it is named /etc/power/pwrctl-local # and is executable. Pwrctl is called by pmud on a power event. If this # script returns the value 1, then pwrctl will skip it's main body # ----------------------------------------------------------------------------- # $Log: pwrctl-local,v $ # Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg # Initial CVS import of the unreleased pmud-0.8 to apmud (new project name # because of a name clash at sourceforge.net). # # Revision 1.2 2000/03/25 21:26:37 stephan # pmud-0.5 changes # # Revision 1.1 2000/03/09 13:02:18 stephan # Initial revision # # ----------------------------------------------------------------------------- logger=/usr/bin/logger # ----------------------------------------------------------------------------- # main # ----------------------------------------------------------------------------- case "$1" in minimum) $logger -p daemon.info -t pwrctl-local "minimum power $2" ;; medium) $logger -p daemon.info -t pwrctl-local "medium power $2" ;; maximum) $logger -p daemon.info -t pwrctl-local "maximum power $2" $logger -p daemon.info -t pwrctl-local "skipping pwrctl-main" exit 1 ;; warning) /usr/bin/wall "Low battery, system going down any minute now" ;; lid-closed) $logger -p daemon.info -t pwrctl-local "lid-closed $2" ;; lid-opened) $logger -p daemon.info -t pwrctl-local "lid-opened $2" ;; sleep) $logger -p daemon.info -t pwrctl-local "sleep $2" ;; wakeup) $logger -p daemon.info -t pwrctl-local "sleep $2" ;; *) $logger -p daemon.error -t pwrctl-local "invalid arg $1 $2" exit 2 ;; esac exit 0 pmud-0.10.orig/snooze.80100664000076400007640000000325407404124243014707 0ustar schmitzschmitz.\" Copyright (c) 2000 Stephan Leemburg .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" .\" $Log: snooze.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:47 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name .\" because of a name clash at sourceforge.net). .\" .\" Revision 1.2 2000/03/09 13:03:08 stephan .\" pmud-0.4 modifications .\" .\" Revision 1.1 2000/01/06 13:48:19 stephan .\" Initial revision .\" .\" .Dd Februari 10, 2000 .Dt SNOOZE 8 .Os "LinuxPPC pmud" .Sh NAME .Nm snooze .Nd will put an Apple Macintosh Powerbook into sleep. .Sh SYNOPSIS .Nm snooze .Op Fl hv .Op Fl f .Op Fl p Ar port .Sh DESCRIPTION .Nm Snooze is a program, which is usefull only for Apple Macintosh Powerbooks. On invocation, it will request the machine to put itself into sleep. This is done by connecting to .Nm pmud and give .Nm pmud the command to put the machine to sleep. You can override the portnumber with the .Op Fl p Ar port option. If you invoke .Nm snooze with the .Op Fl f option, then .Nm snooze will put the machine into sleep itself. This is NOT recommended, because you will not get the benefits of all the facilities that .Nm pmud has to offer. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh FILES .nf /dev/pmu .fi .Sh AUTHORS initial pmud package by Paul Mackerras and initial manual and changes to pmud-0.[34] by Stephan Leemburg . .Sh SEE ALSO .Xr pmud(8) pmud-0.10.orig/snooze.c0100664000076400007640000000772007406745636015005 0ustar schmitzschmitz/* * snooze - put Linux/PPC Powerbooks to sleep. * At present this supports the PB2400/3400/3500, * the 1999 G3 Powerbooks (aka "Lombard"), and the * previous generation of G3 Powerbooks (aka "Wallstreet"). * * Copyright 1999 Paul Mackerras. * Copyright 2000 Stephan Leemburg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * $Log: snooze.c,v $ * Revision 1.1.1.1 2001/12/07 11:31:47 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.6 2001/11/09 10:55:29 stephan * use "pmu.h" * * Revision 1.5 2001/11/09 10:48:07 stephan * location of pmu.h changed * * Revision 1.4 2000/05/11 14:55:01 stephan * pseudo apm compatibility * * Revision 1.3 2000/03/25 21:26:40 stephan * pmud-0.5 changes * * Revision 1.2 2000/03/09 13:03:27 stephan * now call pmud for putting machine to sleep * * Revision 1.1 2000/01/06 13:48:19 stephan * Initial revision * */ static char *rcsid = "@(#)$Id: snooze.c,v 1.1.1.1 2001/12/07 11:31:47 sleemburg Exp $"; #include #include #include #include #include #include #include #include #include #include #include #include "pmu.h" #include "pmud.h" #include "tcp.h" static int usage(char *, int); static int do_sleep(); static int net_sleep(int); int main(int ac, char **av) { struct option options[] = { {"force", 0, 0, 'f'}, {"help", 0, 0, 'h'}, {"port", 1, 0, 'p'}, {"snooze", 1, 0, 's'}, {"standby", 1, 0, 'S'}, {"version", 0, 0, 'v'}, {0, 0, 0, 0} }; int opt; unsigned short port = PORT; int force = 0; // there is a bug in basename() char *p = strrchr(*av, '/'); p = p ? p + 1 : *av; while((opt=getopt_long(ac, av, "fhp:sSv", options, 0))!= EOF) switch(opt) { case 'p': port = atoi(optarg); break; case 'f': force++; break; case 'v': printf("%s\n", rcsid); return 0; case 's': case 'S': /* for compatibility with wmapm/apm only */ break; case 'h': default : return usage(p, opt == 'h' ? EXIT_SUCCESS:EXIT_FAILURE); } return force ? do_sleep() : net_sleep(port); } static int usage(char *name, int ret) { printf("usage: %s [args]\n\n" "\twhere [args] is:\n\n" "\t-f : force snooze to put the machine to sleep\n" "\t this is NOT recommended, as you will mis\n" "\t all the facilities pmud and pwrctl are\n" "\t able to provide\n" "\t-h : this text.\n" "\t-p : connect to pmud on for sleep request\n" "\t-v : print the version string of %s.\n\n" "\tfor the following flags, you can also use long-flags\n\n" "\t-f : --force\n" "\t-h : --help\n" "\t-p : --port \n" "\t-v : --version\n", name, name ); return ret; } static int do_sleep() { int fd = open(PMU_FILE, 0); if (fd < 0) fd = open(PMU_DEVFS_FILE, 0); if (fd < 0) { perror(PMU_FILE); return EXIT_FAILURE; } // direct call will not provide all facilities pmud -> pwrctl does printf("be warned, calling snooze with force is not advised\n"); sync(); if (ioctl(fd, PMU_IOC_SLEEP, 0) == -1) { perror("PMU_IOC_SLEEP"); return EXIT_FAILURE; } return EXIT_SUCCESS; } static int net_sleep(int port) { char buf[35]; int fd = tcp_open("localhost", PMUD_SERVICE, port); if (fd < 0) { perror("connect"); return EXIT_FAILURE; } tcp_printf(fd, "sleep\n"); // read some bytes, in order to prevent pmud complaining about // dropped connections, before ever handling the 'sleep' command tcp_printf(fd, "\n"); alarm(6); tcp_read(fd, buf, sizeof(buf)); tcp_close(fd); return EXIT_SUCCESS; } pmud-0.10.orig/tcp.c0100664000076400007640000001421707404124244014235 0ustar schmitzschmitz/* * --------------------------------------------------------------------------- * $Id: tcp.c,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $ * --------------------------------------------------------------------------- * $Log: tcp.c,v $ * Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.3 1999/01/12 08:29:17 stephan * in tcp_open, close the socket if the connection fails. * * Revision 1.2 1998/09/15 07:13:31 stephan * win32 modifications by Job de Haas (job@dsl.nl) * * Revision 1.1 1998/04/02 12:54:49 stephan * Initial revision * * --------------------------------------------------------------------------- */ static char rcs[]="@(#)$Id: tcp.c,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $"; #include #ifndef WIN32 #include #endif #include #include #include #ifdef WIN32 #include #include #define open _open #define close _close #else #include #include #include #include #include #endif #if defined( __STDC__ ) || defined( WIN32 ) #include #else #include #endif #define FATAL(error) { errno = error; return (-1); } /* * --------------------------------------------------------------------------- * public interface * --------------------------------------------------------------------------- */ int tcp_open(char *, char *, unsigned short); int tcp_bind(unsigned short); void tcp_listen(int); int tcp_read(int, const char *, size_t); int tcp_write(int, const char *, size_t); #ifdef __STDC__ int tcp_printf(int, char *, ...); #else int tcp_printf(); #endif #ifdef SOCKS #define connect Rconnect #define getsockname Rgetsockname #define bind Rbind #define accept Raccept #define listen Rlisten #define select Rselect #endif #ifdef WIN32 int first = 1; #endif int tcp_open(char *host, char *service, unsigned short port) { struct sockaddr_in server; struct hostent *hostinfo; struct servent *servinfo; #ifdef WIN32 SOCKET sock_fd; int iResult; if(first) { /* Start the WSA */ WSADATA wsadata; iResult= WSAStartup( MAKEWORD( 1, 1 ), &wsadata ); if( iResult != 0 ) FATAL( iResult ); first = 0; } #else int sock_fd; #endif /* use localhost if none specified */ if(! host || ! *host) host = "localhost"; /* check arguments */ if( (!service || !*service ) && port <= 0) #ifdef WIN32 FATAL(WSAEDESTADDRREQ) #else FATAL(EDESTADDRREQ) #endif /* initialise the server information */ memset((char *) &server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(port); /* try to get the server specification, if fail then use port */ if( service && *service ) { servinfo = getservbyname(service, "tcp"); if(servinfo) server.sin_port = servinfo->s_port; } /* try to get the address of the host */ server.sin_addr.s_addr = inet_addr(host); if( server.sin_addr.s_addr == INADDR_NONE ) { hostinfo = gethostbyname(host); if(!hostinfo) #ifdef WIN32 FATAL(WSAEADDRNOTAVAIL) #else FATAL(EADDRNOTAVAIL) #endif memcpy( (char *) &server.sin_addr, hostinfo->h_addr, hostinfo->h_length ); } /* create socket */ sock_fd = socket(AF_INET, SOCK_STREAM, 0); if( sock_fd < 0 ) FATAL(errno) /* connect to the server */ if(connect(sock_fd, (struct sockaddr *) &server, sizeof(server)) < 0) { close(sock_fd); FATAL(errno) } return(sock_fd); } int tcp_bind(unsigned short port) { int fd; struct sockaddr_in server; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(fd < 0) return fd; memset((char*)&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_addr.s_addr = htonl(INADDR_ANY); server.sin_port = htons(port); if(bind(fd, (struct sockaddr*) &server, sizeof(server)) < 0) { close(fd); return -1; } return fd; } void tcp_listen(int fd) { if(fd>=0) listen(fd, 5); } int tcp_accept(int fd) { return accept(fd, (struct sockaddr*)0, (int*)0); } int tcp_close(int fd) { #ifdef WIN32 if (!first) { int iResult = WSACleanup(); if(iResult != 0) FATAL(iResult) } #endif return close(fd); } char *tcp_identify(int fd) { struct sockaddr_in client; int len = sizeof(client); char *inetaddr; struct hostent *remote; struct in_addr *remaddr; register int i; int match; if(getpeername(fd, (struct sockaddr*) &client, &len)) return (char*)0; if(client.sin_family != AF_INET) return 0; inetaddr = inet_ntoa(client.sin_addr); if(inetaddr <= (char*)0) return (char*)0; remote=gethostbyaddr((char *)&client.sin_addr, sizeof(client.sin_addr), (int)client.sin_family); if(!remote) return (char*)0; for(match=i=0; remote->h_addr_list[i]; i++) { remaddr = (struct in_addr*) remote->h_addr_list[i]; if(remaddr->s_addr == client.sin_addr.s_addr) match++; } return match ? remote->h_name : (char*)0; } int tcp_write(int fildes, const char *buffer, size_t nbytes) { register char *data; register size_t right; register size_t left; for(data=(char *)buffer, left=nbytes;;) if((right=send(fildes, data, left, 0)) < 0) { return right; } else { left -= right; data += right; /* if right == 0 then EOF, return #bytes written */ if(right == 0 || left == 0) return nbytes - left; } /*NOTREACHED*/ } int tcp_read(int fildes, const char *buffer, size_t nbytes) { register char *data; register size_t right; register size_t left; for(data=(char *)buffer, left=nbytes;;) if((right=recv(fildes, data, left, 0)) < 0) { return right; } else { left -= right; data += right; /* if right == 0 then EOF, return #bytes already read */ if(right == 0 || left == 0) return nbytes - left; } /*NOTREACHED*/ } /*VARARGS*/ int #if defined( __STDC__ ) || defined( WIN32 ) tcp_printf(int sock, char *fmt, ...) #else tcp_printf(sock, fmt, va_alist) int sock; char *fmt; va_dcl #endif { va_list ap; static char buf[2*BUFSIZ]; #if defined( __STDC__ ) || defined( WIN32 ) va_start(ap, fmt); #else va_start(ap); #endif vsprintf(buf, fmt, ap); va_end(ap); return tcp_write(sock, buf, strlen(buf)); } pmud-0.10.orig/tcp.h0100664000076400007640000000212107404124244014231 0ustar schmitzschmitz/* * --------------------------------------------------------------------------- * $Id: tcp.h,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $ * --------------------------------------------------------------------------- * $Log: tcp.h,v $ * Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.1 2000/02/09 20:44:20 stephan * Initial revision * * --------------------------------------------------------------------------- */ #ifndef HDR_MYTCP_H #define HDR_MYTCP_H /* * --------------------------------------------------------------------------- * public interface * --------------------------------------------------------------------------- */ int tcp_open(char *, char *, unsigned short); int tcp_bind(unsigned short); void tcp_listen(int); int tcp_read(int, const char *, size_t); int tcp_write(int, const char *, size_t); #ifdef __STDC__ int tcp_printf(int, char *, ...); #else int tcp_printf(); #endif int tcp_close(int); #endif /* HDR_MYTCP_H */ pmud-0.10.orig/wakebay.c0100664000076400007640000000207707404124246015075 0ustar schmitzschmitz/* * wakebay.c - wakes a powerbook mediabay so the system doesnt crash on accessing * a disk mounted before sleeping. great for CD drives. * * Joseph Palani Garcia * * fairly simple. IOCTL the mediabay to tell it the media changed. (it only forgot * it in sleep. we remind it.) * * 3 cases: * nothing in drive : does nothing, exits normally * in drive, not mounted : acts, no effect (?) * in drive, is mounted : drive regains status, door locked, etc. * * this is useful for PMUD. add it to the wakeup script to prevent crashes. * */ #include #include #include #include #include int main(int argc, char **argv) { int fd, arg=0; if(argc<2){ fprintf(stderr,"Usage:\n\t%s \n",argv[0]); return 1; } fd = open(argv[1], O_RDONLY); if (fd < 0) { fprintf(stderr,"%s cannot be opened. exiting.\n",argv[1]); return 0; } if (ioctl(fd, CDROM_MEDIA_CHANGED, &arg) < 0) perror("CDROM_MEDIA_CHANGED ioctl"); close(fd); return 0; } pmud-0.10.orig/xmouse.80100664000076400007640000000231207404124246014707 0ustar schmitzschmitz.\" Copyright (c) 2000 Chad Miller .\" .\" This program is free software; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License .\" as published by the Free Software Foundation; either version .\" 2 of the License, or (at your option) any later version. .\" .\" $Log: xmouse.8,v $ .\" Revision 1.1.1.1 2001/12/07 11:31:50 sleemburg .\" Initial CVS import of the unreleased pmud-0.8 to apmud (new project name .\" because of a name clash at sourceforge.net). .\" .\" Revision 1.1 2000/10/09 14:34:09 stephan .\" Initial revision .\" .\" .\" .Dd May 30, 2000 .Dt XMOUSE 8 .Os "pmud" .Sh NAME .Nm xmouse .Nd sets and restores X mouse settings .Sh SYNOPSIS .Nm xmouse .Op Fl d Ar display .Op Fl a Ar acceleration .Op Fl t Ar threshhold .Sh DESCRIPTION .Nm xmouse displays the current settings, with no .Ar a or .Ar t parameters, but sets the values otherwise. It is primarily used by the .Nm pmud package to manage settings during power management. .Sh BUGS AND CHANGE REQUESTS Please email your bug reports or change requests to \fB\fP. .Sh AUTHOR Stephan Leemburg . man page by Chad Miller . .Sh SEE ALSO .Xr pmud(8) pmud-0.10.orig/xmouse.c0100775000076400007640000000534707404124244014776 0ustar schmitzschmitz/* * ---------------------------------------------------------------------------- * xmouse - retrieves and sets X window mouse speeds * * Copyright 2000 Stephan Leemburg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ---------------------------------------------------------------------------- * $Log: xmouse.c,v $ * Revision 1.1.1.1 2001/12/07 11:31:48 sleemburg * Initial CVS import of the unreleased pmud-0.8 to apmud (new project name * because of a name clash at sourceforge.net). * * Revision 1.1 2000/05/11 14:55:48 stephan * Initial revision * * ---------------------------------------------------------------------------- */ static char *rcsid = "@(#)$Id: xmouse.c,v 1.1.1.1 2001/12/07 11:31:48 sleemburg Exp $"; #include #include #include #include #define FLG_SET (1<<0) static void get_acceleration(char *arg, int *acceleration, int *denomination); static int myxerror(Display *dp, XErrorEvent *e); int main(int argc, char **argv) { Display *dp; char *myname = strrchr(*argv, '/'); char *display = 0; int acceleration = 0; int denomination = 0; int threshold = 0; int flags = 0; int op; extern char *optarg; extern int optind; extern int opterr; extern int optopt; myname = myname ? myname + 1 : *argv; while( (op=getopt(argc, argv, "d:a:t:")) != EOF ) if(op == 'd') { display = optarg; break; } dp = XOpenDisplay(display); if(!dp) return 1; XSetErrorHandler(myxerror); XGetPointerControl(dp, &acceleration, &denomination, &threshold); for(optind = 0; (op=getopt(argc, argv, "d:a:t:")) != EOF; ) switch(op) { case 'a': flags |= FLG_SET; get_acceleration(optarg, &acceleration, &denomination); break; case 't': flags |= FLG_SET; threshold = atoi(optarg); break; } if(flags&FLG_SET) { if(denomination <= 0) denomination = -1; XChangePointerControl(dp, True, True, acceleration, denomination, threshold ); XGetPointerControl(dp, &acceleration, &denomination, &threshold ); } XCloseDisplay(dp); printf("%s -a %d/%d -t %d\n", myname, acceleration, denomination, threshold ); return 0; } static void get_acceleration(char *arg, int *acceleration, int *denomination) { register char *p; for(p = arg; *p; p++) if(*p == '/') { *p++ = 0; break; } *acceleration = atoi(arg); if(*p) *denomination = atoi(p); } static int myxerror(Display *dp, XErrorEvent *e) { printf("error: %d\n", e->error_code); return 0; }