i386 removal, part 1/x: Remove 'real' APM and associated stuff.
authorSascha Wildner <saw@online.de>
Sat, 20 Jun 2015 03:40:29 +0000 (05:40 +0200)
committerSascha Wildner <saw@online.de>
Sat, 20 Jun 2015 03:40:29 +0000 (05:40 +0200)
Notes:

* 'apm' is now an alias for 'acpiconf -i 0', because some people got used
  to checking their battery status typing 'apm'.

* powerd(8) recently gained the ability to shut down on low battery. Any
  remaining functionality from the former battd(8) could be added to it.

43 files changed:
Makefile_upgrade.inc
etc/Makefile
etc/apmd.conf [deleted file]
etc/defaults/rc.conf
etc/rc.d/Makefile
etc/rc.d/apm [deleted file]
etc/rc.d/apmd [deleted file]
etc/rc.d/battd [deleted file]
etc/rc.resume
etc/rc.suspend
share/examples/etc/README.examples
share/man/man4/Makefile
share/man/man4/apm.4 [deleted file]
share/man/man5/rc.conf.5
share/man/man8/rc.8
share/man/man9/ioctl.9
sys/dev/misc/syscons/Makefile
sys/dev/misc/syscons/apm/Makefile [deleted file]
sys/dev/misc/syscons/apm/apm_saver.c [deleted file]
sys/dev/misc/syscons/syscons.c
sys/platform/pc32/Makefile.inc
sys/platform/pc32/apm/apm.c [deleted file]
sys/platform/pc32/apm/apm.h [deleted file]
sys/platform/pc32/conf/files
sys/platform/pc32/i386/userconfig.c
usr.sbin/Makefile
usr.sbin/acpi/acpiconf/Makefile
usr.sbin/acpi/acpiconf/acpiconf.8
usr.sbin/acpi/acpiconf/acpiconf.c
usr.sbin/apm/Makefile [deleted file]
usr.sbin/apm/apm.8 [deleted file]
usr.sbin/apm/apm.c [deleted file]
usr.sbin/apmd/Makefile [deleted file]
usr.sbin/apmd/README [deleted file]
usr.sbin/apmd/apmd.8 [deleted file]
usr.sbin/apmd/apmd.c [deleted file]
usr.sbin/apmd/apmd.h [deleted file]
usr.sbin/apmd/apmdlex.l [deleted file]
usr.sbin/apmd/apmdparse.y [deleted file]
usr.sbin/apmd/contrib/pccardq.c [deleted file]
usr.sbin/battd/Makefile [deleted file]
usr.sbin/battd/battd.8 [deleted file]
usr.sbin/battd/battd.c [deleted file]

index 27b1236..c6031b4 100644 (file)
@@ -2112,6 +2112,14 @@ TO_REMOVE+=/usr/share/man/en.ISO8859-15
 TO_REMOVE+=/usr/share/zoneinfo/America/Montreal
 TO_REMOVE+=/usr/include/gnu/vfs/ext2fs/ext2mount.h
 TO_REMOVE+=/usr/include/bus/u4b/usb_freebsd.h
+TO_REMOVE+=/etc/apmd.conf
+TO_REMOVE+=/etc/rc.d/apm
+TO_REMOVE+=/etc/rc.d/apmd
+TO_REMOVE+=/etc/rc.d/battd
+TO_REMOVE+=/usr/sbin/apmd
+TO_REMOVE+=/usr/share/man/man4/apm.4.gz
+TO_REMOVE+=/usr/share/man/man8/apmd.8.gz
+TO_REMOVE+=/usr/share/man/man8/battd.8.gz
 
 .if ${MACHINE_ARCH} == "x86_64"
 TO_REMOVE+=/usr/sbin/stlstats
index 2295973..ec96dd1 100644 (file)
@@ -5,7 +5,7 @@ SUBDIR= sendmail
 
 # Files that should be installed read-only (444)
 #
-BINUPDATE= apmd.conf devd.conf fbtab gettytab network.subr \
+BINUPDATE= devd.conf fbtab gettytab network.subr \
        pf.os \
        protocols \
        rc rc.firewall6 \
diff --git a/etc/apmd.conf b/etc/apmd.conf
deleted file mode 100644 (file)
index b946962..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-# apmd Configuration File
-#
-# $FreeBSD: src/etc/apmd.conf,v 1.2.2.2 2001/08/13 17:30:29 nsayer Exp $
-#
-
-apm_event SUSPENDREQ {
-       exec "/etc/rc.suspend";
-}
-
-apm_event USERSUSPENDREQ {
-       exec "sync && sync && sync";
-       exec "sleep 1";
-       exec "apm -z";
-}
-
-apm_event NORMRESUME, STANDBYRESUME {
-       exec "/etc/rc.resume";
-}
-
-# resume event configuration for serial mouse users by
-# reinitializing a moused(8) connected to a serial port.
-#
-#apm_event NORMRESUME {
-#      exec "kill -HUP `cat /var/run/moused.pid`";
-#}
-
-# suspend request event configuration for ATA HDD users:
-# execute standby instead of suspend.
-#
-#apm_event SUSPENDREQ {
-#      reject;
-#      exec "sync && sync && sync";
-#      exec "sleep 1";
-#      exec "apm -Z";
-#}
-
-# Sample entries for battery state monitoring
-#apm_battery 5% discharging {
-#      exec "logger -p user.emerg battery status critical!";
-#}
-#apm_battery 1% discharging {
-#      exec "logger -p user.emerg battery low - emergency suspend";
-#      exec "apm -z";
-#}
-#apm_battery 99% charging {
-#      exec "logger -p user.notice battery fully charged";
-#}
-
-# apmd Configuration ends here
index fefeaba..2bc3ab3 100644 (file)
@@ -24,11 +24,6 @@ rc_info="YES"                # Enables display of informational messages at boot.
 rc_startmsgs="YES"     # Show "Starting foo:" messages at boot
 rcshutdown_timeout="30" # Seconds to wait before terminating rc.shutdown
 swapfile="NO"          # Set to name of swapfile if aux swapfile desired.
-apm_enable="NO"                # Set to YES to enable APM BIOS functions (or NO).
-apmd_enable="NO"       # Run apmd to handle APM event from userland.
-apmd_flags=""          # Flags to apmd (if enabled).
-battd_enable="NO"      # Set to YES to have battd alert on 10% battery power remaining.
-battd_flags=""         # Flags to battd (if enabled).
 powerd_enable="NO"     # Run powerd to adjust CPU speed.
 sensorsd_enable="NO"   # Run sensorsd to monitor and log sensor state changes.
 sensorsd_flags=""      # additional flags for sensorsd(8).
index 8d4d6e1..1a5e3cf 100644 (file)
@@ -5,9 +5,8 @@
 
 # note: bgfsk and lomac left out (from 5.0)
 #
-FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz \
-       amd apm apmd \
-       battd bootconf bootparams btconfig bthcid ccd cleanvar cryptdisks \
+FILES= DAEMON LOGIN NETWORKING SERVERS abi accounting addswap adjkerntz amd \
+       bootconf bootparams btconfig bthcid ccd cleanvar cryptdisks \
        cleartmp cron cryptdisks devd devfs dhclient diskless dmesg dumpon \
        fixbootfile fsck ftpd hostapd hostname hotplugd \
        inetd initdiskless initrandom ip6fw ipfw ipsec \
diff --git a/etc/rc.d/apm b/etc/rc.d/apm
deleted file mode 100644 (file)
index 657cf90..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-#
-# $FreeBSD: src/etc/rc.d/apm,v 1.4 2003/06/09 17:44:30 mtm Exp $
-# $DragonFly: src/etc/rc.d/apm,v 1.3 2005/11/19 21:47:32 swildner Exp $
-#
-
-# PROVIDE: apm
-# REQUIRE: DAEMON
-# BEFORE:  LOGIN
-
-. /etc/rc.subr
-
-name="apm"
-rcvar=`set_rcvar`
-start_precmd="apm_precmd"
-command="/usr/sbin/${name}"
-start_cmd="${command} -e enable"
-stop_cmd="${command} -e disable"
-status_cmd="apm_status"
-
-apm_precmd()
-{
-       case `${SYSCTL_N} hw.machine_arch` in
-       i386)
-               return 0
-               ;;
-       esac
-       return 1
-}
-
-apm_status()
-{
-       case `${command} -s` in
-       1)
-               echo "APM is enabled."
-               return 0
-               ;;
-       0)
-               echo "APM is disabled"
-               ;;
-       esac
-       return 1
-}
-
-load_rc_config $name
-run_rc_command "$1"
diff --git a/etc/rc.d/apmd b/etc/rc.d/apmd
deleted file mode 100644 (file)
index 0d34587..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-#
-# $NetBSD: apmd,v 1.5 2002/03/22 04:33:58 thorpej Exp $
-# $FreeBSD: src/etc/rc.d/apmd,v 1.8 2003/06/09 17:44:30 mtm Exp $
-# $DragonFly: src/etc/rc.d/apmd,v 1.3 2005/11/19 21:47:32 swildner Exp $
-#
-
-# PROVIDE: apmd
-# REQUIRE: DAEMON apm
-# BEFORE:  LOGIN
-
-. /etc/rc.subr
-
-name="apmd"
-rcvar=`set_rcvar`
-command="/usr/sbin/${name}"
-start_precmd="apmd_prestart"
-apmd_prestart()
-{
-       case `${SYSCTL_N} hw.machine_arch` in
-       i386)
-               # Enable apm if it is not already enabled
-               if ! checkyesno apm_enable  && \
-                   ! /etc/rc.d/apm forcestatus 1>/dev/null 2>&1
-               then
-                       force_depend apm || return 1
-               fi
-
-               # Warn user about acpi apm compatibility support which
-               # does not work with apmd.
-               if [ ! -e /dev/apmctl ]; then
-                   warn "/dev/apmctl not found; kernel is missing apm(4)"
-               fi
-               ;;
-       *)
-               return 1
-               ;;
-       esac
-       return 0
-}
-
-load_rc_config $name
-run_rc_command "$1"
diff --git a/etc/rc.d/battd b/etc/rc.d/battd
deleted file mode 100644 (file)
index 2ded811..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-#
-# $DragonFly: src/etc/rc.d/battd,v 1.2 2005/11/19 21:47:32 swildner Exp $
-#
-
-# PROVIDE: battd
-# REQUIRE: DAEMON apm
-# BEFORE:  LOGIN
-
-. /etc/rc.subr
-
-name="battd"
-rcvar=`set_rcvar`
-start_precmd="battd_precmd"
-command="/usr/sbin/${name}"
-pidfile="/var/run/${name}.pid"
-
-battd_precmd()
-{
-       case `${SYSCTL_N} hw.machine_arch` in
-       i386)
-               # Enable apm if it is not already enabled
-               if ! checkyesno apm_enable  && \
-                   ! /etc/rc.d/apm forcestatus 1>/dev/null 2>&1
-               then
-                       force_depend apm || return 1
-               fi
-               ;;
-       *)
-               return 1
-               ;;
-       esac
-       return 0
-}
-
-load_rc_config $name
-run_rc_command "$1"
index 575aa10..6f0b211 100644 (file)
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.resume,v 1.9 2008/07/21 22:55:40 thompsa Exp $
-# $DragonFly: src/etc/rc.resume,v 1.4 2007/12/27 20:00:51 matthias Exp $
 #
 
 # sample run command file for APM Resume Event
 
 if [ $# -ne 2 ]; then
-       echo "Usage: $0 [apm|acpi] [standby,suspend|1-4]"
+       echo "Usage: $0 [acpi] [standby,suspend|1-4]"
        exit 1
 fi
 
index b45f34a..453afa8 100644 (file)
 # SUCH DAMAGE.
 #
 # $FreeBSD: src/etc/rc.suspend,v 1.6 2004/01/21 03:03:40 njl Exp $
-# $DragonFly: src/etc/rc.suspend,v 1.4 2007/12/27 20:00:51 matthias Exp $
 #
 
 # sample run command file for APM Suspend Event
 
 if [ $# -ne 2 ]; then
-       echo "Usage: $0 [apm|acpi] [standby,suspend|1-5]"
+       echo "Usage: $0 [acpi] [standby,suspend|1-5]"
        exit 1
 fi
 
@@ -55,9 +54,7 @@ echo $$ 2> /dev/null > /var/run/rc.suspend.pid
 
 logger -t $subsystem suspend at `date +'%Y%m%d %H:%M:%S'`
 sync && sync && sync
-[ $subsystem = "apm" ] && sleep 3
 
 rm -f /var/run/rc.suspend.pid
-[ $subsystem = "apm" ] && zzz
 
 exit 0
index 74a892e..d7d15eb 100644 (file)
@@ -12,7 +12,6 @@ which can be accessed by `man 5 crontab'.
 This directory contains the following files:
 
 amd.map                - configuration file for amd(8)
-apmd.conf      - configuration file for apmd(8)
 auth.conf      - authentication capability database
 crontab                - system scheduled command table
 csh.cshrc      - system-wide .cshrc for csh(1)
@@ -58,11 +57,11 @@ protocols   - protocol name database
 rc             - system startup script
 rc.firewall    - setup system for ipfw(8)
 rc.firewall6   - setup system for ip6fw(8)
-rc.resume      - run command for APM / ACPI resume event
+rc.resume      - run command for ACPI resume event
 rc.sendmail    - sendmail(8) rc script
 rc.shutdown    - system shutdown script
 rc.subr                - subroutines for rc(8) scripts
-rc.suspend     - run command for APM / ACPI suspend event
+rc.suspend     - run command for ACPI suspend event
 regdomain.xml  - 802.11 regulatory definitions used by ifconfig(8)
 remote         - configuration file for tip(1)
 rpc            - rpc program number database
index ffbce5a..537628e 100644 (file)
@@ -35,7 +35,6 @@ MAN=  aac.4 \
        amdsmb.4 \
        amr.4 \
        an.4 \
-       apm.4 \
        aps.4 \
        arcmsr.4 \
        arp.4 \
diff --git a/share/man/man4/apm.4 b/share/man/man4/apm.4
deleted file mode 100644 (file)
index 9525b0e..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-.\" LP (Laptop Package)
-.\"
-.\" Copyright (c) 1994 by HOSOKAWA, Tatsumi <hosokawa@mt.cs.keio.ac.jp>
-.\"
-.\" This software may be used, modified, copied, and distributed, in
-.\" both source and binary form provided that the above copyright and
-.\" these terms are retained. Under no circumstances is the author
-.\" responsible for the proper functioning of this software, nor does
-.\" the author assume any responsibility for damages incurred with its
-.\" use.
-.\"
-.\" $FreeBSD: src/share/man/man4/man4.i386/apm.4,v 1.13.2.5 2001/08/17 13:08:45 ru Exp $
-.\"
-.Dd September 9, 2012
-.Dt APM 4
-.Os
-.Sh NAME
-.Nm apm
-.Nd APM BIOS interface
-.Sh SYNOPSIS
-.Cd device apm0 at nexus?
-.Sh DESCRIPTION
-.Nm
-is an interface to the Intel / Microsoft APM (Advanced Power Management) BIOS
-on laptop PCs.
-It has been largely superseded by
-.Xr acpi 4 ,
-which emulates
-.Nm Ap s
-ioctls (see below) so userland can use them as a uniform interface
-(to get at the battery status, for example).
-.Pp
-Note that
-.Em real
-.Nm
-(in the absence of
-.Xr acpi 4 )
-is not available on the
-.Sy x86_64
-platform.
-.Pp
-.Nm
-provides the following power management functions.
-.Bl -enum -offset indent
-.It
-When the system wakes up from suspended mode,
-.Nm
-adjusts the system clock to RTC.
-.It
-When the system wakes up from suspended mode,
-.Nm
-passes a message to
-.Xr syslogd 8
-comprising of system wakeup time and elapsed time during suspended mode.
-.It
-.Nm
-slows CPU clock when there are no system activities (runnable processes,
-interrupts, etc.).
-This function is available only on systems whose APM supports CPU idling.
-.It
-.Nm
-exports an application interface as a character device.
-Applications can control APM, or retrieve APM status information via this
-interface.
-.Nm
-exports the following interfaces.
-These symbols are defined in
-.In machine/apm_bios.h .
-.Bl -tag -width 4n -offset indent
-.It Dv APMIO_SUSPEND
-Suspend system.
-.It Dv APMIO_GETINFO
-Get power management information.
-.It Dv APMIO_ENABLE
-.It Dv APMIO_DISABLE
-Enable / Disable power management.
-.It Dv APMIO_HALTCPU
-.It Dv APMIO_NOTHALTCPU
-Control execution of HLT in the kernel context switch routine.
-.It Dv APMIO_GETPWSTATUS
-Get per battery information.
-.Pp
-Some APM implementations execute the HLT
-(Halt CPU until an interrupt occurs)
-instruction in the
-.Dq Em Idle CPU
-call, while others do not.
-Thus enabling this may result in redundant HLT executions because
-.Dq Em Idle CPU
-is called from the kernel context switch routine that inherently executes
-HLT.
-This may reduce peak system performance.
-.Pp
-Also the system hangs up if HLT instruction is disabled in the kernel
-context switch routine, and if the APM implementation of the machine
-does not execute HLT in
-.Dq Em Idle CPU .
-On some implementations that do not support CPU clock slowdown, APM
-might not execute HLT.
-.Nm
-disables
-.Dv APMIO_NOTHALTCPU
-operation on such machines.
-.Pp
-The current version of
-.Nm
-does not call
-.Dq Em Idle CPU
-from the kernel context switch routine if clock slowdown is not supported,
-and it executes HLT instruction by default.
-Therefore, there is no need to use these two operations in most cases.
-.El
-.Pp
-These interfaces are used by
-.Xr apm 8 .
-.It
-.Nm
-polls APM events and handles the following events:
-.Bl -column PMEV_USERSUSPENDREQ "suspend system" "critical suspend request"
-.It Sy Name                Ta Sy Action        Ta Sy Description
-.It Dv PMEV_STANDBYREQ     Ta "suspend system" Ta "standby request"
-.It Dv PMEV_SUSPENDREQ     Ta "suspend system" Ta "suspend request"
-.It Dv PMEV_USERSUSPENDREQ Ta "suspend system" Ta "user suspend"
-.It ""                     Ta ""               Ta "request"
-.It Dv PMEV_CRITSUSPEND    Ta "suspend system" Ta "critical suspend"
-.It ""                     Ta ""               Ta "request"
-.It Dv PMEV_NORMRESUME     Ta "resume system"  Ta "normal resume"
-.It Dv PMEV_CRITRESUME     Ta "resume system"  Ta "critical resume"
-.It Dv PMEV_STANDBYRESUME  Ta "resume system"  Ta "standby resume"
-.It Dv PMEV_BATTERYLOW     Ta "notify message" Ta "battery low"
-.It Dv PMEV_UPDATETIME     Ta "adjust clock"   Ta "update time"
-.El
-.El
-.Sh SEE ALSO
-.Xr apm 8 ,
-.Xr zzz 8
-.Sh AUTHORS
-.An Tatsumi Hosokawa Aq Mt hosokawa@jp.FreeBSD.org
-.Sh BUGS
-WARNING!
-Many, if not most, of the implementations of APM-bios in laptops
-today are buggy.
-You may be putting your LCD-display and batteries at a risk by using this
-interface.
-(The reason this isn't a problem for MS-windows is that they use the
-real-mode interface.)
-If you see any weird behavior from your system with this code in use,
-unplug the power and batteries ASAP, if not immediately, and disable
-this code.
-.Pp
-We are very interested in getting this code working, so please send your
-observations of any anomalous behavior to us.
-.Pp
-When
-.Nm
-is active, calling the BIOS setup routine by using hot-keys,
-may cause serious trouble when resuming the system.
-BIOS setup programs should be called during bootstrap, or from DOS.
-.Pp
-Some APM implementations cannot handle events such as pushing the
-power button or closing the cover.
-On such implementations, the system
-.Ar must
-be suspended
-.Ar only
-by using
-.Xr apm 8
-or
-.Xr zzz 8 .
-.Pp
-Disk spin-down, LCD backlight control, and power on demand have not
-been supported on the current version.
index d404789..7bde5fb 100644 (file)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD: src/share/man/man5/rc.conf.5,v 1.197 2003/07/28 13:56:00 mbr Exp $
 .\"
-.Dd December 21, 2014
+.Dd June 20, 2015
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -137,42 +137,6 @@ The
 driver is needed for a swapfile and will be loaded if it is not
 already compiled into the kernel or loaded via
 .Xr loader.conf 5 .
-.It Va apm_enable
-.Pq Vt bool
-If set to
-.Dq Li YES ,
-enable support for Automatic Power Management with the
-.Xr apm 8
-command.
-.It Va apmd_enable
-.Pq Vt bool
-Run
-.Xr apmd 8
-to handle APM event from userland.
-This also enables support for APM.
-.It Va apmd_flags
-.Pq Vt str
-If
-.Va apmd_enable
-is set to
-.Dq Li YES ,
-these are the flags to pass to the
-.Xr apmd 8
-daemon.
-.It Va battd_enable
-Enable
-.Xr battd 8
-to monitor the status of batteries present in the system.
-This also enables support for APM.
-.It Va battd_flags
-.Pq Vt str
-If
-.Va battd_enable
-is set to
-.Dq Li YES ,
-these are the flags to pass to the
-.Xr battd 8
-daemon.
 .It Va devd_enable
 .Pq Vt bool
 Run
@@ -2660,7 +2624,6 @@ if it is not set.
 .Xr varsym.conf 5 ,
 .Xr accton 8 ,
 .Xr amd 8 ,
-.Xr apm 8 ,
 .Xr btconfig 8 ,
 .Xr bthcid 8 ,
 .Xr cron 8 ,
index 49a539f..11de52c 100644 (file)
@@ -31,7 +31,7 @@
 .\"     @(#)rc.8       8.2 (Berkeley) 12/11/93
 .\" $FreeBSD: src/share/man/man8/rc.8,v 1.22 2002/12/12 17:25:58 ru Exp $
 .\"
-.Dd October 29, 2014
+.Dd June 20, 2015
 .Dt RC 8
 .Os
 .Sh NAME
@@ -462,8 +462,7 @@ Most daemons, including network related daemons, have their own script in
 which can be used to start, stop, and check the status of the service.
 .Pp
 Any architecture specific scripts, such as
-.Pa /etc/rc.d/apm
-for example, specifically check that they are on that architecture
+specifically check that they are on that architecture
 before starting the daemon.
 .Pp
 Following tradition, all startup files reside in
index 9e574e4..eb9c5ab 100644 (file)
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 27, 2009
+.Dd June 20, 2015
 .Dt IOCTL 9
 .Os
 .Sh NAME
@@ -137,7 +137,7 @@ and
 .It 'p'
 .Xr ppbus 4
 .It 'P'
-.Xr apm 4
+.Nm apm (deprecated)
 .It 'q'
 .Pa /dev/sequencer
 .It 'r'
index c8d785a..9219921 100644 (file)
@@ -16,8 +16,4 @@ SUBDIR += snake
 SUBDIR += star
 SUBDIR += warp
 
-.ifdef SYSCONS_APM_SUPPORT
-SUBDIR += apm
-.endif
-
 .include <bsd.subdir.mk>
diff --git a/sys/dev/misc/syscons/apm/Makefile b/sys/dev/misc/syscons/apm/Makefile
deleted file mode 100644 (file)
index a75699b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# $FreeBSD: src/sys/modules/syscons/apm/Makefile,v 1.1.4.2 2002/12/01 09:01:09 nyan Exp $
-# $DragonFly: src/sys/dev/misc/syscons/apm/Makefile,v 1.2 2003/06/17 04:28:47 dillon Exp $
-
-KMOD=  apm_saver
-SRCS=  apm_saver.c
-
-CFLAGS+= -I${.CURDIR}/..
-
-.include <bsd.kmod.mk>
diff --git a/sys/dev/misc/syscons/apm/apm_saver.c b/sys/dev/misc/syscons/apm/apm_saver.c
deleted file mode 100644 (file)
index 1c5c955..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * Copyright (c) 1999 Nick Sayer (who stole shamelessly from blank_saver)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer,
- *    without modification, immediately at the beginning of the file.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/sys/modules/syscons/apm/apm_saver.c,v 1.1.4.2 2001/03/07 21:47:24 nsayer Exp $
- * $DragonFly: src/sys/dev/misc/syscons/apm/apm_saver.c,v 1.9 2006/12/22 23:26:18 swildner Exp $
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/consio.h>
-#include <sys/fbio.h>
-#include <sys/event.h>
-
-#include <dev/video/fb/fbreg.h>
-#include <dev/video/fb/splashreg.h>
-#include "../syscons.h"
-
-#include <machine/apm_bios.h>
-#include <machine/pc/bios.h>
-#include <machine_base/apm/apm.h>
-
-extern int apm_display (int newstate);                                     
-
-extern struct apm_softc apm_softc;
-
-static int blanked=0;
-
-static int
-apm_saver(video_adapter_t *adp, int blank)
-{
-       if (!apm_softc.initialized || !apm_softc.active)
-               return 0;
-
-       if (blank==blanked)
-               return 0;
-
-       blanked=blank;
-
-       apm_display(!blanked);
-
-       return 0;
-}
-
-static int
-apm_init(video_adapter_t *adp)
-{
-       if (!apm_softc.initialized || !apm_softc.active)
-               kprintf("WARNING: apm_saver module requires apm enabled\n");
-       return 0;
-}
-
-static int
-apm_term(video_adapter_t *adp)
-{
-       return 0;
-}
-
-static scrn_saver_t apm_module = {
-       "apm_saver", apm_init, apm_term, apm_saver, NULL,
-};
-
-SAVER_MODULE(apm_saver, apm_module);
index 5ab1a12..256c183 100644 (file)
@@ -36,9 +36,6 @@
 #include "use_splash.h"
 #include "opt_syscons.h"
 #include "opt_ddb.h"
-#ifdef __i386__
-#include "use_apm.h"
-#endif
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -61,9 +58,6 @@
 #include <machine/console.h>
 #include <machine/psl.h>
 #include <machine/pc/display.h>
-#ifdef __i386__
-#include <machine/apm_bios.h>
-#endif
 #include <machine/frame.h>
 
 #include <dev/drm/include/linux/fb.h>
@@ -3581,18 +3575,9 @@ next_code:
 #endif
                break;
 
-#if __i386__ && NAPM > 0
-           case SUSP:
-               apm_suspend(PMST_SUSPEND);
-               break;
-           case STBY:
-               apm_suspend(PMST_STANDBY);
-               break;
-#else
            case SUSP:
            case STBY:
                break;
-#endif
 
            case DBG:
 #ifndef SC_DISABLE_DDBKEY
index f23027a..d4c5779 100644 (file)
@@ -5,6 +5,5 @@ DEV_SUPPORT=    acpica agp bridge crypto disk drm misc netif \
                pccard powermng raid serial sound smbus video \
                virtual/virtio
 
-SYSCONS_APM_SUPPORT=1
 BOOT0CFG_SUPPORT=1
 
diff --git a/sys/platform/pc32/apm/apm.c b/sys/platform/pc32/apm/apm.c
deleted file mode 100644 (file)
index 4fc318e..0000000
+++ /dev/null
@@ -1,1427 +0,0 @@
-/*
- * APM (Advanced Power Management) BIOS Device Driver
- *
- * Copyright (c) 1994 UKAI, Fumitoshi.
- * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
- * Copyright (c) 1996 Nate Williams <nate@FreeBSD.org>
- * Copyright (c) 1997 Poul-Henning Kamp <phk@FreeBSD.org>
- *
- * This software may be used, modified, copied, and distributed, in
- * both source and binary form provided that the above copyright and
- * these terms are retained. Under no circumstances is the author
- * responsible for the proper functioning of this software, nor does
- * the author assume any responsibility for damages incurred with its
- * use.
- *
- * Sep, 1994   Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
- *
- * $FreeBSD: src/sys/i386/apm/apm.c,v 1.114.2.5 2002/11/02 04:41:50 iwasaki Exp $
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/eventhandler.h>
-#include <sys/conf.h>
-#include <sys/device.h>
-#include <sys/kernel.h>
-#include <sys/time.h>
-#include <sys/reboot.h>
-#include <sys/bus.h>
-#include <sys/event.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
-#include <sys/signalvar.h>
-#include <sys/sysctl.h>
-#include <machine/apm_bios.h>
-#include <machine/segments.h>
-#include <machine/clock.h>
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <sys/syslog.h>
-#include <sys/thread2.h>
-
-#include <machine/pc/bios.h>
-#include <machine/vm86.h>
-
-#include <machine_base/apm/apm.h>
-
-/* Used by the apm_saver screen saver module */
-int apm_display (int newstate);
-struct apm_softc apm_softc;
-
-static void apm_resume (void);
-static int apm_bioscall(void);
-static int apm_check_function_supported (u_int version, u_int func);
-
-static u_long  apm_version;
-
-int    apm_evindex;
-
-#define        SCFLAG_ONORMAL  0x0000001
-#define        SCFLAG_OCTL     0x0000002
-#define        SCFLAG_OPEN     (SCFLAG_ONORMAL|SCFLAG_OCTL)
-
-#define APMDEV(dev)    (minor(dev)&0x0f)
-#define APMDEV_NORMAL  0
-#define APMDEV_CTL     8
-
-static struct apmhook  *hook[NAPM_HOOK];               /* XXX */
-
-#define is_enabled(foo) ((foo) ? "enabled" : "disabled")
-
-/* Map version number to integer (keeps ordering of version numbers) */
-#define INTVERSION(major, minor)       ((major)*100 + (minor))
-
-static struct callout apm_timeout_ch;
-
-static timeout_t apm_timeout;
-static d_open_t apmopen;
-static d_close_t apmclose;
-static d_write_t apmwrite;
-static d_ioctl_t apmioctl;
-static d_kqfilter_t apmkqfilter;
-
-static void apmfilter_detach(struct knote *);
-static int apmfilter_read(struct knote *, long);
-static int apmfilter_write(struct knote *, long);
-
-static struct dev_ops apm_ops = {
-       { "apm", 0, 0 },
-       .d_open =       apmopen,
-       .d_close =      apmclose,
-       .d_write =      apmwrite,
-       .d_ioctl =      apmioctl,
-       .d_kqfilter =   apmkqfilter
-};
-
-static int apm_suspend_delay = 1;
-static int apm_standby_delay = 1;
-static int apm_debug = 0;
-
-#define APM_DPRINT(args...) do {                                       \
-       if (apm_debug) {                                                \
-               kprintf(args);                                          \
-       }                                                               \
-} while (0)
-
-SYSCTL_INT(_machdep, OID_AUTO, apm_suspend_delay, CTLFLAG_RW, &apm_suspend_delay, 1, "");
-SYSCTL_INT(_machdep, OID_AUTO, apm_standby_delay, CTLFLAG_RW, &apm_standby_delay, 1, "");
-SYSCTL_INT(_debug, OID_AUTO, apm_debug, CTLFLAG_RW, &apm_debug, 0,
-    "Enable debug output");
-
-/*
- * return  0 if the function successfull,
- * return  1 if the function unsuccessfull,
- * return -1 if the function unsupported.
- */
-static int
-apm_bioscall(void)
-{
-       struct apm_softc *sc = &apm_softc;
-       int error = 0;
-       u_int apm_func = sc->bios.r.eax & 0xff;
-
-       if (!apm_check_function_supported(sc->intversion, apm_func)) {
-               APM_DPRINT("apm_bioscall: function 0x%x is not supported in v%d.%d\n",
-                   apm_func, sc->majorversion, sc->minorversion);
-               return (-1);
-       }
-
-       sc->bios_busy = 1;
-       if (sc->connectmode == APM_PROT32CONNECT) {
-               set_bios_selectors(&sc->bios.seg,
-                                  BIOSCODE_FLAG | BIOSDATA_FLAG);
-               error = bios32(&sc->bios.r,
-                              sc->bios.entry, GSEL(GBIOSCODE32_SEL, SEL_KPL));
-       } else {
-               error = bios16(&sc->bios, NULL);
-       }
-       sc->bios_busy = 0;
-       return (error);
-}
-
-/* check whether APM function is supported (1)  or not (0). */
-static int
-apm_check_function_supported(u_int version, u_int func)
-{
-       /* except driver version */
-       if (func == APM_DRVVERSION) {
-               return (1);
-       }
-
-       switch (version) {
-       case INTVERSION(1, 0):
-               if (func > APM_GETPMEVENT) {
-                       return (0); /* not supported */
-               }
-               break;
-       case INTVERSION(1, 1):
-               if (func > APM_ENGAGEDISENGAGEPM &&
-                   func < APM_OEMFUNC) {
-                       return (0); /* not supported */
-               }
-               break;
-       case INTVERSION(1, 2):
-               break;
-       }
-
-       return (1); /* supported */
-}
-
-/* enable/disable power management */
-static int
-apm_enable_disable_pm(int enable)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_ENABLEDISABLEPM;
-
-       if (sc->intversion >= INTVERSION(1, 1))
-               sc->bios.r.ebx  = PMDV_ALLDEV;
-       else
-               sc->bios.r.ebx  = 0xffff;       /* APM version 1.0 only */
-       sc->bios.r.ecx  = enable;
-       sc->bios.r.edx = 0;
-       return (apm_bioscall());
-}
-
-/* register driver version (APM 1.1 or later) */
-static int
-apm_driver_version(int version)
-{
-       struct apm_softc *sc = &apm_softc;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_DRVVERSION;
-       sc->bios.r.ebx  = 0x0;
-       sc->bios.r.ecx  = version;
-       sc->bios.r.edx = 0;
-
-       if (apm_bioscall() == 0 && sc->bios.r.eax == version)
-               return (0);
-
-       /* Some old BIOSes don't return the connection version in %ax. */
-       if (sc->bios.r.eax == ((APM_BIOS << 8) | APM_DRVVERSION))
-               return (0);
-
-       return (1);
-}
-/* engage/disengage power management (APM 1.1 or later) */
-static int
-apm_engage_disengage_pm(int engage)
-{
-       struct apm_softc *sc = &apm_softc;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_ENGAGEDISENGAGEPM;
-       sc->bios.r.ebx = PMDV_ALLDEV;
-       sc->bios.r.ecx = engage;
-       sc->bios.r.edx = 0;
-       return (apm_bioscall());
-}
-/* get PM event */
-static u_int
-apm_getevent(void)
-{
-       struct apm_softc *sc = &apm_softc;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_GETPMEVENT;
-       sc->bios.r.ebx = 0;
-       sc->bios.r.ecx = 0;
-       sc->bios.r.edx = 0;
-       if (apm_bioscall())
-               return (PMEV_NOEVENT);
-       return (sc->bios.r.ebx & 0xffff);
-}
-/* suspend entire system */
-static int
-apm_suspend_system(int state)
-{
-       struct apm_softc *sc = &apm_softc;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_ALLDEV;
-       sc->bios.r.ecx = state;
-       sc->bios.r.edx = 0;
-       if (apm_bioscall()) {
-               kprintf("Entire system suspend failure: errcode = %d\n",
-                      0xff & (sc->bios.r.eax >> 8));
-               return 1;
-       }
-       return 0;
-}
-
-/* Display control */
-/*
- * Experimental implementation: My laptop machine can't handle this function
- * If your laptop can control the display via APM, please inform me.
- *                            HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
- */
-int
-apm_display(int newstate)
-{
-       struct apm_softc *sc = &apm_softc;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_DISP0;
-       sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND;
-       sc->bios.r.edx = 0;
-       if (apm_bioscall() == 0) {
-               return 0;
-       }
-
-       /* If failed, then try to blank all display devices instead. */
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_DISPALL;  /* all display devices */
-       sc->bios.r.ecx = newstate ? PMST_APMENABLED:PMST_SUSPEND;
-       sc->bios.r.edx = 0;
-       if (apm_bioscall() == 0) {
-               return 0;
-       }
-       kprintf("Display off failure: errcode = %d\n",
-              0xff & (sc->bios.r.eax >> 8));
-       return 1;
-}
-
-/*
- * Turn off the entire system.
- */
-static void
-apm_power_off(void *junk, int howto)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       /* Not halting powering off, or not active */
-       if (!(howto & RB_POWEROFF) || !apm_softc.active)
-               return;
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_ALLDEV;
-       sc->bios.r.ecx = PMST_OFF;
-       sc->bios.r.edx = 0;
-       apm_bioscall();
-}
-
-/* APM Battery low handler */
-static void
-apm_battery_low(void)
-{
-       kprintf("\007\007 * * * BATTERY IS LOW * * * \007\007");
-}
-
-/* APM hook manager */
-static struct apmhook *
-apm_add_hook(struct apmhook **list, struct apmhook *ah)
-{
-       struct apmhook *p, *prev;
-
-       APM_DPRINT("Add hook \"%s\"\n", ah->ah_name);
-
-       crit_enter();
-       if (ah == NULL)
-               panic("illegal apm_hook!");
-       prev = NULL;
-       for (p = *list; p != NULL; prev = p, p = p->ah_next)
-               if (p->ah_order > ah->ah_order)
-                       break;
-
-       if (prev == NULL) {
-               ah->ah_next = *list;
-               *list = ah;
-       } else {
-               ah->ah_next = prev->ah_next;
-               prev->ah_next = ah;
-       }
-       crit_exit();
-       return ah;
-}
-
-static void
-apm_del_hook(struct apmhook **list, struct apmhook *ah)
-{
-       struct apmhook *p, *prev;
-
-       crit_enter();
-       prev = NULL;
-       for (p = *list; p != NULL; prev = p, p = p->ah_next)
-               if (p == ah)
-                       goto deleteit;
-       panic("Tried to delete unregistered apm_hook.");
-       goto nosuchnode;
-deleteit:
-       if (prev != NULL)
-               prev->ah_next = p->ah_next;
-       else
-               *list = p->ah_next;
-nosuchnode:
-       crit_exit();
-}
-
-
-/* APM driver calls some functions automatically */
-static void
-apm_execute_hook(struct apmhook *list)
-{
-       struct apmhook *p;
-
-       for (p = list; p != NULL; p = p->ah_next) {
-               APM_DPRINT("Execute APM hook \"%s.\"\n", p->ah_name);
-               if ((*(p->ah_fun))(p->ah_arg))
-                       kprintf("Warning: APM hook \"%s\" failed", p->ah_name);
-       }
-}
-
-
-/* establish an apm hook */
-struct apmhook *
-apm_hook_establish(int apmh, struct apmhook *ah)
-{
-       if (apmh < 0 || apmh >= NAPM_HOOK)
-               return NULL;
-
-       return apm_add_hook(&hook[apmh], ah);
-}
-
-/* disestablish an apm hook */
-void
-apm_hook_disestablish(int apmh, struct apmhook *ah)
-{
-       if (apmh < 0 || apmh >= NAPM_HOOK)
-               return;
-
-       apm_del_hook(&hook[apmh], ah);
-}
-
-
-static struct timeval suspend_time;
-static struct timeval diff_time;
-
-static int
-apm_default_resume(void *arg)
-{
-       u_int second, minute, hour;
-       struct timeval resume_time, tmp_time;
-
-       /* modified for adjkerntz */
-       crit_enter();
-       timer_restore();                /* restore the all timers */
-       inittodr(0);                    /* adjust time to RTC */
-       microtime(&resume_time);
-       getmicrotime(&tmp_time);
-       timevaladd(&tmp_time, &diff_time);
-
-#ifdef FIXME
-       /* XXX THIS DOESN'T WORK!!! */
-       time = tmp_time;
-#endif
-
-#ifdef APM_FIXUP_CALLTODO
-       /* Calculate the delta time suspended */
-       timevalsub(&resume_time, &suspend_time);
-       /* Fixup the calltodo list with the delta time. */
-       adjust_timeout_calltodo(&resume_time);
-#endif /* APM_FIXUP_CALLTODOK */
-       crit_exit();
-#ifndef APM_FIXUP_CALLTODO
-       second = resume_time.tv_sec - suspend_time.tv_sec; 
-#else /* APM_FIXUP_CALLTODO */
-       /* 
-        * We've already calculated resume_time to be the delta between 
-        * the suspend and the resume. 
-        */
-       second = resume_time.tv_sec; 
-#endif /* APM_FIXUP_CALLTODO */
-       hour = second / 3600;
-       second %= 3600;
-       minute = second / 60;
-       second %= 60;
-       log(LOG_NOTICE, "resumed from suspended mode (slept %02d:%02d:%02d)\n",
-               hour, minute, second);
-       return 0;
-}
-
-static int
-apm_default_suspend(void *arg)
-{
-       crit_enter();
-       microtime(&diff_time);
-       inittodr(0);
-       microtime(&suspend_time);
-       timevalsub(&diff_time, &suspend_time);
-       crit_exit();
-       return 0;
-}
-
-static int apm_record_event (struct apm_softc *, u_int);
-static void apm_processevent(void);
-
-static u_int apm_op_inprog = 0;
-
-static void
-apm_do_suspend(void)
-{
-       struct apm_softc *sc = &apm_softc;
-       int error;
-
-       if (!sc)
-               return;
-
-       apm_op_inprog = 0;
-       sc->suspends = sc->suspend_countdown = 0;
-
-       if (sc->initialized) {
-               error = DEVICE_SUSPEND(root_bus);
-               if (error) {
-                       DEVICE_RESUME(root_bus);
-               } else {
-                       apm_execute_hook(hook[APM_HOOK_SUSPEND]);
-                       if (apm_suspend_system(PMST_SUSPEND) == 0) {
-                               apm_processevent();
-                       } else {
-                               /* Failure, 'resume' the system again */
-                               apm_execute_hook(hook[APM_HOOK_RESUME]);
-                               DEVICE_RESUME(root_bus);
-                       }
-               }
-       }
-}
-
-static void
-apm_do_standby(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (!sc)
-               return;
-
-       apm_op_inprog = 0;
-       sc->standbys = sc->standby_countdown = 0;
-
-       if (sc->initialized) {
-               /*
-                * As far as standby, we don't need to execute 
-                * all of suspend hooks.
-                */
-               apm_default_suspend(&apm_softc);
-               if (apm_suspend_system(PMST_STANDBY) == 0)
-                       apm_processevent();
-       }
-}
-
-static void
-apm_lastreq_notify(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_ALLDEV;
-       sc->bios.r.ecx = PMST_LASTREQNOTIFY;
-       sc->bios.r.edx = 0;
-       apm_bioscall();
-}
-
-static int
-apm_lastreq_rejected(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (apm_op_inprog == 0) {
-               return 1;       /* no operation in progress */
-       }
-
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
-       sc->bios.r.ebx = PMDV_ALLDEV;
-       sc->bios.r.ecx = PMST_LASTREQREJECT;
-       sc->bios.r.edx = 0;
-
-       if (apm_bioscall()) {
-               APM_DPRINT("apm_lastreq_rejected: failed\n");
-               return 1;
-       }
-       apm_op_inprog = 0;
-       return 0;
-}
-
-/*
- * Public interface to the suspend/resume:
- *
- * Execute suspend and resume hook before and after sleep, respectively.
- *
- */
-
-void
-apm_suspend(int state)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (!sc->initialized)
-               return;
-
-       switch (state) {
-       case PMST_SUSPEND:
-               if (sc->suspends)
-                       return;
-               sc->suspends++;
-               sc->suspend_countdown = apm_suspend_delay;
-               break;
-       case PMST_STANDBY:
-               if (sc->standbys)
-                       return;
-               sc->standbys++;
-               sc->standby_countdown = apm_standby_delay;
-               break;
-       default:
-               kprintf("apm_suspend: Unknown Suspend state 0x%x\n", state);
-               return;
-       }
-
-       apm_op_inprog++;
-       apm_lastreq_notify();
-}
-
-void
-apm_resume(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (!sc)
-               return;
-
-       if (sc->initialized) {
-               apm_execute_hook(hook[APM_HOOK_RESUME]);
-               DEVICE_RESUME(root_bus);
-       }
-}
-
-
-/* get power status per battery */
-static int
-apm_get_pwstatus(apm_pwstatus_t app)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (app->ap_device != PMDV_ALLDEV &&
-           (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
-               return 1;
-
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_GETPWSTATUS;
-       sc->bios.r.ebx = app->ap_device;
-       sc->bios.r.ecx = 0;
-       sc->bios.r.edx = 0xffff;        /* default to unknown battery time */
-
-       if (apm_bioscall())
-               return 1;
-
-       app->ap_acline    = (sc->bios.r.ebx >> 8) & 0xff;
-       app->ap_batt_stat = sc->bios.r.ebx & 0xff;
-       app->ap_batt_flag = (sc->bios.r.ecx >> 8) & 0xff;
-       app->ap_batt_life = sc->bios.r.ecx & 0xff;
-       sc->bios.r.edx &= 0xffff;
-       if (sc->bios.r.edx == 0xffff)   /* Time is unknown */
-               app->ap_batt_time = -1;
-       else if (sc->bios.r.edx & 0x8000)       /* Time is in minutes */
-               app->ap_batt_time = (sc->bios.r.edx & 0x7fff) * 60;
-       else                            /* Time is in seconds */
-               app->ap_batt_time = sc->bios.r.edx;
-
-       return 0;
-}
-
-
-/* get APM information */
-static int
-apm_get_info(apm_info_t aip)
-{
-       struct apm_softc *sc = &apm_softc;
-       struct apm_pwstatus aps;
-
-       bzero(&aps, sizeof(aps));
-       aps.ap_device = PMDV_ALLDEV;
-       if (apm_get_pwstatus(&aps))
-               return 1;
-
-       aip->ai_infoversion = 1;
-       aip->ai_acline      = aps.ap_acline;
-       aip->ai_batt_stat   = aps.ap_batt_stat;
-       aip->ai_batt_life   = aps.ap_batt_life;
-       aip->ai_batt_time   = aps.ap_batt_time;
-       aip->ai_major       = (u_int)sc->majorversion;
-       aip->ai_minor       = (u_int)sc->minorversion;
-       aip->ai_status      = (u_int)sc->active;
-
-       sc->bios.r.eax = (APM_BIOS << 8) | APM_GETCAPABILITIES;
-       sc->bios.r.ebx = 0;
-       sc->bios.r.ecx = 0;
-       sc->bios.r.edx = 0;
-       if (apm_bioscall()) {
-               aip->ai_batteries = -1; /* Unknown */
-               aip->ai_capabilities = 0xff00; /* Unknown, with no bits set */
-       } else {
-               aip->ai_batteries = sc->bios.r.ebx & 0xff;
-               aip->ai_capabilities = sc->bios.r.ecx & 0xf;
-       }
-
-       bzero(aip->ai_spare, sizeof aip->ai_spare);
-
-       return 0;
-}
-
-
-/* inform APM BIOS that CPU is idle */
-void
-apm_cpu_idle(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (sc->active) {
-
-               sc->bios.r.eax = (APM_BIOS <<8) | APM_CPUIDLE;
-               sc->bios.r.edx = sc->bios.r.ecx = sc->bios.r.ebx = 0;
-               apm_bioscall();
-       }
-       /*
-        * Some APM implementation halts CPU in BIOS, whenever
-        * "CPU-idle" function are invoked, but swtch() of
-        * FreeBSD halts CPU, therefore, CPU is halted twice
-        * in the sched loop. It makes the interrupt latency
-        * terribly long and be able to cause a serious problem
-        * in interrupt processing. We prevent it by removing
-        * "hlt" operation from swtch() and managed it under
-        * APM driver.
-        */
-       if (!sc->active || sc->always_halt_cpu)
-               __asm("hlt");   /* wait for interrupt */
-}
-
-/* inform APM BIOS that CPU is busy */
-void
-apm_cpu_busy(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       /*
-        * The APM specification says this is only necessary if your BIOS
-        * slows down the processor in the idle task, otherwise it's not
-        * necessary.
-        */
-       if (sc->slow_idle_cpu && sc->active) {
-
-               sc->bios.r.eax = (APM_BIOS <<8) | APM_CPUBUSY;
-               sc->bios.r.edx = sc->bios.r.ecx = sc->bios.r.ebx = 0;
-               apm_bioscall();
-       }
-}
-
-
-/*
- * APM timeout routine:
- *
- * This routine is automatically called by timer once per second.
- */
-
-static void
-apm_timeout(void *dummy)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (apm_op_inprog)
-               apm_lastreq_notify();
-
-       if (sc->standbys && sc->standby_countdown-- <= 0)
-               apm_do_standby();
-
-       if (sc->suspends && sc->suspend_countdown-- <= 0)
-               apm_do_suspend();
-
-       if (!sc->bios_busy)
-               apm_processevent();
-
-       if (sc->active == 1) {
-               /* Run slightly more oftan than 1 Hz */
-               callout_reset(&apm_timeout_ch, hz - 1, apm_timeout, NULL);
-       }
-}
-
-/* enable APM BIOS */
-static void
-apm_event_enable(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       APM_DPRINT("called apm_event_enable()\n");
-       if (sc->initialized) {
-               sc->active = 1;
-               callout_init(&apm_timeout_ch);
-               apm_timeout(sc);
-       }
-}
-
-/* disable APM BIOS */
-static void
-apm_event_disable(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       APM_DPRINT("called apm_event_disable()\n");
-       if (sc->initialized) {
-               callout_stop(&apm_timeout_ch);
-               sc->active = 0;
-       }
-}
-
-/* halt CPU in scheduling loop */
-static void
-apm_halt_cpu(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (sc->initialized)
-               sc->always_halt_cpu = 1;
-}
-
-/* don't halt CPU in scheduling loop */
-static void
-apm_not_halt_cpu(void)
-{
-       struct apm_softc *sc = &apm_softc;
-
-       if (sc->initialized)
-               sc->always_halt_cpu = 0;
-}
-
-/* device driver definitions */
-
-/*
- * probe for APM BIOS
- */
-static int
-apm_probe(device_t dev)
-{
-#define APM_KERNBASE   KERNBASE
-       struct vm86frame        vmf;
-       struct apm_softc        *sc = &apm_softc;
-       int                     disabled, flags;
-
-       if (resource_int_value("apm", 0, "disabled", &disabled) == 0
-           && disabled != 0)
-               return ENXIO;
-
-       device_set_desc(dev, "APM BIOS");
-
-       if ( device_get_unit(dev) > 0 ) {
-               kprintf("apm: Only one APM driver supported.\n");
-               return ENXIO;
-       }
-
-       if (resource_int_value("apm", 0, "flags", &flags) != 0)
-               flags = 0;
-
-       bzero(&vmf, sizeof(struct vm86frame));          /* safety */
-       bzero(&apm_softc, sizeof(apm_softc));
-       vmf.vmf_ah = APM_BIOS;
-       vmf.vmf_al = APM_INSTCHECK;
-       vmf.vmf_bx = 0;
-       if (vm86_intcall(APM_INT, &vmf))
-               return ENXIO;                   /* APM not found */
-       if (vmf.vmf_bx != 0x504d) {
-               kprintf("apm: incorrect signature (0x%x)\n", vmf.vmf_bx);
-               return ENXIO;
-       }
-       if ((vmf.vmf_cx & (APM_32BIT_SUPPORT | APM_16BIT_SUPPORT)) == 0) {
-               kprintf("apm: protected mode connections are not supported\n");
-               return ENXIO;
-       }
-
-       apm_version = vmf.vmf_ax;
-       sc->slow_idle_cpu = ((vmf.vmf_cx & APM_CPUIDLE_SLOW) != 0);
-       sc->disabled = ((vmf.vmf_cx & APM_DISABLED) != 0);
-       sc->disengaged = ((vmf.vmf_cx & APM_DISENGAGED) != 0);
-
-       vmf.vmf_ah = APM_BIOS;
-       vmf.vmf_al = APM_DISCONNECT;
-       vmf.vmf_bx = 0;
-        vm86_intcall(APM_INT, &vmf);           /* disconnect, just in case */
-
-       if ((vmf.vmf_cx & APM_32BIT_SUPPORT) != 0) {
-               vmf.vmf_ah = APM_BIOS;
-               vmf.vmf_al = APM_PROT32CONNECT;
-               vmf.vmf_bx = 0;
-               if (vm86_intcall(APM_INT, &vmf)) {
-                       kprintf("apm: 32-bit connection error.\n");
-                       return (ENXIO);
-               }
-               sc->bios.seg.code32.base = (vmf.vmf_ax << 4) + APM_KERNBASE;
-               sc->bios.seg.code32.limit = 0xffff;
-               sc->bios.seg.code16.base = (vmf.vmf_cx << 4) + APM_KERNBASE;
-               sc->bios.seg.code16.limit = 0xffff;
-               sc->bios.seg.data.base = (vmf.vmf_dx << 4) + APM_KERNBASE;
-               sc->bios.seg.data.limit = 0xffff;
-               sc->bios.entry = vmf.vmf_ebx;
-               sc->connectmode = APM_PROT32CONNECT;
-       } else {
-               /* use 16-bit connection */
-               vmf.vmf_ah = APM_BIOS;
-               vmf.vmf_al = APM_PROT16CONNECT;
-               vmf.vmf_bx = 0;
-               if (vm86_intcall(APM_INT, &vmf)) {
-                       kprintf("apm: 16-bit connection error.\n");
-                       return (ENXIO);
-               }
-               sc->bios.seg.code16.base = (vmf.vmf_ax << 4) + APM_KERNBASE;
-               sc->bios.seg.code16.limit = 0xffff;
-               sc->bios.seg.data.base = (vmf.vmf_cx << 4) + APM_KERNBASE;
-               sc->bios.seg.data.limit = 0xffff;
-               sc->bios.entry = vmf.vmf_bx;
-               sc->connectmode = APM_PROT16CONNECT;
-       }
-       return(0);
-}
-
-
-/*
- * return 0 if the user will notice and handle the event,
- * return 1 if the kernel driver should do so.
- */
-static int
-apm_record_event(struct apm_softc *sc, u_int event_type)
-{
-       struct apm_event_info *evp;
-
-       if ((sc->sc_flags & SCFLAG_OPEN) == 0)
-               return 1;               /* no user waiting */
-       if (sc->event_count == APM_NEVENTS)
-               return 1;                       /* overflow */
-       if (sc->event_filter[event_type] == 0)
-               return 1;               /* not registered */
-       evp = &sc->event_list[sc->event_ptr];
-       sc->event_count++;
-       sc->event_ptr++;
-       sc->event_ptr %= APM_NEVENTS;
-       evp->type = event_type;
-       evp->index = ++apm_evindex;
-       KNOTE(&sc->sc_rkq.ki_note, 0);
-       return (sc->sc_flags & SCFLAG_OCTL) ? 0 : 1; /* user may handle */
-}
-
-/* Process APM event */
-static void
-apm_processevent(void)
-{
-       int apm_event;
-       struct apm_softc *sc = &apm_softc;
-
-#define OPMEV_DEBUGMESSAGE(symbol) case symbol:                                \
-       APM_DPRINT("Received APM Event: " #symbol "\n");
-
-       do {
-               apm_event = apm_getevent();
-               switch (apm_event) {
-                   OPMEV_DEBUGMESSAGE(PMEV_STANDBYREQ);
-                       if (apm_op_inprog == 0) {
-                           apm_op_inprog++;
-                           if (apm_record_event(sc, apm_event)) {
-                               apm_suspend(PMST_STANDBY);
-                           }
-                       }
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_USERSTANDBYREQ);
-                       if (apm_op_inprog == 0) {
-                           apm_op_inprog++;
-                           if (apm_record_event(sc, apm_event)) {
-                               apm_suspend(PMST_STANDBY);
-                           }
-                       }
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_SUSPENDREQ);
-                       apm_lastreq_notify();
-                       if (apm_op_inprog == 0) {
-                           apm_op_inprog++;
-                           if (apm_record_event(sc, apm_event)) {
-                               apm_do_suspend();
-                           }
-                       }
-                       return; /* XXX skip the rest */
-                   OPMEV_DEBUGMESSAGE(PMEV_USERSUSPENDREQ);
-                       apm_lastreq_notify();
-                       if (apm_op_inprog == 0) {
-                           apm_op_inprog++;
-                           if (apm_record_event(sc, apm_event)) {
-                               apm_do_suspend();
-                           }
-                       }
-                       return; /* XXX skip the rest */
-                   OPMEV_DEBUGMESSAGE(PMEV_CRITSUSPEND);
-                       apm_do_suspend();
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_NORMRESUME);
-                       apm_record_event(sc, apm_event);
-                       apm_resume();
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_CRITRESUME);
-                       apm_record_event(sc, apm_event);
-                       apm_resume();
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_STANDBYRESUME);
-                       apm_record_event(sc, apm_event);
-                       apm_resume();
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_BATTERYLOW);
-                       if (apm_record_event(sc, apm_event)) {
-                           apm_battery_low();
-                           apm_suspend(PMST_SUSPEND);
-                       }
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE);
-                       apm_record_event(sc, apm_event);
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_UPDATETIME);
-                       apm_record_event(sc, apm_event);
-                       inittodr(0);    /* adjust time to RTC */
-                       break;
-                   OPMEV_DEBUGMESSAGE(PMEV_CAPABILITIESCHANGE);
-                       apm_record_event(sc, apm_event);
-                       break;
-                   case PMEV_NOEVENT:
-                       break;
-                   default:
-                       kprintf("Unknown Original APM Event 0x%x\n", apm_event);
-                           break;
-               }
-       } while (apm_event != PMEV_NOEVENT);
-}
-
-/*
- * Attach APM:
- *
- * Initialize APM driver
- */
-
-static int
-apm_attach(device_t dev)
-{
-       struct apm_softc        *sc = &apm_softc;
-       int                     flags;
-       int                     drv_version;
-
-       if (resource_int_value("apm", 0, "flags", &flags) != 0)
-               flags = 0;
-
-       sc->initialized = 0;
-
-       /* Must be externally enabled */
-       sc->active = 0;
-
-       /* Always call HLT in idle loop */
-       sc->always_halt_cpu = 1;
-
-       kgetenv_int("debug.apm_debug", &apm_debug);
-
-       /* print bootstrap messages */
-       APM_DPRINT("apm: APM BIOS version %04lx\n",  apm_version);
-       APM_DPRINT("apm: Code16 0x%08x, Data 0x%08x\n",
-           sc->bios.seg.code16.base, sc->bios.seg.data.base);
-       APM_DPRINT("apm: Code entry 0x%08x, Idling CPU %s, Management %s\n",
-           sc->bios.entry, is_enabled(sc->slow_idle_cpu),
-           is_enabled(!sc->disabled));
-       APM_DPRINT("apm: CS_limit=0x%x, DS_limit=0x%x\n",
-           sc->bios.seg.code16.limit, sc->bios.seg.data.limit);
-
-       /*
-         * In one test, apm bios version was 1.02; an attempt to register
-         * a 1.04 driver resulted in a 1.00 connection!  Registering a
-         * 1.02 driver resulted in a 1.02 connection.
-         */
-       drv_version = apm_version > 0x102 ? 0x102 : apm_version;
-       for (; drv_version > 0x100; drv_version--)
-               if (apm_driver_version(drv_version) == 0)
-                       break;
-       sc->minorversion = ((drv_version & 0x00f0) >>  4) * 10 +
-               ((drv_version & 0x000f) >> 0);
-       sc->majorversion = ((drv_version & 0xf000) >> 12) * 10 +
-               ((apm_version & 0x0f00) >> 8);
-
-       sc->intversion = INTVERSION(sc->majorversion, sc->minorversion);
-
-       if (sc->intversion >= INTVERSION(1, 1))
-               APM_DPRINT("apm: Engaged control %s\n", is_enabled(!sc->disengaged));
-       device_printf(dev, "found APM BIOS v%ld.%ld, connected at v%d.%d\n",
-              ((apm_version & 0xf000) >> 12) * 10 + ((apm_version & 0x0f00) >> 8),
-              ((apm_version & 0x00f0) >> 4) * 10 + ((apm_version & 0x000f) >> 0),
-              sc->majorversion, sc->minorversion);
-
-
-       APM_DPRINT("apm: Slow Idling CPU %s\n", is_enabled(sc->slow_idle_cpu));
-       /* enable power management */
-       if (sc->disabled) {
-               if (apm_enable_disable_pm(1)) {
-                       APM_DPRINT("apm: *Warning* enable function failed! [%x]\n",
-                           (sc->bios.r.eax >> 8) & 0xff);
-               }
-       }
-
-       /* engage power managment (APM 1.1 or later) */
-       if (sc->intversion >= INTVERSION(1, 1) && sc->disengaged) {
-               if (apm_engage_disengage_pm(1)) {
-                       APM_DPRINT("apm: *Warning* engage function failed err=[%x]",
-                           (sc->bios.r.eax >> 8) & 0xff);
-                       APM_DPRINT(" (Docked or using external power?).\n");
-               }
-       }
-
-        /* default suspend hook */
-        sc->sc_suspend.ah_fun = apm_default_suspend;
-        sc->sc_suspend.ah_arg = sc;
-        sc->sc_suspend.ah_name = "default suspend";
-        sc->sc_suspend.ah_order = APM_MAX_ORDER;
-
-        /* default resume hook */
-        sc->sc_resume.ah_fun = apm_default_resume;
-        sc->sc_resume.ah_arg = sc;
-        sc->sc_resume.ah_name = "default resume";
-        sc->sc_resume.ah_order = APM_MIN_ORDER;
-
-        apm_hook_establish(APM_HOOK_SUSPEND, &sc->sc_suspend);
-        apm_hook_establish(APM_HOOK_RESUME , &sc->sc_resume);
-
-       /* Power the system off using APM */
-       EVENTHANDLER_REGISTER(shutdown_final, apm_power_off, NULL, 
-                             SHUTDOWN_PRI_LAST);
-
-       sc->initialized = 1;
-
-       make_dev(&apm_ops, 0, UID_ROOT, GID_OPERATOR, 0660, "apm");
-       make_dev(&apm_ops, 8, UID_ROOT, GID_OPERATOR, 0660, "apmctl");
-       return 0;
-}
-
-static int
-apmopen(struct dev_open_args *ap)
-{
-       cdev_t dev = ap->a_head.a_dev;
-       struct apm_softc *sc = &apm_softc;
-       int ctl = APMDEV(dev);
-
-       if (!sc->initialized)
-               return (ENXIO);
-
-       switch (ctl) {
-       case APMDEV_CTL:
-               if (!(ap->a_oflags & FWRITE))
-                       return EINVAL;
-               if (sc->sc_flags & SCFLAG_OCTL)
-                       return EBUSY;
-               sc->sc_flags |= SCFLAG_OCTL;
-               bzero(sc->event_filter, sizeof sc->event_filter);
-               break;
-       case APMDEV_NORMAL:
-               sc->sc_flags |= SCFLAG_ONORMAL;
-               break;
-       default:
-               return ENXIO;
-               break;
-       }
-       return 0;
-}
-
-static int
-apmclose(struct dev_close_args *ap)
-{
-       cdev_t dev = ap->a_head.a_dev;
-       struct apm_softc *sc = &apm_softc;
-       int ctl = APMDEV(dev);
-
-       switch (ctl) {
-       case APMDEV_CTL:
-               apm_lastreq_rejected();
-               sc->sc_flags &= ~SCFLAG_OCTL;
-               bzero(sc->event_filter, sizeof sc->event_filter);
-               break;
-       case APMDEV_NORMAL:
-               sc->sc_flags &= ~SCFLAG_ONORMAL;
-               break;
-       }
-       if ((sc->sc_flags & SCFLAG_OPEN) == 0) {
-               sc->event_count = 0;
-               sc->event_ptr = 0;
-       }
-       return 0;
-}
-
-static int
-apmioctl(struct dev_ioctl_args *ap)
-{
-       cdev_t dev = ap->a_head.a_dev;
-       struct apm_softc *sc = &apm_softc;
-       struct apm_bios_arg *args;
-       int error = 0;
-       int ret;
-       int newstate;
-
-       if (!sc->initialized)
-               return (ENXIO);
-       APM_DPRINT("APM ioctl: cmd = 0x%lx\n", ap->a_cmd);
-
-       switch (ap->a_cmd) {
-       case APMIO_SUSPEND:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               if (sc->active)
-                       apm_suspend(PMST_SUSPEND);
-               else
-                       error = EINVAL;
-               break;
-
-       case APMIO_STANDBY:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               if (sc->active)
-                       apm_suspend(PMST_STANDBY);
-               else
-                       error = EINVAL;
-               break;
-
-       case APMIO_GETINFO_OLD:
-               {
-                       struct apm_info info;
-                       apm_info_old_t aiop;
-
-                       if (apm_get_info(&info))
-                               error = ENXIO;
-                       aiop = (apm_info_old_t)ap->a_data;
-                       aiop->ai_major = info.ai_major;
-                       aiop->ai_minor = info.ai_minor;
-                       aiop->ai_acline = info.ai_acline;
-                       aiop->ai_batt_stat = info.ai_batt_stat;
-                       aiop->ai_batt_life = info.ai_batt_life;
-                       aiop->ai_status = info.ai_status;
-               }
-               break;
-       case APMIO_GETINFO:
-               if (apm_get_info((apm_info_t)ap->a_data))
-                       error = ENXIO;
-               break;
-       case APMIO_GETPWSTATUS:
-               if (apm_get_pwstatus((apm_pwstatus_t)ap->a_data))
-                       error = ENXIO;
-               break;
-       case APMIO_ENABLE:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               apm_event_enable();
-               break;
-       case APMIO_DISABLE:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               apm_event_disable();
-               break;
-       case APMIO_HALTCPU:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               apm_halt_cpu();
-               break;
-       case APMIO_NOTHALTCPU:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               apm_not_halt_cpu();
-               break;
-       case APMIO_DISPLAY:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               newstate = *(int *)ap->a_data;
-               if (apm_display(newstate))
-                       error = ENXIO;
-               break;
-       case APMIO_BIOS:
-               if (!(ap->a_fflag & FWRITE))
-                       return (EPERM);
-               /* XXX compatibility with the old interface */
-               args = (struct apm_bios_arg *)ap->a_data;
-               sc->bios.r.eax = args->eax;
-               sc->bios.r.ebx = args->ebx;
-               sc->bios.r.ecx = args->ecx;
-               sc->bios.r.edx = args->edx;
-               sc->bios.r.esi = args->esi;
-               sc->bios.r.edi = args->edi;
-               if ((ret = apm_bioscall())) {
-                       /*
-                        * Return code 1 means bios call was unsuccessful.
-                        * Error code is stored in %ah.
-                        * Return code -1 means bios call was unsupported
-                        * in the APM BIOS version.
-                        */
-                       if (ret == -1) {
-                               error = EINVAL;
-                       }
-               } else {
-                       /*
-                        * Return code 0 means bios call was successful.
-                        * We need only %al and can discard %ah.
-                        */
-                       sc->bios.r.eax &= 0xff;
-               }
-               args->eax = sc->bios.r.eax;
-               args->ebx = sc->bios.r.ebx;
-               args->ecx = sc->bios.r.ecx;
-               args->edx = sc->bios.r.edx;
-               args->esi = sc->bios.r.esi;
-               args->edi = sc->bios.r.edi;
-               break;
-       default:
-               error = EINVAL;
-               break;
-       }
-
-       /* for /dev/apmctl */
-       if (APMDEV(dev) == APMDEV_CTL) {
-               struct apm_event_info *evp;
-               int i;
-
-               error = 0;
-               switch (ap->a_cmd) {
-               case APMIO_NEXTEVENT:
-                       if (!sc->event_count) {
-                               error = EAGAIN;
-                       } else {
-                               evp = (struct apm_event_info *)ap->a_data;
-                               i = sc->event_ptr + APM_NEVENTS - sc->event_count;
-                               i %= APM_NEVENTS;
-                               *evp = sc->event_list[i];
-                               sc->event_count--;
-                       }
-                       break;
-               case APMIO_REJECTLASTREQ:
-                       if (apm_lastreq_rejected()) {
-                               error = EINVAL;
-                       }
-                       break;
-               default:
-                       error = EINVAL;
-                       break;
-               }
-       }
-
-       return error;
-}
-
-static int
-apmwrite(struct dev_write_args *ap)
-{
-       cdev_t dev = ap->a_head.a_dev;
-       struct uio *uio = ap->a_uio;
-       struct apm_softc *sc = &apm_softc;
-       u_int event_type;
-       int error;
-       u_char enabled;
-
-       if (APMDEV(dev) != APMDEV_CTL)
-               return(ENODEV);
-       if (uio->uio_resid != sizeof(u_int))
-               return(E2BIG);
-
-       if ((error = uiomove((caddr_t)&event_type, sizeof(u_int), uio)))
-               return(error);
-
-       if (event_type < 0 || event_type >= APM_NPMEV)
-               return(EINVAL);
-
-       if (sc->event_filter[event_type] == 0) {
-               enabled = 1;
-       } else {
-               enabled = 0;
-       }
-       sc->event_filter[event_type] = enabled;
-       APM_DPRINT("apmwrite: event 0x%x %s\n", event_type, is_enabled(enabled));
-
-       return uio->uio_resid;
-}
-
-static struct filterops apmfiltops_read =
-       { FILTEROP_ISFD, NULL, apmfilter_detach, apmfilter_read };
-static struct filterops apmfiltops_write =
-       { FILTEROP_ISFD, NULL, apmfilter_detach, apmfilter_write };
-
-static int
-apmkqfilter(struct dev_kqfilter_args *ap)
-{
-       struct apm_softc *sc = &apm_softc;
-       struct knote *kn = ap->a_kn;
-       struct klist *klist;
-
-       ap->a_result = 0;
-
-       switch (kn->kn_filter) {
-       case EVFILT_READ:
-               kn->kn_fop = &apmfiltops_read;
-               kn->kn_hook = (caddr_t)sc;
-               break;
-       case EVFILT_WRITE:
-               kn->kn_fop = &apmfiltops_write;
-               kn->kn_hook = (caddr_t)sc;
-               break;
-       default:
-               ap->a_result = EOPNOTSUPP;
-               return (0);
-       }
-
-       klist = &sc->sc_rkq.ki_note;
-       knote_insert(klist, kn);
-
-       return (0);
-}
-
-static void
-apmfilter_detach(struct knote *kn)
-{
-       struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
-       struct klist *klist;
-
-       klist = &sc->sc_rkq.ki_note;
-       knote_remove(klist, kn);
-}
-
-static int
-apmfilter_read(struct knote *kn, long hint)
-{
-       struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
-       int ready = 0;
-
-       if (sc->event_count)
-               ready = 1;
-
-       return (ready);
-}
-
-static int
-apmfilter_write(struct knote *kn, long hint)
-{
-       /* write()'s are always OK */
-       return (1);
-}
-
-/*
- * Because apm is a static device that always exists under any attached
- * isa device, and not scanned by the isa device, we need an identify
- * function to install the device so we can probe for it.
- */
-static device_method_t apm_methods[] = {
-       /* Device interface */
-       DEVMETHOD(device_identify,      bus_generic_identify),
-       DEVMETHOD(device_probe,         apm_probe),
-       DEVMETHOD(device_attach,        apm_attach),
-
-       DEVMETHOD_END
-};
-
-static driver_t apm_driver = {
-       "apm",
-       apm_methods,
-       1,                      /* no softc (XXX) */
-};
-
-static devclass_t apm_devclass;
-
-DRIVER_MODULE(apm, nexus, apm_driver, apm_devclass, NULL, NULL);
-
diff --git a/sys/platform/pc32/apm/apm.h b/sys/platform/pc32/apm/apm.h
deleted file mode 100644 (file)
index 501763a..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * APM (Advanced Power Management) BIOS Device Driver
- *
- * Copyright (c) 1994 UKAI, Fumitoshi.
- * Copyright (c) 1994-1995 by HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
- * Copyright (c) 1996 Nate Williams <nate@FreeBSD.org>
- * Copyright (c) 1997 Poul-Henning Kamp <phk@FreeBSD.org>
- *
- * This software may be used, modified, copied, and distributed, in
- * both source and binary form provided that the above copyright and
- * these terms are retained. Under no circumstances is the author
- * responsible for the proper functioning of this software, nor does
- * the author assume any responsibility for damages incurred with its
- * use.
- *
- * Sep, 1994   Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
- *
- * $FreeBSD: src/sys/i386/apm/apm.h,v 1.1 1999/10/02 03:34:15 nsayer Exp $
- * $DragonFly: src/sys/platform/pc32/apm/apm.h,v 1.2 2003/06/17 04:28:34 dillon Exp $
- */
-
-#define APM_NEVENTS 16
-#define APM_NPMEV   13
-
-/* static data */
-struct apm_softc {
-       int     initialized, active, bios_busy;
-       int     always_halt_cpu, slow_idle_cpu;
-       int     disabled, disengaged;
-       int     standby_countdown, suspend_countdown;
-       u_int   minorversion, majorversion;
-       u_int   intversion, connectmode;
-       u_int   standbys, suspends;
-       struct bios_args bios;
-       struct apmhook sc_suspend;
-       struct apmhook sc_resume;
-       struct kqinfo sc_rkq;
-       int     sc_flags;
-       int     event_count;
-       int     event_ptr;
-       struct  apm_event_info event_list[APM_NEVENTS];
-       u_char  event_filter[APM_NPMEV];
-};
-
index df294e2..b21eeec 100644 (file)
@@ -169,7 +169,6 @@ vfs/smbfs/smbfs_smb.c               optional        smbfs
 vfs/smbfs/smbfs_subr.c         optional        smbfs
 vfs/smbfs/smbfs_vfsops.c       optional        smbfs
 vfs/smbfs/smbfs_vnops.c                optional        smbfs
-platform/pc32/apm/apm.c                optional        apm
 cpu/i386/misc/atomic.c         standard                                \
        compile-with    "${CC} -c ${CFLAGS} ${WERROR} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}"
 cpu/i386/misc/elf_machdep.c            standard
index c32a14c..58bcc3d 100644 (file)
@@ -341,7 +341,6 @@ static DEV_INFO device_info[] = {
 {"joy",         "Joystick",                            FLG_FIXED,      CLS_INPUT},
 {"sc",          "Syscons console driver",              FLG_IMMUTABLE,  CLS_INPUT},
 
-{"apm",         "Advanced Power Management",           FLG_FIXED,      CLS_MISC},
 {"pcic",        "PC-card controller",                  0,              CLS_MISC},
 {"npx",                "Math coprocessor",                     FLG_IMMUTABLE,  CLS_MISC},
 {"vga",                "Catchall PCI VGA driver",              FLG_INVISIBLE,  CLS_MISC},
index b37d8b0..d7fc406 100644 (file)
@@ -152,10 +152,7 @@ SUBDIR+=nscd
 .endif
 
 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
-SUBDIR+=apm \
-       apmd \
-       battd \
-       btxld \
+SUBDIR+=btxld \
        kgmon \
        lptcontrol \
        mptable \
index f2b0e61..d7c3873 100644 (file)
@@ -3,5 +3,7 @@
 
 PROG=  acpiconf
 MAN=   acpiconf.8
+LINKS= ${BINDIR}/acpiconf ${BINDIR}/apm
+MLINKS=        acpiconf.8 apm.8
 
 .include <bsd.prog.mk>
index 4ab176d..0de95ab 100644 (file)
 .\"
 .\" $FreeBSD: head/usr.sbin/acpi/acpiconf/acpiconf.8 267668 2014-06-20 09:57:27Z bapt $
 .\"
-.Dd September 11, 2014
+.Dd June 20, 2015
 .Dt ACPICONF 8
 .Os
 .Sh NAME
-.Nm acpiconf
+.Nm acpiconf ,
+.Nm apm
 .Nd control ACPI power management
 .Sh SYNOPSIS
 .Nm
@@ -39,6 +40,8 @@
 .Op Fl i Ar batt
 .Op Fl k Ar ack
 .Op Fl s Ar type
+.Pp
+.Nm apm
 .Sh DESCRIPTION
 The
 .Nm
@@ -78,6 +81,10 @@ and
 scripts are executable, they will be run before and after entering
 the given sleep state.
 .El
+.Pp
+.Nm apm
+is a shortcut for
+.Nm Fl i Ar 0 .
 .Sh SEE ALSO
 .Xr acpi 4 ,
 .Xr acpibin 8 ,
@@ -86,7 +93,6 @@ the given sleep state.
 .Xr acpihelp 8 ,
 .Xr acpinames 8 ,
 .Xr acpixtract 8 ,
-.Xr apm 8 ,
 .Xr iasl 8
 .Sh HISTORY
 The
index 5b75fb3..93be573 100644 (file)
@@ -188,13 +188,19 @@ usage(const char* prog)
 int
 main(int argc, char *argv[])
 {
-       char    c, *prog;
+       char    c, *prog, *ptr;
        int     sleep_type;
 
        prog = argv[0];
-       if (argc < 2)
+       if (strstr((ptr = strrchr(prog, '/')) ? ptr + 1 : prog, "apm") != 0) {
+               acpi_init();
+               acpi_battinfo(0);
+               close(acpifd);
+               exit(0);
+       } else if (argc < 2) {
                usage(prog);
                /* NOTREACHED */
+       }
 
        sleep_type = -1;
        acpi_init();
diff --git a/usr.sbin/apm/Makefile b/usr.sbin/apm/Makefile
deleted file mode 100644 (file)
index 08e029c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# $FreeBSD: src/usr.sbin/apm/Makefile,v 1.10.2.1 2001/04/25 12:09:17 ru Exp $
-# $DragonFly: src/usr.sbin/apm/Makefile,v 1.3 2004/12/20 10:28:41 liamfoy Exp $
-
-PROG=  apm
-LINKS= ${BINDIR}/apm ${BINDIR}/zzz
-MAN=   apm.8
-MLINKS=        apm.8 apmconf.8 apm.8 zzz.8
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/apm/apm.8 b/usr.sbin/apm/apm.8
deleted file mode 100644 (file)
index 74915fb..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-.\" LP (Laptop Package)
-.\"
-.\" Copyright (c) 1994 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
-.\"
-.\" This software may be used, modified, copied, and distributed, in
-.\" both source and binary form provided that the above copyright and
-.\" these terms are retained. Under no circumstances is the author
-.\" responsible for the proper functioning of this software, nor does
-.\" the author assume any responsibility for damages incurred with its
-.\" use.
-.\"
-.\" $FreeBSD: src/usr.sbin/apm/apm.8,v 1.16.2.7 2003/05/07 17:42:02 tobez Exp $
-.\"
-.Dd November 1, 1994
-.Dt APM 8
-.Os
-.Sh NAME
-.Nm apm ,
-.Nm zzz
-.Nd control the APM BIOS and display its information
-.Sh SYNOPSIS
-.Nm
-.Op Fl ablstzZ
-.Op Fl d Ar enable
-.Op Fl e Ar enable
-.Op Fl h Ar enable
-.Op Fl r Ar delta
-.Pp
-.Nm zzz
-.Sh DESCRIPTION
-The
-.Nm
-utility
-controls the Intel / Microsoft APM (Advanced Power Management) BIOS and
-displays the current status of APM on laptop PCs.
-The
-.Nm zzz
-utility suspends the system by controlling APM.
-.Pp
-The following options are available for
-.Nm
-(no options are available for
-.Nm zzz ) .
-If no options are specified,
-.Nm
-displays information and current status of APM in verbose mode.
-If multiple display options are given, the values are displayed one
-per line in the order given here.
-.Bl -tag -width indent
-.It Fl a
-Display the current AC-line status as an integer value.  The values
-0, 1 and 2 correspond to the
-.Dq off-line
-state,
-.Dq on-line
-state or
-.Dq backup power
-state, respectively.
-.It Fl b
-Display an integer value reflecting the current battery status.
-The values 0, 1, 2, 3, correspond to the
-.Dq high
-status,
-.Dq low
-status,
-.Dq critical
-status,
-.Dq charging
-status respectively.
-.It Fl d Ar enable
-Disable/enable suspending of the display separately from a normal suspend
-using the boolean value for
-.Ar enable .
-This feature seems to not work on many different laptops,
-including the Libretto 30CT and 50CT.
-.It Fl e Ar enable
-Enable or disable APM functions of the computer,
-depending on the boolean
-.Ar enable
-argument.
-.It Fl h Ar enable
-Depending on the boolean value of
-.Ar enable ,
-enable or disable the HLT instruction in the kernel context switch routine.
-These options are not necessary for almost all APM implementations,
-but for some implementations whose
-.Dq Pa Idle CPU
-call executes both CPU clock slowdown and HLT instruction,
-.Fl h Ar false
-is necessary to prevent the system from reducing its peak performance.
-See
-.Xr apm 4
-for details.
-.It Fl l
-Display the remaining battery percentage.  If your laptop does not
-support this function, 255 is displayed.
-.It Fl r Ar delta
-Enable the resume wakeup timer, if the laptop supports it.  This
-doesn't actually suspend the laptop, but if the laptop is suspended,
-and it supports resume from suspend, then it will be resumed after
-.Ar delta
-seconds (from when you run this command, not from when you suspend).
-.It Fl s
-Display the status of the APM support as an integer value.  The values
-0 and 1 correspond to the
-.Dq disabled
-state or
-.Dq enabled
-state respectively.
-.It Fl t
-Display the estimated remaining battery lifetime in seconds.  If
-it is unknown, -1 is displayed.
-.It Fl Z
-Transition the system into standby mode.  This mode uses less power than
-full power mode, but more than suspend mode.  Some laptops support
-resuming from this state on timer or Ring Indicator events.  The
-output of
-.Nm
-tells what your laptop claims to support.
-.It Fl z
-Suspend the system.
-It is equivalent to
-.Nm zzz .
-.El
-.Sh NOTES
-.Xr apmconf 8
-has been merged in
-.Nm
-and thus
-.Nm
-replaces all of its functionality.
-.Sh SEE ALSO
-.Xr apm 4
-.Sh AUTHORS
-.An Tatsumi Hosokawa Aq Mt hosokawa@jp.FreeBSD.org
-.Sh BUGS
-Some APM implementations do not support parameters needed by
-.Nm .
-On such systems,
-.Nm
-displays them as unknown.
-.Pp
-Some APM implementations cannot handle events such as pushing the
-power button or closing the cover.  On such implementations, the system
-.Ar must
-be suspended
-.Ar only
-by using
-.Nm
-or
-.Nm zzz .
diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c
deleted file mode 100644 (file)
index 7fdc1a2..0000000
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * apm / zzz   APM BIOS utility for FreeBSD
- *
- * Copyright (C) 1994-1996 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
- *
- * This software may be used, modified, copied, distributed, and sold,
- * in both source and binary form provided that the above copyright and
- * these terms are retained. Under no circumstances is the author
- * responsible for the proper functioning of this software, nor does
- * the author assume any responsibility for damages incurred with its
- * use.
- *
- * Sep., 1994  Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
- *
- * $FreeBSD: src/usr.sbin/apm/apm.c,v 1.22.2.6 2003/04/29 08:53:04 maxim Exp $
- * $DragonFly: src/usr.sbin/apm/apm.c,v 1.13 2006/08/13 02:18:51 swildner Exp $
- */
-
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
-#include <machine/apm_bios.h>
-
-#include <err.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#define APMDEV "/dev/apm"
-
-#define xh(a)  (((a) & 0xff00) >> 8)
-#define xl(a)  ((a) & 0xff)
-#define APMERR(a) xh(a)
-
-static void    apm_display(int, int);
-static void    apm_enable(int, int);
-static void    apm_getinfo(int, apm_info_t);
-static void    apm_haltcpu(int, int);
-static void    apm_set_timer(int, int);
-static void    apm_standby(int);
-static void    apm_suspend(int);
-static int     bcd2int(int);
-static int     int2bcd(int);
-static int     is_true(const char *);
-static void    print_all_info(int, apm_info_t, int);
-static void    print_batt_life(u_int);
-static void    print_batt_stat(u_int);
-static void    print_batt_time(int);
-static void    usage(void) __dead2;
-
-int cmos_wall = 0;     /* True when wall time is in cmos clock, else UTC */
-
-static void
-usage(void)
-{
-       fprintf(stderr, "%s\n%s\n",
-               "usage: apm [-ablstzZ] [-d enable ] [ -e enable ] "
-               "[ -h enable ] [-r delta]",
-               "       zzz");
-       exit(EXIT_FAILURE);
-}
-
-/*
- * Return 1 for boolean true, and 0 for false, according to the
- * interpretation of the string argument given.
- */
-static int
-is_true(const char *boolean)
-{
-       char *endp;
-       long val;
-
-       val = strtoul(boolean, &endp, 0);
-       if (*endp == '\0')
-               return (val != 0 ? 1 : 0);
-       if (strcasecmp(boolean, "true") == 0 ||
-           strcasecmp(boolean, "yes") == 0 ||
-           strcasecmp(boolean, "enable") == 0)
-               return (1);
-       if (strcasecmp(boolean, "false") == 0 ||
-           strcasecmp(boolean, "no") == 0 ||
-           strcasecmp(boolean, "disable") == 0)
-               return (0);
-       /* Well, I have no idea what the user wants, so... */
-       warnx("invalid boolean argument \"%s\"", boolean);
-       usage();
-       /* NOTREACHED */
-}
-
-static int
-int2bcd(int i)
-{
-       int retval = 0;
-       int base = 0;
-
-       if (i >= 10000)
-               return -1;
-    
-       while (i) {
-               retval |= (i % 10) << base;
-               i /= 10;
-               base += 4;
-       }
-       return retval;
-}
-
-static int
-bcd2int(int bcd)
-{
-       int retval = 0;
-       int place = 1;
-
-       if (bcd > 0x9999)
-               return -1;
-
-       while (bcd) {
-               retval += (bcd & 0xf) * place;
-               bcd >>= 4;
-               place *= 10;
-       }
-       return retval;
-}
-
-static void 
-apm_suspend(int fd)
-{
-       if (ioctl(fd, APMIO_SUSPEND, NULL) == -1)
-               err(1, "ioctl(APMIO_SUSPEND)");
-}
-
-static void 
-apm_standby(int fd)
-{
-       if (ioctl(fd, APMIO_STANDBY, NULL) == -1)
-               err(1, "ioctl(APMIO_STANDBY)");
-}
-
-static void 
-apm_getinfo(int fd, apm_info_t aip)
-{
-       if (ioctl(fd, APMIO_GETINFO, aip) == -1)
-               err(1, "ioctl(APMIO_GETINFO)");
-}
-
-static void 
-apm_enable(int fd, int enable)
-{
-
-       if (enable) {
-               if (ioctl(fd, APMIO_ENABLE) == -1)
-                       err(1, "ioctl(APMIO_ENABLE)");
-       } else {
-               if (ioctl(fd, APMIO_DISABLE) == -1)
-                       err(1, "ioctl(APMIO_DISABLE)");
-       }
-}
-
-static void
-print_batt_life(u_int batt_life)
-{
-       printf("Remaining battery life: ");
-       if (batt_life >= 255)
-               printf("unknown\n");
-       else if (batt_life <= 100)
-               printf("%d%%\n", batt_life);
-       else
-               printf("invalid value (0x%x)\n", batt_life);
-}
-
-static void
-print_batt_stat(u_int batt_stat)
-{
-       const char *batt_msg[] = { "high", "low", "critical", "charging" };
-
-       printf("Battery Status: ");
-       if (batt_stat >= 255)
-               printf("unknown\n");
-       else if (batt_stat > 3)
-               printf("invalid value (0x%x)\n", batt_stat);
-       else
-               printf("%s\n", batt_msg[batt_stat]);
-}
-
-static void
-print_batt_time(int batt_time)
-{
-       printf("Remaining battery time: ");
-       if (batt_time == -1)
-               printf("unknown\n");
-       else {
-               int h, m, s;
-
-               h = batt_time;
-               s = h % 60;
-               h /= 60;
-               m = h % 60;
-               h /= 60;
-               printf("%2d:%02d:%02d\n", h, m, s);
-       }
-}
-
-static void 
-print_all_info(int fd, apm_info_t aip, int bioscall_available)
-{
-       struct apm_bios_arg args;
-       int apmerr;
-       const char *line_msg[] = { "off-line", "on-line" , "backup power"};
-
-       printf("APM version: %d.%d\n", aip->ai_major, aip->ai_minor);
-       printf("APM Management: %s\n", (aip->ai_status ? "Enabled" : "Disabled"));
-       printf("AC Line status: ");
-       if (aip->ai_acline == 255)
-               printf("unknown\n");
-       else if (aip->ai_acline > 2)
-               printf("invalid value (0x%x)\n", aip->ai_acline);
-       else
-               printf("%s\n", line_msg[aip->ai_acline]);
-
-       print_batt_stat(aip->ai_batt_stat);
-       print_batt_life(aip->ai_batt_life);
-       print_batt_time(aip->ai_batt_time);
-
-       if (aip->ai_infoversion >= 1) {
-               printf("Number of batteries: ");
-               if (aip->ai_batteries == (u_int) -1)
-                       printf("unknown\n");
-               else {
-                       u_int i;
-                       struct apm_pwstatus aps;
-
-                       printf("%d\n", aip->ai_batteries);
-                       for (i = 0; i < aip->ai_batteries; ++i) {
-                               bzero(&aps, sizeof(aps));
-                               aps.ap_device = PMDV_BATT0 + i;
-                               if (ioctl(fd, APMIO_GETPWSTATUS, &aps) == -1)
-                                       continue;
-                               printf("Battery %d:\n", i);
-                               if (aps.ap_batt_flag != 255 &&
-                                   (aps.ap_batt_flag & APM_BATT_NOT_PRESENT)) {
-                                       printf("\tnot present\n");
-                                       continue;
-                               }
-
-                               printf("\t");
-                               print_batt_stat(aps.ap_batt_stat);
-                               printf("\t");
-                               print_batt_life(aps.ap_batt_life);
-                               printf("\t");
-                               print_batt_time(aps.ap_batt_time);
-                       }
-               }
-       }
-
-       if (bioscall_available) {
-               /*
-                * try to get the suspend timer
-                */
-               bzero(&args, sizeof(args));
-               args.eax = (APM_BIOS) << 8 | APM_RESUMETIMER;
-               args.ebx = PMDV_APMBIOS;
-               args.ecx = 0x0001;
-               if (ioctl(fd, APMIO_BIOS, &args)) {
-                       printf("Resume timer: unknown\n");
-               } else {
-                       apmerr = APMERR(args.eax);
-                       if (apmerr == 0x0d || apmerr == 0x86)
-                               printf("Resume timer: disabled\n");
-                       else if (apmerr)
-                               fprintf(stderr, 
-                                       "Failed to get the resume timer: APM error0x%x\n",
-                                       apmerr);
-                       else {
-                               /*
-                                * OK.  We have the time (all bcd).
-                                * CH - seconds
-                                * DH - hours
-                                * DL - minutes
-                                * xh(SI) - month (1-12)
-                                * xl(SI) - day of month (1-31)
-                                * DI - year
-                                */
-                               struct tm tm;
-                               char buf[1024];
-                               time_t t;
-
-                               tm.tm_sec = bcd2int(xh(args.ecx));
-                               tm.tm_min = bcd2int(xl(args.edx));
-                               tm.tm_hour = bcd2int(xh(args.edx));
-                               tm.tm_mday = bcd2int(xl(args.esi));
-                               tm.tm_mon = bcd2int(xh(args.esi)) - 1;
-                               tm.tm_year = bcd2int(args.edi) - 1900;
-                               if (cmos_wall)
-                                       t = mktime(&tm);
-                               else
-                                       t = timegm(&tm);
-                               tm = *localtime(&t);
-                               strftime(buf, sizeof(buf), "%s", &tm);
-                               printf("Resume timer: %s\n", buf);
-                       }
-               }
-
-               /*
-                * Get the ring indicator resume state
-                */
-               bzero(&args, sizeof(args));
-               args.eax  = (APM_BIOS) << 8 | APM_RESUMEONRING;
-               args.ebx = PMDV_APMBIOS;
-               args.ecx = 0x0002;
-               if (ioctl(fd, APMIO_BIOS, &args) == 0) {
-                       printf("Resume on ring indicator: %sabled\n",
-                              args.ecx ? "en" : "dis");
-               }
-       }
-
-       if (aip->ai_infoversion >= 1) {
-               printf("APM Capacities:\n");
-               if (aip->ai_capabilities == 0xff00)
-                       printf("\tunknown\n");
-               if (aip->ai_capabilities & 0x01)
-                       printf("\tglobal standby state\n");
-               if (aip->ai_capabilities & 0x02)
-                       printf("\tglobal suspend state\n");
-               if (aip->ai_capabilities & 0x04)
-                       printf("\tresume timer from standby\n");
-               if (aip->ai_capabilities & 0x08)
-                       printf("\tresume timer from suspend\n");
-               if (aip->ai_capabilities & 0x10)
-                       printf("\tRI resume from standby\n");
-               if (aip->ai_capabilities & 0x20)
-                       printf("\tRI resume from suspend\n");
-               if (aip->ai_capabilities & 0x40)
-                       printf("\tPCMCIA RI resume from standby\n");
-               if (aip->ai_capabilities & 0x80)
-                       printf("\tPCMCIA RI resume from suspend\n");
-       }
-
-}
-
-/*
- * currently, it can turn off the display, but the display never comes
- * back until the machine suspend/resumes :-).
- */
-static void 
-apm_display(int fd, int newstate)
-{
-       if (ioctl(fd, APMIO_DISPLAY, &newstate) == -1)
-               err(1, "ioctl(APMIO_DISPLAY)");
-}
-
-static void
-apm_haltcpu(int fd, int enable)
-{
-
-       if (enable) {
-               if (ioctl(fd, APMIO_HALTCPU, NULL) == -1)
-                       err(1, "ioctl(APMIO_HALTCPU)");
-       } else {
-               if (ioctl(fd, APMIO_NOTHALTCPU, NULL) == -1)
-                       err(1, "ioctl(APMIO_NOTHALTCPU)");
-       }
-}
-
-static void
-apm_set_timer(int fd, int delta)
-{
-       time_t tmr;
-       struct tm *tm;
-       struct apm_bios_arg args;
-
-       tmr = time(NULL) + delta;
-       if (cmos_wall)
-               tm = localtime(&tmr);
-       else
-               tm = gmtime(&tmr);
-       bzero(&args, sizeof(args));
-       args.eax = (APM_BIOS) << 8 | APM_RESUMETIMER;
-       args.ebx = PMDV_APMBIOS;
-       if (delta > 0) {
-               args.ecx = (int2bcd(tm->tm_sec) << 8) | 0x02;
-               args.edx = (int2bcd(tm->tm_hour) << 8) | int2bcd(tm->tm_min);
-               args.esi = (int2bcd(tm->tm_mon + 1) << 8) | int2bcd(tm->tm_mday);
-               args.edi = int2bcd(tm->tm_year + 1900);
-       } else {
-               args.ecx = 0x0000;
-       }
-       if (ioctl(fd, APMIO_BIOS, &args)) {
-               err(1,"Set resume timer");
-       }
-}
-
-int 
-main(int argc, char *argv[])
-{
-       int     c, fd;
-       int     apm_sleep = 0, all_info = 1, apm_status = 0, batt_status = 0;
-       int     display = -1, batt_life = 0, ac_status = 0, standby = 0;
-       int     batt_time = 0, delta = 0, enable = -1, haltcpu = -1;
-       const char      *cmdname;
-       int     bioscall_available = 0;
-       size_t  cmos_wall_len = sizeof(cmos_wall);
-
-       if (sysctlbyname("machdep.wall_cmos_clock", &cmos_wall, &cmos_wall_len,
-           NULL, 0) == -1)
-               err(1, "sysctlbyname(machdep.wall_cmos_clock)");
-       if ((cmdname = strrchr(argv[0], '/')) != NULL)
-               cmdname++;
-       else
-               cmdname = argv[0];
-
-       if (strcmp(cmdname, "zzz") == 0) {
-               apm_sleep = 1;
-               all_info = 0;
-               goto finish_option;
-       }
-       while ((c = getopt(argc, argv, "abe:h:lRr:stzd:Z")) != -1) {
-               switch (c) {
-               case 'a':
-                       ac_status = 1;
-                       all_info = 0;
-                       break;
-               case 'b':
-                       batt_status = 1;
-                       all_info = 0;
-                       break;
-               case 'd':
-                       display = is_true(optarg);
-                       all_info = 0;
-                       break;
-               case 'l':
-                       batt_life = 1;
-                       all_info = 0;
-                       break;
-               case 'R':
-                       delta = -1;
-                       break;
-               case 'r':
-                       delta = atoi(optarg);
-                       break;
-               case 's':
-                       apm_status = 1;
-                       all_info = 0;
-                       break;
-               case 'e':
-                       enable = is_true(optarg);
-                       all_info = 0;
-                       break;
-               case 'h':
-                       haltcpu = is_true(optarg);
-                       all_info = 0;
-                       break;
-               case 't':
-                       batt_time = 1;
-                       all_info = 0;
-                       break;
-               case 'z':
-                       apm_sleep = 1;
-                       all_info = 0;
-                       break;
-               case 'Z':
-                       standby = 1;
-                       all_info = 0;
-                       break;
-               default:
-                       usage();
-               }
-               argc -= optind;
-               argv += optind;
-       }
-finish_option:
-       if (haltcpu != -1 || enable != -1 || display != -1 || delta || apm_sleep || standby) {
-               fd = open(APMDEV, O_RDWR);
-               bioscall_available = 1;
-       } else if ((fd = open(APMDEV, O_RDWR)) >= 0)
-               bioscall_available = 1;
-       else
-               fd = open(APMDEV, O_RDONLY);
-       if (fd == -1)
-               err(1, "can't open %s", APMDEV);
-       if (enable != -1)
-               apm_enable(fd, enable);
-       if (haltcpu != -1)
-               apm_haltcpu(fd, haltcpu);
-       if (delta)
-               apm_set_timer(fd, delta);
-       if (apm_sleep)
-               apm_suspend(fd);
-       else if (standby)
-               apm_standby(fd);
-       else if (delta == 0) {
-               struct apm_info info;
-
-               apm_getinfo(fd, &info);
-               if (all_info)
-                       print_all_info(fd, &info, bioscall_available);
-               if (ac_status)
-                       printf("%d\n", info.ai_acline);
-               if (batt_status)
-                       printf("%d\n", info.ai_batt_stat);
-               if (batt_life)
-                       printf("%d\n", info.ai_batt_life);
-               if (apm_status)
-                       printf("%d\n", info.ai_status);
-               if (batt_time)
-                       printf("%d\n", info.ai_batt_time);
-               if (display != -1)
-                       apm_display(fd, display);
-       }
-       close(fd);
-       exit(EXIT_SUCCESS);
-}
diff --git a/usr.sbin/apmd/Makefile b/usr.sbin/apmd/Makefile
deleted file mode 100644 (file)
index 7af60d3..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# $FreeBSD: src/usr.sbin/apmd/Makefile,v 1.2.2.2 2001/04/25 12:09:18 ru Exp $
-# $DragonFly: src/usr.sbin/apmd/Makefile,v 1.4 2008/10/29 18:18:04 swildner Exp $
-
-PROG=  apmd
-SRCS=  apmd.c apmdlex.l apmdparse.y y.tab.h
-WARNS?=        3
-
-DPADD= ${LIBL} ${LIBUTIL}
-LDADD= -ll -lutil
-
-MAN=   apmd.8
-
-YFLAGS+=-v
-CFLAGS+=-I. -I${.CURDIR} #-DYY_STACK_USED
-# for debug:
-#CFLAGS+= -g -DDEBUG
-
-CLEANFILES= y.output
-
-test:
-       ./apmd -d -f etc/apmd.conf -n
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/apmd/README b/usr.sbin/apmd/README
deleted file mode 100644 (file)
index 7f8dde1..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-FreeBSD apmd Package Release Notes (19990711 version)
-
-1. What is "apmd"?
-==================
-
-The apmd package provides a means of handling various APM events from
-userland code.  Using apmd.conf, the apmd(8) configuration file, you
-can select the APM events to be handled from userland and specify the
-commands for a given event, allowing APM behaviour to be configured
-flexibly.
-
-
-2. How to install the apmd package
-==================================
-
-2.1 Making the apmd control device file
----------------------------------------
-
-apmd(8) uses the new special device file /dev/apmctl.  This should be
-created as follows:
-
-# cd /dev
-# mknod apmctl c 39 8
-
-2.2 Applying the kernel patch and building a new kernel
--------------------------------------------------------
-
-The next step is to apply the patch against the sys source tree.
-Go to the source directory (eg. /usr/src/ or /usr/PAO3/src/) and run
-the patch command as follows:
-
-# gzip -cd [somewhere]/apmd-sys-R320.diff | patch
-
-For PAO3 users, the patch file name would be apmd-sys-PAO3.diff
-instead of apmd-sys-R320.diff.  After this step has completed
-successfully, build and install a new kernel and reboot your system.
-
-2.3 Making the apmd program
----------------------------
-
-Go to src/usr.sbin/ and extract the apmd tarball as follows:
-
-# tar xzpvf [somewhere]/apmd-usr.sbin.tar.gz 
-
-Before doing a make all, you need to copy apm_bios.h in the sys source
-tree to /usr/include/machine/ first:
-
-# cp /sys/i386/include/apm_bios.h /usr/include/machine/
-
-Then do the build and install steps in the apmd directory:
-
-# cd src/usr.sbin/apmd
-# make depend all install
-
-2.4 Setting up the configuration file and userland script
----------------------------------------------------------
-
-In src/usr.sbin/apm/etc/ there are example configuration and userland
-script files which are invoked automatically when the APM BIOS informs
-apmd of an event, such as suspend request.  Copy these files to
-/etc/ as follows:
-
-# cp src/usr.sbin/apm/etc/* /etc/
-
-
-3. Running the apmd daemon program
-==================================
-
-To run apmd(8) in background mode, simply type ``apmd''.
-
-# apmd
-
-To make a running apmd reload /etc/apmd.conf, send a SIGHUP signal to
-the apmd(8) process.
-
-# kill -HUP [apmd pid]
-or
-# killall -HUP apmd
-
-apmd has some command line options.  For the details, please 
-refer to the manpage of apmd.
-
-4. Configuration file
-=====================
-
-The structure of the apmd configuration file is quite simple.  For
-example:
-
-apm_event SUSPENDREQ {
-       exec "sync && sync && sync";
-       exec "sleep 1";
-       exec "zzz";
-}
-
-Will cause apmd to recieve the APM event SUSPENDREQ (which may be
-posted by an LCD close), run the sync command 3 times and wait for a
-while, then execute zzz (apm -z) to put the system in the suspend
-state.
-
-4.1 The apm_event keyword
--------------------------
-`apm_event' is the keyword which indicates the start of configuration for
-each events.
-
-4.2 APM events
---------------
-
-If you wish to execute the same commands for different events, the
-event names should be delimited by a comma.  The following are valid
-event names:
-
-o Events ignored by the kernel if apmd is running:
-
-STANDBYREQ
-SUSPENDREQ
-USERSUSPENDREQ
-BATTERYLOW
-
-o Events passed to apmd after kernel handling:
-
-NORMRESUME
-CRITRESUME
-STANDBYRESUME
-POWERSTATECHANGE
-UPDATETIME
-
-
-Other events will not be sent to apmd.
-
-4.3 command line syntax
------------------------
-
-In the example above, the three lines begining with `exec' are commands 
-for the event.  Each line should be terminated with a semicolon.  The
-command list for the event should be enclosed by `{' and `}'. apmd(8)
-uses /bin/sh for double-quotation enclosed command execution, just as
-with system(3).  Each command is executed in order until the end of
-the list is reached or a command finishes with a non-zero status code. 
-apmd(8) will report any failed command's status code via syslog(3)
-and will then reject the request event posted by APM BIOS.
-
-4.4 Built-in functions
-----------------------
-
-You can also specify apmd built-in functions instead of command lines.
-A built-in function name should be terminated with a semicolon, just as
-with a command line.
-The following built-in functions are currently supported:
-
-o reject;
-
-  Reject last request posted by the APM BIOS.  This can be used to reject a
-  SUSPEND request when the LCD is closed and put the system in a STANDBY
-  state instead.
-
-
-
-5. EXAMPLES
-===========
-
-Sample configuration commands include:
-
-apm_event SUSPENDREQ {
-       exec "/etc/rc.suspend";
-}
-
-apm_event USERSUSPENDREQ {
-       exec "sync && sync && sync";
-       exec "sleep 1";
-       exec "apm -z";
-}
-
-apm_event NORMRESUME, STANDBYRESUME {
-       exec "/etc/rc.resume";
-}
-
-# resume event configuration for serial mouse users by
-# reinitializing a moused(8) connected to a serial port.
-#
-#apm_event NORMRESUME {
-#      exec "kill -HUP `cat /var/run/moused.pid`";
-#}
-
-# suspend request event configuration for ATA HDD users:
-# execute standby instead of suspend.
-#
-#apm_event SUSPENDREQ {
-#      reject;
-#      exec "sync && sync && sync";
-#      exec "sleep 1";
-#      exec "apm -Z";
-#}
-
-
-6. Call for developers
-======================
-
-The initial version of apmd(8) was implemented primarily to test the
-kernel support code and was ALPHA quality.  Based on that code, the
-current version was developed by KOIE Hidetaka <hide@koie.org>. 
-However, we're still looking around for interesting new features and
-ideas, so if you have any thoughts, please let us know. 
-Documentation is also sparse, and the manpage have just written.  
-If you wish to collaborate on this work, please e-mail me:
-iwasaki@freebsd.org.
-
-
-June 1, 1999
-Created by: iwasaki@FreeBSD.org
-Edited by: jkh@FreeBSD.org
-           nick@foobar.org
-
-$FreeBSD: src/usr.sbin/apmd/README,v 1.2 1999/08/28 01:15:24 peter Exp $
-$DragonFly: src/usr.sbin/apmd/README,v 1.2 2003/06/17 04:29:52 dillon Exp $
diff --git a/usr.sbin/apmd/apmd.8 b/usr.sbin/apmd/apmd.8
deleted file mode 100644 (file)
index a99662e..0000000
+++ /dev/null
@@ -1,300 +0,0 @@
-.\" Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
-.\" Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
-.\" Copyright (c) 1999 Yoshihiko SARUMARU <mistral@imasy.or.jp>
-.\" Copyright (c) 1999 Norihiro Kumagai <kuma@nk.rim.or.jp>
-.\" All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in the
-.\"    documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\"     @(#)apmd.8     1.1 (FreeBSD) 6/28/99
-.\" $FreeBSD: src/usr.sbin/apmd/apmd.8,v 1.7.2.7 2003/03/11 21:13:47 trhodes Exp $
-.\"
-.Dd June 28, 1999
-.Dt APMD 8
-.Os
-.Sh NAME
-.Nm apmd
-.Nd Advanced Power Management monitor daemon
-.Sh SYNOPSIS
-.Nm
-.Op Fl d
-.Op Fl f file
-.Op Fl v
-.Sh DESCRIPTION
-The
-.Nm
-utility
-monitors the occurrence of the specified Advanced Power Management
-.Pq Tn APM
-events and, if one of the events occurs, it executes the sequence of
-commands corresponding to the event.  Only the events specified in the
-configuration file are notified to
-.Nm ;
-all other events are ignored.  For each event posted by the APM BIOS,
-.Nm
-invokes the sequence of commands specified in the configuration file.
-When
-.Nm
-is running with monitoring suspend/standby requests,
-the kernel will not process those requests.
-Therefore, if you wish action to be taken when these events
-occur, you need to explicitly configure the appropriate commands or
-built-in functions in the configuration file.
-.Pp
-The
-.Nm
-utility recognizes the following runtime options:
-.Bl -tag -width ".Fl f Ar file"
-.It Fl d
-Starts in debug mode.  This causes
-.Nm
-to execute in the foreground instead of in daemon mode.
-.It Fl f Ar file
-Specifies a different configuration file
-.Ar file
-to be used in place of the default
-.Pa /etc/apmd.conf .
-.It Fl v
-Verbose mode.
-.El
-.Pp
-When
-.Nm
-starts, it reads the configuration file
-.Pa ( /etc/apmd.conf
-as default)
-and notifies the set of events to be monitored to the APM device driver.
-When it terminates, the APM device driver automatically cancels
-monitored events.
-.Pp
-If the
-.Nm
-process receives a
-.Dv SIGHUP ,
-it will reread its configuration file and
-notify the APM device driver of any changes to its configuration.
-.Pp
-The
-.Nm
-utility uses the device
-.Pa /dev/apmctl
-to issue
-.Xr ioctl 2
-requests for monitoring events and for controlling the APM system.
-This device file is opened exclusively, so only a single
-.Nm
-process can be running at any time.
-.Pp
-When
-.Nm
-receives an APM event, it forks a child process to execute the
-commands specified in the configuration file and then continues
-listening for more events.  The child process executes the commands
-specified, one at a time and in the order that they are listed.
-.Pp
-While
-.Nm
-is processing the command list for SUSPEND/STANDBY requests, the APM kernel
-device driver issues notifications to APM BIOS once per second so that the
-BIOS knows that there are still some commands pending, and that it should not
-complete the request just yet.
-.Pp
-The
-.Nm
-utility creates the file
-.Pa /var/run/apmd.pid ,
-and stores its process
-id there.
-This can be used to kill or reconfigure
-.Nm .
-.Sh CONFIGURATION FILE
-The structure of the
-.Nm
-configuration file is quite simple.  For example:
-.Bd -literal
-apm_event SUSPENDREQ {
-       exec "sync && sync && sync";
-       exec "sleep 1";
-       exec "zzz";
-}
-.Ed
-.Pp
-will cause
-.Nm
-to receive the APM event
-.Ql SUSPENDREQ
-(which may be posted by an LCD close), run the
-.Ql sync
-command 3 times and wait for a while, then execute
-.Nm zzz ( Ns Nm apm Fl z )
-to put the system in the suspend state.
-.Bl -bullet
-.It
-The  apm_event keyword
-.Bd -ragged -offset indent
-.Ql apm_event
-is the keyword which indicates the start of configuration for
-each event.
-.Ed
-.It
-APM events
-.Bd -ragged -offset indent
-If you wish to execute the same commands for different events, the
-event names should be delimited by a comma.  The following are
-valid event names:
-.Bl -item
-.It
-- Events ignored by the kernel if
-.Nm
-is running:
-.Pp
-.Bl -tag -width USERSUSPENDREQ -compact -offset indent
-.It STANDBYREQ
-.It USERSTANDBYREQ
-.It SUSPENDREQ
-should include sync in the command list,
-.It USERSUSPENDREQ
-should include sync in the command list,
-.It BATTERYLOW
-only zzz should be specified in the command list.
-.El
-.It
-- Events passed to
-.Nm
-after kernel handling:
-.Pp
-.Bl -tag -width USERSUSPENDREQ -compact -offset indent
-.It NORMRESUME
-.It CRITRESUME
-.It STANDBYRESUME
-.It POWERSTATECHANGE
-.It UPDATETIME
-.It CAPABILITIESCHANGE
-.El
-.Pp
-Other events will not be sent to
-.Nm .
-.El
-.Ed
-.It
-command line syntax
-.Bd -ragged -offset indent
-In the example above, the three lines beginning with
-.Ql exec
-are commands for the event.
-Each line should be terminated with a semicolon.
-The command list for the event should be enclosed by
-.Ql {
-and
-.Ql } .
-The
-.Nm
-utility uses
-.Pa /bin/sh
-for double-quotation enclosed command execution, just as with
-.Xr system 3 .
-Each command is executed in order until the end of
-the list is reached or a command finishes with a non-zero status code.
-The
-.Nm
-utility will report any failed command's status code via
-.Xr syslog 3
-and will then reject the request event posted by the APM BIOS.
-.Ed
-.It
-Built-in functions
-.Bd -ragged -offset indent
-You can also specify
-.Nm
-built-in functions instead of command lines.
-A built-in function name should be terminated with a semicolon,
-just as with a command line.
-The following built-in functions are currently supported:
-.Bl -tag -width "- reject:"
-.It - reject:
-Reject last request posted by APM BIOS.  This can be used to reject
-a SUSPEND request when the LCD is closed and put the system in a
-STANDBY state instead.
-.El
-.Ed
-.El
-.Sh FILES
-.Bl -tag -width /etc/apmd.conf -compact
-.It Pa /etc/apmd.conf
-.It Pa /dev/apmctl
-.It Pa /var/run/apmd.pid
-.El
-.Sh EXAMPLES
-Sample configuration commands include:
-.Bd -literal
-apm_event SUSPENDREQ {
-        exec "/etc/rc.suspend";
-}
-
-apm_event USERSUSPENDREQ {
-        exec "sync && sync && sync";
-        exec "sleep 1";
-        exec "apm -z";
-}
-
-apm_event NORMRESUME, STANDBYRESUME {
-        exec "/etc/rc.resume";
-}
-
-# resume event configuration for serial mouse users by
-# reinitializing a moused(8) connected to a serial port.
-#
-#apm_event NORMRESUME {
-#       exec "kill -HUP `cat /var/run/moused.pid`";
-#}
-#
-# suspend request event configuration for ATA HDD users:
-# execute standby instead of suspend.
-#
-#apm_event SUSPENDREQ {
-#       reject;
-#       exec "sync && sync && sync";
-#       exec "sleep 1";
-#       exec "apm -Z";
-#}
-.Ed
-.Sh SEE ALSO
-.Xr apm 4 ,
-.Xr apm 8
-.Sh HISTORY
-The
-.Nm
-utility appeared in
-.Fx 3.3 .
-.Sh AUTHORS
-.An Mitsuru IWASAKI Aq Mt iwasaki@FreeBSD.org
-.An KOIE Hidetaka Aq Mt koie@suri.co.jp
-.Pp
-.An -nosplit
-Some contributions made by
-.An Warner Losh Aq Mt imp@FreeBSD.org ,
-.An Hiroshi Yamashita Aq Mt bluemoon@msj.biglobe.ne.jp ,
-.An Yoshihiko SARUMARU Aq Mt mistral@imasy.or.jp ,
-.An Norihiro Kumagai Aq Mt kuma@nk.rim.or.jp ,
-.An NAKAGAWA Yoshihisa Aq Mt nakagawa@jp.FreeBSD.org ,
-and
-.An Nick Hilliard Aq Mt nick@foobar.org .
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c
deleted file mode 100644 (file)
index 4af0a5b..0000000
+++ /dev/null
@@ -1,680 +0,0 @@
-/*-
- * APM (Advanced Power Management) Event Dispatcher
- *
- * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
- * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/apmd/apmd.c,v 1.3.2.1 2001/08/13 17:30:30 nsayer Exp $
- * $DragonFly: src/usr.sbin/apmd/apmd.c,v 1.7 2008/07/10 18:29:52 swildner Exp $
- */
-
-#include <assert.h>
-#include <bitstring.h>
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <libutil.h>
-#include <paths.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <machine/apm_bios.h>
-
-#include "apmd.h"
-
-
-int            debug_level = 0;
-int            verbose = 0;
-const char     *apmd_configfile = APMD_CONFIGFILE;
-int             apmctl_fd = -1, apmnorm_fd = -1;
-
-/*
- * table of event handlers
- */
-#define EVENT_CONFIG_INITIALIZER(EV,R) { #EV, NULL, R },
-struct event_config events[EVENT_MAX] = {
-       EVENT_CONFIG_INITIALIZER(NOEVENT, 0)
-       EVENT_CONFIG_INITIALIZER(STANDBYREQ, 1)
-       EVENT_CONFIG_INITIALIZER(SUSPENDREQ, 1)
-       EVENT_CONFIG_INITIALIZER(NORMRESUME, 0)
-       EVENT_CONFIG_INITIALIZER(CRITRESUME, 0)
-       EVENT_CONFIG_INITIALIZER(BATTERYLOW, 0)
-       EVENT_CONFIG_INITIALIZER(POWERSTATECHANGE, 0)
-       EVENT_CONFIG_INITIALIZER(UPDATETIME, 0)
-       EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1)
-       EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1)
-       EVENT_CONFIG_INITIALIZER(USERSUSPENDREQ, 1)
-       EVENT_CONFIG_INITIALIZER(STANDBYRESUME, 0)
-       EVENT_CONFIG_INITIALIZER(CAPABILITIESCHANGE, 0)
-};
-
-/*
- * List of battery events
- */
-struct battery_watch_event *battery_watch_list = NULL;
-
-#define BATT_CHK_INTV 10 /* how many seconds between battery state checks? */
-
-/*
- * default procedure
- */
-struct event_cmd *
-event_cmd_default_clone(void *this)
-{
-       struct event_cmd * oldone = this;
-       struct event_cmd * newone = malloc(oldone->len);
-
-       newone->next = NULL;
-       newone->len = oldone->len;
-       newone->name = oldone->name;
-       newone->op = oldone->op;
-       return newone;
-}
-
-/*
- * exec command
- */
-int
-event_cmd_exec_act(void *this)
-{
-       struct event_cmd_exec * p = this;
-       int status = -1;
-       pid_t pid;
-
-       switch ((pid = fork())) {
-       case -1:
-               warn("cannot fork");
-               goto out;
-       case 0:
-               /* child process */
-               execl(_PATH_BSHELL, "sh", "-c", p->line, NULL);
-               _exit(127);
-       default:
-               /* parent process */
-               do {
-                       pid = waitpid(pid, &status, 0);
-               } while (pid == -1 && errno == EINTR);
-               break;
-       }
- out:
-       return status;
-}
-void
-event_cmd_exec_dump(void *this, FILE *fp)
-{
-       fprintf(fp, " \"%s\"", ((struct event_cmd_exec *)this)->line);
-}
-struct event_cmd *
-event_cmd_exec_clone(void *this)
-{
-       struct event_cmd_exec * newone = (struct event_cmd_exec *) event_cmd_default_clone(this);
-       struct event_cmd_exec * oldone = this;
-
-       newone->evcmd.next = NULL;
-       newone->evcmd.len = oldone->evcmd.len;
-       newone->evcmd.name = oldone->evcmd.name;
-       newone->evcmd.op = oldone->evcmd.op;
-       if ((newone->line = strdup(oldone->line)) == NULL)
-               err(1, "out of memory");
-       return (struct event_cmd *) newone;
-}
-void
-event_cmd_exec_free(void *this)
-{
-       free(((struct event_cmd_exec *)this)->line);
-}
-struct event_cmd_op event_cmd_exec_ops = {
-       event_cmd_exec_act,
-       event_cmd_exec_dump,
-       event_cmd_exec_clone,
-       event_cmd_exec_free
-};
-
-/*
- * reject commad
- */
-int
-event_cmd_reject_act(void *this)
-{
-       int rc = -1;
-
-       if (ioctl(apmctl_fd, APMIO_REJECTLASTREQ, NULL)) {
-               syslog(LOG_NOTICE, "fail to reject\n");
-               goto out;
-       }
-       rc = 0;
- out:
-       return rc;
-}
-struct event_cmd_op event_cmd_reject_ops = {
-       event_cmd_reject_act,
-       NULL,
-       event_cmd_default_clone,
-       NULL
-};
-
-/*
- * manipulate event_config
- */
-struct event_cmd *
-clone_event_cmd_list(struct event_cmd *p)
-{
-       struct event_cmd dummy;
-       struct event_cmd *q = &dummy;
-       for ( ;p; p = p->next) {
-               assert(p->op->clone);
-               if ((q->next = p->op->clone(p)) == NULL)
-                       err(1, "out of memory");
-               q = q->next;
-       }
-       q->next = NULL;
-       return dummy.next;
-}
-void
-free_event_cmd_list(struct event_cmd *p)
-{
-       struct event_cmd * q;
-       for ( ; p ; p = q) {
-               q = p->next;
-               if (p->op->free)
-                       p->op->free(p);
-               free(p);
-       }
-}
-int
-register_battery_handlers(
-       int level, int direction,
-       struct event_cmd *cmdlist)
-{
-       /*
-        * level is negative if it's in "minutes", non-negative if
-        * percentage.
-        *
-        * direction =1 means we care about this level when charging,
-        * direction =-1 means we care about it when discharging.
-        */
-       if (level>100) /* percentage > 100 */
-               return -1;
-       if (abs(direction) != 1) /* nonsense direction value */
-               return -1;
-
-       if (cmdlist) {
-               struct battery_watch_event *we;
-               
-               if ((we = malloc(sizeof(struct battery_watch_event))) == NULL)
-                       err(1, "out of memory");
-
-               we->next = battery_watch_list; /* starts at NULL */
-               battery_watch_list = we;
-               we->level = abs(level);
-               we->type = (level<0)?BATTERY_MINUTES:BATTERY_PERCENT;
-               we->direction = (direction<0)?BATTERY_DISCHARGING:
-                       BATTERY_CHARGING;
-               we->done = 0;
-               we->cmdlist = clone_event_cmd_list(cmdlist);
-       }
-       return 0;
-}
-int
-register_apm_event_handlers(
-       bitstr_t bit_decl(evlist, EVENT_MAX),
-       struct event_cmd *cmdlist)
-{
-       if (cmdlist) {
-               bitstr_t bit_decl(tmp, EVENT_MAX);
-               memcpy(&tmp, evlist, bitstr_size(EVENT_MAX));
-
-               for (;;) {
-                       int n;
-                       struct event_cmd *p;
-                       struct event_cmd *q;
-                       bit_ffs(tmp, EVENT_MAX, &n);
-                       if (n < 0)
-                               break;
-                       p = events[n].cmdlist;
-                       if ((q = clone_event_cmd_list(cmdlist)) == NULL)
-                               err(1, "out of memory");
-                       if (p) {
-                               while (p->next != NULL)
-                                       p = p->next;
-                               p->next = q;
-                       } else {
-                               events[n].cmdlist = q;
-                       }
-                       bit_clear(tmp, n);
-               }
-       }
-       return 0;
-}
-
-/*
- * execute command
- */
-int
-exec_run_cmd(struct event_cmd *p)
-{
-       int status = 0;
-
-       for (; p; p = p->next) {
-               assert(p->op->act);
-               if (verbose)
-                       syslog(LOG_INFO, "action: %s", p->name);
-               status = p->op->act(p);
-               if (status) {
-                       syslog(LOG_NOTICE, "command finished with %d\n", status);
-                       break;
-               }
-       }
-       return status;
-}
-
-/*
- * execute command -- the event version
- */
-int
-exec_event_cmd(struct event_config *ev)
-{
-       int status = 0;
-
-       status = exec_run_cmd(ev->cmdlist);
-       if (status && ev->rejectable) {
-               syslog(LOG_ERR, "canceled");
-               event_cmd_reject_act(NULL);
-       }
-       return status;
-}
-
-/*
- * read config file
- */
-extern FILE * yyin;
-extern int yydebug;
-
-void
-read_config(void)
-{
-       int i;
-
-       if ((yyin = fopen(apmd_configfile, "r")) == NULL) {
-               err(1, "cannot open config file");
-       }
-
-#ifdef DEBUG
-       yydebug = debug_level;
-#endif
-
-       if (yyparse() != 0)
-               err(1, "cannot parse config file");
-
-       fclose(yyin);
-
-       /* enable events */
-       for (i = 0; i < EVENT_MAX; i++) {
-               if (events[i].cmdlist) {
-                       u_int event_type = i;
-                       if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) {
-                               err(1, "cannot enable event 0x%x", event_type);
-                       }
-               }
-       }
-}
-
-void
-dump_config(void)
-{
-       int i;
-       struct battery_watch_event *q;
-
-       for (i = 0; i < EVENT_MAX; i++) {
-               struct event_cmd * p;
-               if ((p = events[i].cmdlist)) {
-                       fprintf(stderr, "apm_event %s {\n", events[i].name);
-                       for ( ; p ; p = p->next) {
-                               fprintf(stderr, "\t%s", p->name);
-                               if (p->op->dump)
-                                       p->op->dump(p, stderr);
-                               fprintf(stderr, ";\n");
-                       }
-                       fprintf(stderr, "}\n");
-               }
-       }
-       for (q = battery_watch_list ; q != NULL ; q = q -> next) {
-               struct event_cmd * p;
-               fprintf(stderr, "apm_battery %d%s %s {\n",
-                       q -> level,
-                       (q -> type == BATTERY_PERCENT)?"%":"m",
-                       (q -> direction == BATTERY_CHARGING)?"charging":
-                               "discharging");
-               for ( p = q -> cmdlist; p ; p = p->next) {
-                       fprintf(stderr, "\t%s", p->name);
-                       if (p->op->dump)
-                               p->op->dump(p, stderr);
-                       fprintf(stderr, ";\n");
-               }
-               fprintf(stderr, "}\n");
-       }
-}
-
-void
-destroy_config(void)
-{
-       int i;
-       struct battery_watch_event *q;
-
-       /* disable events */
-       for (i = 0; i < EVENT_MAX; i++) {
-               if (events[i].cmdlist) {
-                       u_int event_type = i;
-                       if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) {
-                               err(1, "cannot disable event 0x%x", event_type);
-                       }
-               }
-       }
-
-       for (i = 0; i < EVENT_MAX; i++) {
-               struct event_cmd * p;
-               if ((p = events[i].cmdlist))
-                       free_event_cmd_list(p);
-               events[i].cmdlist = NULL;
-       }
-
-       for( ; battery_watch_list; battery_watch_list = battery_watch_list -> next) {
-               free_event_cmd_list(battery_watch_list->cmdlist);
-               q = battery_watch_list->next;
-               free(battery_watch_list);
-               battery_watch_list = q;
-       }
-}
-
-void
-restart(void)
-{
-       destroy_config();
-       read_config();
-       if (verbose)
-               dump_config();
-}
-
-/*
- * handle signals
- */
-static int signal_fd[2];
-
-void
-enque_signal(int sig)
-{
-       if (write(signal_fd[1], &sig, sizeof sig) != sizeof sig)
-               err(1, "cannot process signal.");
-}
-
-void
-wait_child(void)
-{
-       int status;
-       while (waitpid(-1, &status, WNOHANG) > 0)
-               ;
-}
-
-int
-proc_signal(int fd)
-{
-       int rc = -1;
-       int sig;
-
-       while (read(fd, &sig, sizeof sig) == sizeof sig) {
-               syslog(LOG_INFO, "caught signal: %d", sig);
-               switch (sig) {
-               case SIGHUP:
-                       syslog(LOG_NOTICE, "restart by SIG");
-                       restart();
-                       break;
-               case SIGTERM:
-                       syslog(LOG_NOTICE, "going down on signal %d", sig);
-                       rc = 1;
-                       goto out;
-               case SIGCHLD:
-                       wait_child();
-                       break;
-               default:
-                       warn("unexpected signal(%d) received.", sig);
-                       break;
-               }
-       }
-       rc = 0;
- out:
-       return rc;
-}
-void
-proc_apmevent(int fd)
-{
-       struct apm_event_info apmevent;
-
-       while (ioctl(fd, APMIO_NEXTEVENT, &apmevent) == 0) {
-               int status;
-               syslog(LOG_NOTICE, "apmevent %04x index %d\n",
-                       apmevent.type, apmevent.index);
-               syslog(LOG_INFO, "apm event: %s", events[apmevent.type].name);
-               if (fork() == 0) {
-                       status = exec_event_cmd(&events[apmevent.type]);
-                       exit(status);
-               }
-       }
-}
-
-#define AC_POWER_STATE ((pw_info.ai_acline == 1) ? BATTERY_CHARGING :\
-       BATTERY_DISCHARGING)
-
-void
-check_battery(void)
-{
-
-       static int first_time=1, last_state;
-
-       struct apm_info pw_info;
-       struct battery_watch_event *p;
-
-       /* If we don't care, don't bother */
-       if (battery_watch_list == NULL)
-               return;
-
-       if (first_time) {
-               if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0)
-                       err(1, "cannot check battery state.");
-/*
- * This next statement isn't entirely true. The spec does not tie AC
- * line state to battery charging or not, but this is a bit lazier to do.
- */
-               last_state = AC_POWER_STATE;
-               first_time = 0;
-               return; /* We can't process events, we have no baseline */
-       }
-
-       /*
-        * XXX - should we do this a bunch of times and perform some sort
-        * of smoothing or correction?
-        */
-       if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0)
-               err(1, "cannot check battery state.");
-
-       /*
-        * If we're not in the state now that we were in last time,
-        * then it's a transition, which means we must clean out
-        * the event-caught state.
-        */
-       if (last_state != AC_POWER_STATE) {
-               last_state = AC_POWER_STATE;
-               for (p = battery_watch_list ; p!=NULL ; p = p -> next)
-                       p->done = 0;
-       }
-       for (p = battery_watch_list ; p != NULL ; p = p -> next)
-               if (p -> direction == AC_POWER_STATE &&
-                       !(p -> done) &&
-                       ((p -> type == BATTERY_PERCENT && 
-                               p -> level == (int)pw_info.ai_batt_life) ||
-                       (p -> type == BATTERY_MINUTES &&
-                               p -> level == (pw_info.ai_batt_time / 60)))) {
-                       p -> done++;
-                       if (verbose)
-                               syslog(LOG_NOTICE, "Caught battery event: %s, %d%s",
-                                       (p -> direction == BATTERY_CHARGING)?"charging":"discharging",
-                                       p -> level,
-                                       (p -> type == BATTERY_PERCENT)?"%":" minutes");
-                       if (fork() == 0) {
-                               int status;
-                               status = exec_run_cmd(p -> cmdlist);
-                               exit(status);
-                       }
-               }
-}
-void
-event_loop(void)
-{
-       int             fdmax = 0;
-       struct sigaction nsa;
-       fd_set          master_rfds;
-       sigset_t        sigmask, osigmask;
-
-       FD_ZERO(&master_rfds);
-       FD_SET(apmctl_fd, &master_rfds);
-       fdmax = apmctl_fd > fdmax ? apmctl_fd : fdmax;
-
-       FD_SET(signal_fd[0], &master_rfds);
-       fdmax = signal_fd[0] > fdmax ? signal_fd[0] : fdmax;
-
-       memset(&nsa, 0, sizeof nsa);
-       nsa.sa_handler = enque_signal;
-       sigfillset(&nsa.sa_mask);
-       nsa.sa_flags = SA_RESTART;
-       sigaction(SIGHUP, &nsa, NULL);
-       sigaction(SIGCHLD, &nsa, NULL);
-       sigaction(SIGTERM, &nsa, NULL);
-
-       sigemptyset(&sigmask);
-       sigaddset(&sigmask, SIGHUP);
-       sigaddset(&sigmask, SIGCHLD);
-       sigaddset(&sigmask, SIGTERM);
-       sigprocmask(SIG_SETMASK, &sigmask, &osigmask);
-
-       while (1) {
-               fd_set rfds;
-               int res;
-               struct timeval to;
-
-               to.tv_sec = BATT_CHK_INTV;
-               to.tv_usec = 0;
-
-               memcpy(&rfds, &master_rfds, sizeof rfds);
-               sigprocmask(SIG_SETMASK, &osigmask, NULL);
-               if ((res=select(fdmax + 1, &rfds, 0, 0, &to)) < 0) {
-                       if (errno != EINTR)
-                               err(1, "select");
-               }
-               sigprocmask(SIG_SETMASK, &sigmask, NULL);
-
-               if (res == 0) { /* time to check the battery */
-                       check_battery();
-                       continue;
-               }
-
-               if (FD_ISSET(signal_fd[0], &rfds)) {
-                       if (proc_signal(signal_fd[0]) < 0)
-                               goto out;
-               }
-
-               if (FD_ISSET(apmctl_fd, &rfds))
-                       proc_apmevent(apmctl_fd);
-       }
-out:
-       return;
-}
-
-int
-main(int ac, char* av[])
-{
-       int     ch;
-       int     daemonize = 1;
-       char    *prog;
-       int     logopt = LOG_NDELAY | LOG_PID;
-       struct pidfh *pfh = NULL;
-
-       while ((ch = getopt(ac, av, "df:v")) != -1) {
-               switch (ch) {
-               case 'd':
-                       daemonize = 0;
-                       debug_level++;
-                       break;
-               case 'f':
-                       apmd_configfile = optarg;
-                       break;
-               case 'v':
-                       verbose = 1;
-                       break;
-               default:
-                       err(1, "unknown option `%c'", ch);
-               }
-       }
-
-       pfh = pidfile_open(NULL, 600, NULL);
-       if (daemonize)
-               daemon(0, 0);
-
-#ifdef NICE_INCR
-       nice(NICE_INCR);
-#endif
-
-       if (!daemonize)
-               logopt |= LOG_PERROR;
-
-       prog = strrchr(av[0], '/');
-       openlog(prog ? prog+1 : av[0], logopt, LOG_DAEMON);
-
-       syslog(LOG_NOTICE, "start");
-
-       if (pipe(signal_fd) < 0)
-               err(1, "pipe");
-       if (fcntl(signal_fd[0], F_SETFL, O_NONBLOCK) < 0)
-               err(1, "fcntl");
-
-       if ((apmnorm_fd = open(APM_NORM_DEVICEFILE, O_RDWR)) == -1) {
-               err(1, "cannot open device file `%s'", APM_NORM_DEVICEFILE);
-       }
-
-       if ((apmctl_fd = open(APM_CTL_DEVICEFILE, O_RDWR)) == -1) {
-               err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE);
-       }
-
-       restart();
-       pidfile_write(pfh);
-       event_loop();
-       exit(EXIT_SUCCESS);
-}
-
diff --git a/usr.sbin/apmd/apmd.h b/usr.sbin/apmd/apmd.h
deleted file mode 100644 (file)
index d3fd119..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*-
- * APM (Advanced Power Management) Event Dispatcher
- *
- * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
- * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/apmd/apmd.h,v 1.2.2.1 2001/08/13 17:30:30 nsayer Exp $
- * $DragonFly: src/usr.sbin/apmd/apmd.h,v 1.5 2005/08/28 20:55:07 liamfoy Exp $
- */
-
-#define APMD_CONFIGFILE                "/etc/apmd.conf"
-#define APM_CTL_DEVICEFILE     "/dev/apmctl"
-#define APM_NORM_DEVICEFILE    "/dev/apm"
-#define NICE_INCR              -20
-
-enum {
-       EVENT_NOEVENT,
-       EVENT_STANDBYREQ,
-       EVENT_SUSPENDREQ,
-       EVENT_NORMRESUME,
-       EVENT_CRITRESUME,
-       EVENT_BATTERYLOW,
-       EVENT_POWERSTATECHANGE,
-       EVENT_UPDATETIME,
-       EVENT_CRITSUSPEND,
-       EVENT_USERSTANDBYREQ,
-       EVENT_USERSUSPENDREQ,
-       EVENT_STANDBYRESUME,
-       EVENT_CAPABILITIESCHANGE,
-       EVENT_MAX
-};
-
-struct event_cmd_op {
-       int (* act)(void *this);
-       void (* dump)(void *this, FILE * fp);
-       struct event_cmd * (* clone)(void *this);
-       void (* free)(void *this);
-};
-struct event_cmd {
-       struct event_cmd * next;
-       size_t len;
-       char * name;
-       struct event_cmd_op * op;
-};
-struct event_cmd_exec {
-       struct event_cmd evcmd;
-       char * line;            /* Command line */
-};
-struct event_cmd_reject {
-       struct event_cmd evcmd;
-};
-
-struct event_config {
-       const char *name;
-       struct event_cmd * cmdlist;
-       int rejectable;
-};
-
-struct battery_watch_event {
-       struct battery_watch_event *next;
-       int level;
-       enum {
-               BATTERY_CHARGING,
-               BATTERY_DISCHARGING
-       } direction;
-       enum {
-               BATTERY_MINUTES,
-               BATTERY_PERCENT
-       } type;
-       int done;
-       struct event_cmd *cmdlist;
-};
-
-       
-extern struct event_cmd_op event_cmd_exec_ops;
-extern struct event_cmd_op event_cmd_reject_ops;
-extern struct event_config events[EVENT_MAX];
-extern struct battery_watch_event *battery_watch_list;
-
-extern int register_battery_handlers(
-       int level, int direction,
-       struct event_cmd *cmdlist);
-extern int register_apm_event_handlers(
-       bitstr_t bit_decl(evlist, EVENT_MAX),
-       struct event_cmd *cmdlist);
-extern void free_event_cmd_list(struct event_cmd *p);
-
-extern int     yyparse(void);
-
-void   yyerror(const char *);
-int    yylex(void);
-
-struct event_cmd *event_cmd_default_clone(void *);
-int event_cmd_exec_act(void *);
-void event_cmd_exec_dump(void *, FILE *);
-struct event_cmd *event_cmd_exec_clone(void *);
-void event_cmd_exec_free(void *);
-int event_cmd_reject_act(void *);
-struct event_cmd *clone_event_cmd_list(struct event_cmd *);
-int exec_run_cmd(struct event_cmd *);
-int exec_event_cmd(struct event_config *);
-void read_config(void);
-void dump_config(void);
-void destroy_config(void);
-void restart(void);
-void enque_signal(int);
-void wait_child(void);
-int proc_signal(int);
-void proc_apmevent(int);
-void check_battery(void);
-void event_loop(void);
diff --git a/usr.sbin/apmd/apmdlex.l b/usr.sbin/apmd/apmdlex.l
deleted file mode 100644 (file)
index 9555827..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-%{
-/*-
- * APM (Advanced Power Management) Event Dispatcher
- *
- * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
- * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/apmd/apmdlex.l,v 1.2.2.1 2001/08/13 17:30:30 nsayer Exp $
- */
-
-#include <string.h>
-#include <syslog.h>
-#include <bitstring.h>
-#include "apmd.h"
-#include "y.tab.h"
-
-int lineno;
-int first_time;
-%}
-
-%option noinput
-%option nounput
-
-%s TOP
-
-%%
-
-%{
-       if (first_time) {
-               BEGIN TOP;
-               lineno = 1;
-               first_time = 0;
-       }
-%}
-
-<TOP>[ \t]+            ;
-<TOP>\n                        lineno++;
-<TOP>,                 { return COMMA; }
-<TOP>;                 { return SEMICOLON; }
-<TOP>#.*$              ;
-
-<TOP>apm_event         { return APMEVENT; }
-
-<TOP>NOEVENT           { yylval.ev = EVENT_NOEVENT; return EVENT; }
-<TOP>STANDBYREQ                { yylval.ev = EVENT_STANDBYREQ; return EVENT; }
-<TOP>SUSPENDREQ                { yylval.ev = EVENT_SUSPENDREQ; return EVENT; }
-<TOP>NORMRESUME                { yylval.ev = EVENT_NORMRESUME; return EVENT; }
-<TOP>CRITRESUME                { yylval.ev = EVENT_CRITRESUME; return EVENT; }
-<TOP>BATTERYLOW                { yylval.ev = EVENT_BATTERYLOW; return EVENT; }
-<TOP>POWERSTATECHANGE  { yylval.ev = EVENT_POWERSTATECHANGE; return EVENT; }
-<TOP>UPDATETIME                { yylval.ev = EVENT_UPDATETIME; return EVENT; }
-<TOP>CRITSUSPEND       { yylval.ev = EVENT_CRITSUSPEND; return EVENT; }
-<TOP>USERSTANDBYREQ    { yylval.ev = EVENT_USERSTANDBYREQ; return EVENT; }
-<TOP>USERSUSPENDREQ    { yylval.ev = EVENT_USERSUSPENDREQ; return EVENT; }
-<TOP>STANDBYRESUME     { yylval.ev = EVENT_STANDBYRESUME; return EVENT; }
-<TOP>CAPABILITIESCHANGE        { yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; }
-
-<TOP>apm_battery       { return APMBATT; }
-
-<TOP>charging          { return BATTCHARGE; }
-<TOP>discharging       { return BATTDISCHARGE; }
-<TOP>[0-9]+%           {
-                               yylval.i = atoi(yytext);
-                               return BATTPERCENT;
-                       }
-<TOP>[0-9]+[Mm]                {
-                               yylval.i = -atoi(yytext);
-                               return BATTTIME;
-                       }
-
-<TOP>exec              { return EXECCMD; }
-<TOP>reject            { return REJECTCMD; }
-
-<TOP>\{                        { return BEGINBLOCK; }
-<TOP>\}                        { return ENDBLOCK; }
-<TOP>\"[^"]+\" {
-                               int len = strlen(yytext) - 2;
-                               if ((yylval.str = (char *) malloc(len + 1)) == NULL)
-                                       goto out;
-                               memcpy(yylval.str, yytext + 1, len);
-                               yylval.str[len] = '\0';
-                       out:
-                               return STRING;
-                       }
-
-<TOP>[^"{},;#\n\t ]+   { yylval.str = strdup(yytext); return UNKNOWN; }
-%%
-
-void
-yyerror(const char *s)
-{
-       syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s);
-}
diff --git a/usr.sbin/apmd/apmdparse.y b/usr.sbin/apmd/apmdparse.y
deleted file mode 100644 (file)
index 1c1d508..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-%{
-/*-
- * APM (Advanced Power Management) Event Dispatcher
- *
- * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
- * Copyright (c) 1999 KOIE Hidetaka <koie@suri.co.jp>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/usr.sbin/apmd/apmdparse.y,v 1.2.2.1 2001/08/13 17:30:30 nsayer Exp $
- * $DragonFly: src/usr.sbin/apmd/apmdparse.y,v 1.3 2007/11/25 01:28:23 swildner Exp $
- */
-
-#include <stdio.h>
-#include <bitstring.h>
-#include <stdlib.h>
-#include <string.h>
-#include "apmd.h"
-
-#ifdef DEBUG
-#define YYDEBUG 1
-#endif
-
-extern int first_time;
-
-%}
-
-%union {
-       char *str;
-       bitstr_t bit_decl(evlist, EVENT_MAX);
-       int ev;
-       struct event_cmd * evcmd;
-       int i;
-}
-
-%token BEGINBLOCK ENDBLOCK
-%token COMMA SEMICOLON
-%token APMEVENT
-%token APMBATT
-%token BATTCHARGE BATTDISCHARGE
-%token <i> BATTTIME BATTPERCENT
-%token EXECCMD REJECTCMD
-%token <ev> EVENT
-%token <str> STRING UNKNOWN
-
-%type <i> apm_battery_level
-%type <i> apm_battery_direction
-%type <str> string
-%type <str> unknown
-%type <evlist> event_list
-%type <evcmd> cmd_list
-%type <evcmd> cmd
-%type <evcmd> exec_cmd reject_cmd
-
-%%
-
-config_file
-       : { first_time = 1; } config_list
-       ;
-
-config_list
-       : config
-       | config_list config
-       ;
-
-config
-       : apm_event_statement
-       | apm_battery_statement
-       ;
-
-apm_event_statement
-       : APMEVENT event_list BEGINBLOCK cmd_list ENDBLOCK
-               {
-                       if (register_apm_event_handlers($2, $4) < 0)
-                               abort(); /* XXX */
-                       free_event_cmd_list($4);
-               }
-       ;
-
-apm_battery_level
-       : BATTPERCENT
-               {
-                       $$ = $1;
-               }
-       | BATTTIME
-               {
-                       $$ = $1;
-               }
-       ;
-
-apm_battery_direction
-       : BATTCHARGE
-               {
-                       $$ = 1;
-               }
-       | BATTDISCHARGE
-               {
-                       $$ = -1;
-               }
-       ;
-apm_battery_statement
-       : APMBATT apm_battery_level apm_battery_direction
-               BEGINBLOCK cmd_list ENDBLOCK
-               {
-                       if (register_battery_handlers($2, $3, $5) < 0)
-                               abort(); /* XXX */
-                       free_event_cmd_list($5);
-               }
-       ;
-
-event_list
-       : EVENT
-               {
-                       bit_nclear($$, 0, EVENT_MAX - 1);
-                       bit_set($$, $1);
-               }
-       | event_list COMMA EVENT
-               {
-                       memcpy(&($$), &($1), bitstr_size(EVENT_MAX));
-                       bit_set($$, $3);
-               }
-       ;
-
-cmd_list
-       : /* empty */
-               {
-                       $$  = NULL;
-               }
-       | cmd_list cmd
-               {
-                       struct event_cmd * p = $1;
-                       if (p) {
-                               while (p->next != NULL)
-                                       p = p->next;
-                               p->next = $2;
-                               $$ = $1;
-                       } else {
-                               $$ = $2;
-                       }
-               }
-       ;
-
-cmd
-       : exec_cmd SEMICOLON    { $$ = $1; }
-       | reject_cmd SEMICOLON  { $$ = $1; }
-       ;
-
-exec_cmd
-       : EXECCMD string
-               {
-                       size_t len = sizeof (struct event_cmd_exec);
-                       struct event_cmd_exec *cmd = malloc(len);
-                       cmd->evcmd.next = NULL;
-                       cmd->evcmd.len = len;
-                       cmd->evcmd.name = "exec";
-                       cmd->evcmd.op = &event_cmd_exec_ops;
-                       cmd->line = $2;
-                       $$ = (struct event_cmd *) cmd;
-               }
-       ;
-
-reject_cmd
-       : REJECTCMD
-               {
-                       size_t len = sizeof (struct event_cmd_reject);
-                       struct event_cmd_reject *cmd = malloc(len);
-                       cmd->evcmd.next = NULL;
-                       cmd->evcmd.len = len;
-                       cmd->evcmd.name = "reject";
-                       cmd->evcmd.op = &event_cmd_reject_ops;
-                       $$ = (struct event_cmd *) cmd;
-               }
-       ;
-
-string
-       : STRING        { $$ = $1; }
-       ;
-
-unknown
-       : UNKNOWN
-               {
-                       $$ = $1;
-               }
-       ;
-%%
-
diff --git a/usr.sbin/apmd/contrib/pccardq.c b/usr.sbin/apmd/contrib/pccardq.c
deleted file mode 100644 (file)
index 5863707..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-/* $FreeBSD: src/usr.sbin/apmd/contrib/pccardq.c,v 1.2 1999/08/28 05:11:25 peter Exp $ */
-/* $DragonFly: src/usr.sbin/apmd/contrib/pccardq.c,v 1.4 2008/07/10 18:29:52 swildner Exp $ */
-
-#include <err.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-const char     *const pccardd_file = "/var/tmp/.pccardd";
-const char     *prog = "pccardq";
-const char     *tmp_dir = "/tmp";
-unsigned        slot_map = ~0;
-
-void
-usage(void)
-{
-    fprintf(stderr, "usage: %s [-a] [-n] [-s slot]\n", prog);
-}
-
-int
-proc_arg(int ac, char **av)
-{
-    int             rc = -1;
-    int             ch;
-
-    char           *p = strrchr(av[0], '/');
-    prog = p ? p + 1 : av[0];
-
-    tmp_dir = getenv("TMPDIR") ? getenv("TMPDIR") : tmp_dir;
-
-    while ((ch = getopt(ac, av, "ans:")) != -1) {
-       switch (ch) {
-       case 'a':
-           slot_map = ~0;
-           break;
-       case 'n':
-           slot_map = 0;
-           break;
-       case 's':
-           {
-               int             n = atoi(optarg);
-               if (n < 0 || n >= CHAR_BIT * sizeof slot_map) {
-                   warnc(0, "Invalid slot number.");
-                   usage();
-                   goto out;
-               }
-               if (slot_map == ~0)
-                   slot_map = 0;
-               slot_map |= 1 << n;
-           }
-           break;
-       default:
-           usage();
-           goto out;
-       }
-    }
-
-    rc = 0;
-  out:
-    return rc;
-}
-
-int
-connect_to_pccardd(char **path)
-{
-    int             so = -1;
-    int             pccardd_len;
-    struct sockaddr_un pccardq;
-    struct sockaddr_un pccardd;
-
-    if ((so = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
-       warn("socket");
-       goto err;
-    }
-
-    snprintf(pccardq.sun_path, sizeof pccardq.sun_path,
-            "%s/%s%ld%ld", tmp_dir, prog, (long) getpid(), (long) time(0));
-    pccardq.sun_family = AF_UNIX;
-    pccardq.sun_len = offsetof(struct sockaddr_un, sun_path) + strlen(pccardq.sun_path);
-    if (bind(so, (struct sockaddr *) &pccardq, pccardq.sun_len) < 0) {
-       warn("bind: %s", pccardq.sun_path);
-       goto err;
-    }
-    if ((*path = strdup(pccardq.sun_path)) == NULL) {
-       warn("strdup");
-       goto err;
-    }
-
-    pccardd_len = strlen(pccardd_file) + 1;
-    if (pccardd_len > sizeof pccardd.sun_path) {
-       warnc(0, "%s: too long", pccardd_file);
-       goto err;
-    }
-    pccardd.sun_len = offsetof(struct sockaddr_un, sun_path) + pccardd_len;
-    pccardd.sun_family = AF_UNIX;
-    strcpy(pccardd.sun_path, pccardd_file);
-    if (connect(so, (struct sockaddr *) &pccardd, pccardd.sun_len) < 0) {
-       warn("connect: %s", pccardd_file);
-       goto err;
-    }
-    return so;
-  err:
-    if (so >= 0)
-       close(so);
-    return -1;
-}
-
-int
-get_slot_number(int so)
-{
-    char            buf[8];
-    int             rv;
-    int             nslot;
-
-    if ((rv = write(so, "S", 1)) < 1) {
-       warn("write");
-       goto err;
-    } else if (rv != 1) {
-       warnc(0, "write: fail.");
-       goto err;
-    }
-
-    if ((rv = read(so, buf, sizeof buf)) < 0) {
-       warn("read");
-       goto err;
-    }
-    buf[sizeof buf - 1] = 0;
-    if (sscanf(buf, "%d", &nslot) != 1) {
-       warnc(0, "Invalid response.");
-       goto err;
-    }
-    return nslot;
-  err:
-    return -1;
-}
-
-enum {
-    SLOT_EMPTY = 0,
-    SLOT_FILLED = 1,
-    SLOT_INACTIVE = 2,
-    SLOT_UNDEFINED = 9
-};
-
-int
-get_slot_info(int so, int slot, char **manuf, char **version, char
-             **device, int *state)
-{
-    int             rc = -1;
-    int             rv;
-    static char     buf[1024];
-    int             slen;
-    char           *s;
-    char           *sl;
-
-    char           *_manuf;
-    char           *_version;
-    char           *_device;
-
-    slen = snprintf(buf, sizeof buf, "N%d", slot);
-    if ((rv = write(so, buf, slen)) < 0) {
-       warn("write");
-       goto err;
-    } else if (rv != slen) {
-       warnc(0, "write");
-       goto err;
-    }
-
-    if ((rv = read(so, buf, sizeof buf)) < 0) {
-       warn("read");
-       goto err;
-    }
-
-    s = buf;
-    if ((sl = strsep(&s, "~")) == NULL)
-       goto parse_err;
-    if (atoi(sl) != slot)
-       goto parse_err;
-    if ((_manuf = strsep(&s, "~")) == NULL)
-       goto parse_err;
-    if ((_version = strsep(&s, "~")) == NULL)
-       goto parse_err;
-    if ((_device = strsep(&s, "~")) == NULL)
-       goto parse_err;
-    if (sscanf(s, "%1d", state) != 1)
-       goto parse_err;
-    if (s != NULL && strchr(s, '~') != NULL)
-       goto parse_err;
-
-    *manuf = strdup(_manuf);
-    *version = strdup(_version);
-    *device = strdup(_device);
-    if (*manuf == NULL || *version == NULL || *device == NULL) {
-       warn("strdup");
-       goto err;
-    }
-
-    rc = 0;
-  err:
-    return rc;
-  parse_err:
-    warnc(0, "Invalid response: %*s", rv, buf);
-    return rc;
-}
-
-const char *
-strstate(int state)
-{
-    switch (state) {
-    case 0:
-       return "empty";
-    case 1:
-       return "filled";
-    case 2:
-       return "inactive";
-    default:
-       return "unknown";
-    }
-}
-
-int
-main(int ac, char **av)
-{
-    char           *path = NULL;
-    int             so = -1;
-    int             nslot;
-    int             i;
-
-    if (proc_arg(ac, av) < 0)
-       goto out;
-    if ((so = connect_to_pccardd(&path)) < 0)
-       goto out;
-    if ((nslot = get_slot_number(so)) < 0)
-       goto out;
-    if (slot_map == 0) {
-       printf("%d\n", nslot);
-    } else {
-       for (i = 0; i < nslot; i++) {
-           if ((slot_map & (1 << i))) {
-               char           *manuf;
-               char           *version;
-               char           *device;
-               int             state;
-
-               if (get_slot_info(so, i, &manuf, &version, &device,
-                                 &state) < 0)
-                   goto out;
-               if (manuf == NULL || version == NULL || device == NULL)
-                   goto out;
-               printf("%d~%s~%s~%s~%s\n",
-                      i, manuf, version, device, strstate(state));
-               free(manuf);
-               free(version);
-               free(device);
-           }
-       }
-    }
-  out:
-    if (path) {
-       unlink(path);
-       free(path);
-    }
-    if (so >= 0)
-       close(so);
-    exit(0);
-}
diff --git a/usr.sbin/battd/Makefile b/usr.sbin/battd/Makefile
deleted file mode 100644 (file)
index d0a2e68..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#      @(#)Makefile    8.1 (Berkeley) 6/6/93
-# $DragonFly: src/usr.sbin/battd/Makefile,v 1.3 2005/08/28 20:15:38 liamfoy Exp $
-
-PROG=  battd   
-MAN=   battd.8
-
-LDADD+=        -lutil
-DPADD+=        ${LIBUTIL}
-
-.include <bsd.prog.mk>
diff --git a/usr.sbin/battd/battd.8 b/usr.sbin/battd/battd.8
deleted file mode 100644 (file)
index 0af65f6..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-.\" Copyright (c) 2005 The DragonFly Project.  All rights reserved.
-.\"
-.\" This code is derived from software contributed to The DragonFly Project
-.\" by Maxime Labelle.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\"
-.\" 1. Redistributions of source code must retain the above copyright
-.\"    notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\"    notice, this list of conditions and the following disclaimer in
-.\"    the documentation and/or other materials provided with the
-.\"    distribution.
-.\" 3. Neither the name of The DragonFly Project nor the names of its
-.\"    contributors may be used to endorse or promote products derived
-.\"    from this software without specific, prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
-.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
-.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
-.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.Dd April 6, 2009
-.Dt BATTD 8
-.Os
-.Sh NAME
-.Nm battd
-.Nd Battery status monitoring daemon
-.Sh SYNOPSIS
-.Nm
-.Op Fl dEhT
-.Op Fl c Ar seconds
-.Op Fl e Ar command
-.Op Fl f Ar device
-.Op Fl p Ar percent
-.Op Fl s Ar status
-.Op Fl t Ar minutes
-.Sh DESCRIPTION
-The
-.Nm
-daemon monitors the status of the battery or batteries present in the system.
-The daemon will alert all users on the system and may execute a supplied
-command once a particular criterion has been met.
-The criteria are based
-on the percentage remaining, the time remaining and the status of the battery.
-.Pp
-The options are as follows:
-.Bl -tag -width indent
-.It Fl c Ar seconds
-Interval in seconds for checking the battery status.
-Default is
-.Ar 30
-seconds.
-.It Fl d
-Start in debug mode (works when
-.Nm
-is compiled with
-.Fl DDEBUG ) .
-.It Fl e Ar command
-Execute
-.Ar command
-once condition has been met.
-.It Fl E
-Execute command only once after a condition has been met.
-.It Fl f Ar device
-Specifies a different device path to be used.
-Default is
-.Pa /dev/apm .
-.It Fl h
-Print
-.Nm
-command line usage and exit.
-.It Fl p Ar percent
-Alert users when the remaining battery life has reached approximately
-.Ar percent .
-Default is
-.Ar 10 .
-A value of
-.Ar 0
-turns this alert off.
-.It Fl s Ar status
-Alert users when the remaining battery has reached a given status.
-The status specified can either be
-.Ar high ,
-.Ar low
-or
-.Ar critical .
-.It Fl t Ar minutes
-Alert users when the remaining battery time has reached approximately
-.Ar minutes .
-.It Fl T
-Alert users when the system has approximately 10 minutes remaining battery time,
-but don't execute command
-.Pq Fl e
-on this alert.
-.El
-.Sh EXAMPLES
-.Dl "battd -p 50 -s low"
-Alert users when the battery percentage has reached 50% and
-once again when the status reaches
-.Ar low .
-.Pp
-.Dl "battd -t 15 -c 10"
-Alert users when the battery has 15 minutes worth of power remaining
-and once again when battery percentage has reached 10%.
-Decrease the interval between checking the battery to 10 seconds.
-.Pp
-.Dl "battd -Tt4 -p0 -Ee \*q/sbin/shutdown -p +2 Battery_Low\*q"
-Alert users when the battery has 10 minutes worth power remaining and
-alert again when 4 minutes is remaining and then execute the given
-.Xr shutdown 8
-command once.
-(User will have to
-.Xr kill 1
-the
-.Xr shutdown 8
-process, if AC power is connected to system and shutdown isn't wanted.)
-.Sh SEE ALSO
-.Xr viapm 4 ,
-.Xr apm 8 ,
-.Xr apmd 8 ,
-.Xr syslogd 8 ,
-.Xr zzz 8
-.Sh HISTORY
-The
-.Nm
-command first appeared in
-.Dx 1.1 .
-.Sh AUTHORS
-.An Liam J. Foy Aq Mt liamfoy@dragonflybsd.org
-.Pp
-Man page contributions by:
-.An Maxime Labelle Aq Mt mlabelle@vt220.com
-.An Sarunas Vancevicius Aq Mt svan@redbrick.dcu.ie
diff --git a/usr.sbin/battd/battd.c b/usr.sbin/battd/battd.c
deleted file mode 100644 (file)
index 0cccc2d..0000000
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- * Copyright (c) 2003, 2005 The DragonFly Project.  All rights reserved.
- *
- * This code is derived from software contributed to The DragonFly Project
- * by Liam J. Foy <liamfoy@dragonflybsd.org> 
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- * 3. Neither the name of The DragonFly Project nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific, prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $DragonFly: src/usr.sbin/battd/battd.c,v 1.12 2008/02/22 04:30:34 swildner Exp $
- *
- * Dedicated to my grandfather Peter Foy. Goodnight... 
- */
-
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <machine/apm_bios.h>
-#include <limits.h>
-
-#include <err.h>
-#include <errno.h>
-#include <libutil.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#define APMUNKNOWN     255 /* Unknown value. */
-#define        AC_LINE_IN      1 /* AC Line Status values. */
-#define AC_OFFLINE     0
-#define SECONDS                60
-#define APM_DEVICE     "/dev/apm" /* Default APM Device. */
-#define ERR_OUT                1  /* Values for error writing. */
-#define SYSLOG_OUT     0
-#define DEFAULT_ALERT  10 /* Default alert is 10%. */
-#define EXEC_ALL       0
-#define EXEC_ONCE      1
-#define EXEC_DONE      2
-
-struct battd_conf {
-       int     alert_per;      /* Percentage to alert user on */
-       int     alert_time;     /* User can also alert when there is only X amount of minutes left */
-       int     alert_status;   /* Alert when battery is either high, low, critical */ 
-       const char      *apm_dev;       /* APM Device */
-       const char      *exec_cmd;      /* Command to execute if desired */     
-};
-
-#ifdef DEBUG
-static int f_debug;
-#endif
-
-static int     check_percent(int);
-static int     check_stat(int);
-static int     check_time(int);
-static int     get_apm_info(struct apm_info *, int, const char *, int);
-static void    execute_cmd(const char *, int *);
-static void    write_emerg(const char *, int *);
-static void    usage(void) __dead2;
-
-static void
-usage(void)
-{
-#ifdef DEBUG
-       fprintf(stderr, "usage: battd [-dEhT] [-c seconds] [-e command] [-f device]\n"
-                       "             [-p percent] [-s status] [-t minutes]\n");
-#else
-       fprintf(stderr, "usage: battd [-EhT] [-c seconds] [-e command] [-f device]\n"
-                       "             [-p percent] [-s status] [-t minutes]\n");
-#endif
-       exit(EXIT_FAILURE);
-}
-
-static int
-check_percent(int apm_per)
-{
-       if (apm_per < 0 || apm_per >= APMUNKNOWN || apm_per > 100)
-               return(1);
-
-       return(0);
-}
-
-static int
-check_time(int apm_time)
-{
-       if (apm_time <= -1)
-               return(1);
-
-       return(0);
-}
-
-static int
-check_stat(int apm_stat)
-{
-       if (apm_stat > 3 || apm_stat < 0)
-               return(1);
-
-       return(0);
-}
-
-/* Fetch battery information */
-static int
-get_apm_info(struct apm_info *ai, int fp_dev, const char *apm_dev, int err_to)
-{
-       if (ioctl(fp_dev, APMIO_GETINFO, ai) == -1) {
-               if (err_to)
-                       err(1, "ioctl(APMIO_GETINFO) device: %s", apm_dev);
-               else
-                       syslog(LOG_ERR, "ioctl(APMIO_GETINFO) device: %s: %m ",
-                               apm_dev);
-
-               return(1);
-       }
-
-       return(0);
-}
-
-/* Execute command. */
-static void
-execute_cmd(const char *exec_cmd, int *exec_cont)
-{
-       pid_t pid;
-       int status;
-               
-       if (*exec_cont != EXEC_DONE) {
-               if ((pid = fork()) == -1) {
-                       /* Here fork failed */
-#ifdef DEBUG
-                       if (f_debug)
-                               warn("fork failed");
-                       else
-#endif
-                               syslog(LOG_ERR, "fork failed: %m");
-               } else if (pid == 0) {
-                       execl("/bin/sh", "/bin/sh", "-c", exec_cmd, NULL);
-                       _exit(EXIT_FAILURE);
-               } else {
-                       while (waitpid(pid, &status, 0) != pid)
-                               ;
-                       if (WEXITSTATUS(status)) {
-#ifdef DEBUG
-                               if (f_debug)
-                                       warnx("child exited with code %d", status);
-                               else
-#endif
-                                       syslog(LOG_ERR, "child exited with code %d", status);
-                       }
-                       if (*exec_cont == EXEC_ONCE)
-                               *exec_cont = EXEC_DONE;
-               }
-       }
-}
-
-/* Write warning. */
-static void
-write_emerg(const char *eme_msg, int *warn_cont)
-{
-       if (*warn_cont == 0) {
-               openlog("battd", LOG_EMERG, LOG_CONSOLE);
-               syslog(LOG_ERR, "%s\n", eme_msg);
-               *warn_cont = 1;
-       }
-}
-
-/* Check given numerical arguments. */
-static int
-getnum(const char *str)
-{
-       long val;
-       char *ep;
-
-       errno = 0;
-       val = strtol(str, &ep, 10);
-       if (errno)
-               err(1, "strtol failed: %s", str);
-
-       if (str == ep || *ep != '\0')
-               errx(1, "invalid value: %s", str);
-
-       if (val > INT_MAX || val < INT_MIN) {
-               errno = ERANGE;
-               errc(1, errno, "getnum failed:");
-       }
-
-       return((int)val);
-}
-
-int
-main(int argc, char **argv)
-{
-       struct battd_conf battd_options, *opts;
-       struct apm_info ai;
-       int fp_device, exec_cont;
-       int per_warn_cont, time_warn_cont, stat_warn_cont;
-       int check_sec, time_def_alert, def_warn_cont;
-       int c, tmp;
-       char msg[80];
-
-       opts = &battd_options;
-
-       /*
-        * As default, we sleep for 30 seconds before
-        * we next call get_apm_info and do the rounds.
-        * The lower the value, the more accurate. Very
-        * low values could cause a decrease in system
-        * performance. We recommend about 30 seconds.
-        */
-
-       check_sec = 30;
-
-       exec_cont = EXEC_ALL;
-       per_warn_cont = stat_warn_cont = 0;
-       time_warn_cont = time_def_alert = def_warn_cont = 0;
-
-       opts->alert_per = DEFAULT_ALERT;
-       opts->alert_time = 0;
-       opts->alert_status = -1;
-       opts->exec_cmd = NULL;
-       opts->apm_dev = APM_DEVICE;
-
-       while ((c = getopt(argc, argv, "de:Ep:s:c:f:ht:T")) != -1) {
-               switch (c) {
-               case 'c':
-                       /* Parse the check battery interval. */
-                       check_sec = getnum(optarg);
-                       if (check_sec <= 0)
-                               errx(1, "the interval for checking battery "
-                                       "status must be greater than 0.");
-                       break;
-#ifdef DEBUG
-               case 'd':
-                       /* Debug mode. */
-                       f_debug = 1;
-                       break;
-#endif
-               case 'e':
-                       /* Command to execute. */
-                       opts->exec_cmd = optarg;
-                       break;
-               case 'E':
-                       /* Only execute once when any condition has been met. */
-                       exec_cont = EXEC_ONCE;
-                       break;
-               case 'f':
-                       /* Don't use /dev/apm use optarg. */
-                       opts->apm_dev = optarg;
-                       break;
-               case 'h':
-                       /* Print usage and be done! */
-                       usage();
-                       break;
-               case 'p':
-                       /*
-                        * Parse percentage to alert on and enable
-                        * battd to monitor the battery percentage.
-                        * A value of 0 disables battery percentage monitoring.
-                        */
-                       opts->alert_per = getnum(optarg);
-                       if (opts->alert_per < 0 || opts->alert_per > 99)
-                               errx(1, "Battery percentage to alert on must be "
-                                       "between 0 and 99.");
-                       break;
-               case 's':
-                       /*
-                        * Parse status to alert on and enable
-                        * battd to monitor the battery status.
-                        * We also accept 'high', 'HIGH' or 'HiGh'.
-                        */
-                       if (strcasecmp(optarg, "high") == 0)
-                               opts->alert_status = 0; /* High */
-                       else if (strcasecmp(optarg, "low") == 0)
-                               opts->alert_status = 1; /* Low */
-                       else if (strcasecmp(optarg, "critical") == 0)
-                               opts->alert_status = 2; /* Critical (mental) */
-                       else {
-                               /* No idea, see what we have. */
-                               opts->alert_status = getnum(optarg);
-                               if (opts->alert_status < 0 || opts->alert_status > 2)
-                                       errx(1, "Alert status must be between 0 and 2.");
-                       }
-                       break;
-               case 't':
-                       /*
-                        * Parse time to alert on and enable
-                        * battd to monitor the time percentage.
-                        */
-                       opts->alert_time = getnum(optarg);
-                       if (opts->alert_time <= 0)
-                               errx(1, "Alert time must be greater than 0 minutes.");
-                       break;
-               case 'T':
-                       time_def_alert = 1;
-                       break;
-               default:
-                       usage();
-               }
-       }
-
-       if ((fp_device = open(opts->apm_dev, O_RDONLY)) < 0)
-               err(1, "open failed: %s", opts->apm_dev);
-
-       /* 
-        * Before we become a daemon, first check whether
-        * the actual function requested is supported. If
-        * not, exit and let the user know.
-        */
-
-       /* Start test */
-       get_apm_info(&ai, fp_device, opts->apm_dev, ERR_OUT);
-
-       if (opts->alert_per > 0)
-               if (check_percent(ai.ai_batt_life))
-                       errx(1, "invalid/unknown percentage(%d) returned from %s",
-                               ai.ai_batt_life, opts->apm_dev);
-
-       if (opts->alert_time || time_def_alert)
-               if (check_time(ai.ai_batt_time) && ai.ai_batt_time != -1)
-                       errx(1, "invalid/unknown time(%d) returned from %s",
-                               ai.ai_batt_time, opts->apm_dev);
-
-       if (opts->alert_status)
-               if (check_stat(ai.ai_batt_stat))
-                       errx(1, "invalid/unknown status(%d) returned from %s",
-                               ai.ai_batt_stat, opts->apm_dev);
-       /* End test */
-
-#ifdef DEBUG
-       if (f_debug == 0) {
-#endif
-               struct pidfh *pfh = NULL;
-
-               pfh = pidfile_open(NULL, 600, NULL);
-               if (daemon(0, 0) == -1)
-                       err(1, "daemon failed");
-               pidfile_write(pfh);
-#ifdef DEBUG
-       }
-#endif
-
-       for (;;) {
-               if (get_apm_info(&ai, fp_device, opts->apm_dev,
-#ifdef DEBUG
-                       f_debug ? ERR_OUT : SYSLOG_OUT))
-#else
-                       SYSLOG_OUT))
-#endif
-                       /* Recoverable - sleep for check_sec seconds */
-                       goto sleepy_time;
-
-               /* If we have power, reset the warning values. */
-               if (ai.ai_acline == AC_LINE_IN) {
-                       per_warn_cont = 0;
-                       time_warn_cont = 0;
-                       stat_warn_cont = 0;
-                       def_warn_cont = 0;
-               }
-
-               /*
-                * If the battery has main power (AC lead is plugged in)
-                * we skip and sleep for check_sec seconds.
-                */
-               if (ai.ai_acline != AC_LINE_IN) {
-                       /*
-                        * Battery has no mains power. Time to do
-                        * our job!
-                        */
-
-                       /*
-                        * Main Processing loop
-                        * --------------------
-                        * 1. Check battery percentage if enabled.
-                        * 2. Check battery time remaining if enabled.
-                        * 3. Check battery status if enabled.
-                        * 4. Deal with time default alert.
-                        */ 
-
-                       /* 1. Check battery percentage if enabled */
-                       if (opts->alert_per) {
-                               if (check_percent(ai.ai_batt_life)) {
-#ifdef DEBUG
-                                       if (f_debug) {
-                                               printf("Invalid percentage (%d) received from %s.\n",
-                                                       ai.ai_batt_life, opts->apm_dev);
-                                       } else {
-#endif
-                                               syslog(LOG_ERR, "Invalid percentage received from %s.",
-                                                       opts->apm_dev);
-#ifdef DEBUG
-                                       }
-#endif
-                                       continue;
-                               }
-
-                               if (ai.ai_batt_life <= (u_int)opts->alert_per) {
-                                       tmp = (ai.ai_batt_life == (u_int)opts->alert_per);
-                                       snprintf(msg, sizeof(msg), "battery has %s %d%%\n",
-                                               tmp ? "reached" : "fallen below",
-                                               opts->alert_per);
-                                       execute_cmd(opts->exec_cmd, &exec_cont);
-                                       write_emerg(msg, &per_warn_cont);
-                               }
-                       }
-
-                       /* 2. Check battery time remaining if enabled */
-                       if (opts->alert_time) {
-                               if (check_time(ai.ai_batt_time)) {
-#ifdef DEBUG
-                                       if (f_debug) {
-                                               printf("Invalid time value (%d) received from %s.\n",
-                                                       ai.ai_batt_time, opts->apm_dev);
-                                       } else {
-#endif
-                                               syslog(LOG_ERR, "Invalid time value received from %s.",
-                                                       opts->apm_dev);
-#ifdef DEBUG
-                                       }
-#endif
-                                       continue;
-                               }
-       
-                               if (ai.ai_batt_time <= (opts->alert_time * SECONDS)) {
-                                       int h, m, s;
-                                       char tmp_time[sizeof "tt:tt:tt" + 1];
-                                       h = ai.ai_batt_time;
-                                       s = h % 60;
-                                       h /= 60;
-                                       m = h % 60;
-                                       h /= 60;
-                                       snprintf(tmp_time, sizeof(tmp_time), "%d:%d:%d\n", h, m, s);
-                                       tmp = (ai.ai_batt_time == opts->alert_time);
-                                       snprintf(msg, sizeof(msg), "battery has %s %d(%s) minutes "
-                                               "remaining\n", tmp ? "reached" : "fallen below",
-                                               ai.ai_batt_time / SECONDS, tmp_time);
-                                       execute_cmd(opts->exec_cmd, &exec_cont);
-                                       write_emerg(msg, &time_warn_cont);
-                               }
-                       }
-
-                       /* 3. Check battery status if enabled */
-                       if (opts->alert_status != -1) {
-                               if (check_stat(ai.ai_batt_stat)) {
-#ifdef DEBUG
-                                       if (f_debug) {
-                                               printf("Invalid status value (%d) received from %s.\n",
-                                                       ai.ai_batt_life, opts->apm_dev);
-                                       } else {
-#endif
-                                               syslog(LOG_ERR, "Invalid status value received from %s.",
-                                                       opts->apm_dev);
-#ifdef DEBUG
-                                       }
-#endif
-                                       continue;
-                               }
-
-                               if (ai.ai_batt_stat >= (u_int)opts->alert_status) {
-                                       const char *batt_status[] = {"high", "low", "critical"};
-
-                                       tmp = (ai.ai_batt_stat == (u_int)opts->alert_status);
-                                       snprintf(msg, sizeof(msg), "battery has %s '%s' status\n",
-                                               tmp ? "reached" : "fallen below",
-                                               batt_status[ai.ai_batt_stat]);
-                                       execute_cmd(opts->exec_cmd, &exec_cont);
-                                       write_emerg(msg, &stat_warn_cont);
-                               }
-                       }
-
-                       /* 4. Deal with time default alert. */
-                       if (time_def_alert) {
-                               if (check_time(ai.ai_batt_time)) {
-#ifdef DEBUG
-                                       if (f_debug) {
-                                               printf("Invalid time value (%d) received from %s.\n",
-                                                       ai.ai_batt_time, opts->apm_dev);
-                                       } else {
-#endif
-                                               syslog(LOG_ERR, "Invalid time value received from %s.",
-                                                       opts->apm_dev);
-#ifdef DEBUG
-                                       }
-#endif
-                                       continue;
-                               }
-
-                               if (ai.ai_batt_time <= DEFAULT_ALERT * SECONDS) {
-                                       snprintf(msg, sizeof(msg), "WARNING! battery has "
-                                               "only roughly %d minutes remaining!\n",
-                                               ai.ai_batt_time / SECONDS);
-                                       write_emerg(msg, &def_warn_cont);
-                               }
-                       }
-
-               }
-sleepy_time:
-               /* Sleep time! Default is 30 seconds */
-               sleep(check_sec);
-       }
-       return(0);
-}