summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>1998-07-18 02:42:29 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>1998-07-18 02:42:29 +0000
commitc2ffb4b0a5b13de29b4b271b8a8d6e5442b4c188 (patch)
tree69bd0ea468017f1dc708c48da1aff2a8a671c4cf
parentf34a96fd754aa066dce4677f57e90fc20f2c5048 (diff)
apmd will turn off apm driver messages when in daemon mode
added three flags. -m to not turn off messages. -e to turn them back on after an apmd crash. -p to turn on print percentage change mode.
-rw-r--r--usr.sbin/apmd/apmd.833
-rw-r--r--usr.sbin/apmd/apmd.c41
2 files changed, 65 insertions, 9 deletions
diff --git a/usr.sbin/apmd/apmd.8 b/usr.sbin/apmd/apmd.8
index 9155e4b5c16..72b89e4f7cd 100644
--- a/usr.sbin/apmd/apmd.8
+++ b/usr.sbin/apmd/apmd.8
@@ -24,7 +24,7 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Id: apmd.8,v 1.3 1998/03/10 04:51:05 millert Exp $
+.\" $Id: apmd.8,v 1.4 1998/07/18 02:42:27 marc Exp $
.\"
.Dd March 24, 1996
.Dt APMD 8
@@ -34,10 +34,7 @@
.Nd Advanced Power Management monitor daemon
.Sh SYNOPSIS
.Nm
-.Op Fl d
-.Op Fl s
-.Op Fl a
-.Op Fl q
+.Op Fl dsaqepm
.Op Fl t Ar seconds
.Op Fl S Ar sockname
.Op Fl f Ar devname
@@ -105,6 +102,32 @@ flag is specified,
.Nm
does not announce suspend and standby requests on the speaker.
.Pp
+If the
+.Fl m
+flag is specified,
+.Nm
+does not disable power status messages issued by the
+.Tn APM
+driver. In normal operation these status messages are disabled as they are
+the same as the information collected by this daemon and reported via syslog.
+.Pp
+The
+.Fl e
+and
+.Fl p
+flags are used to re-enable
+.Tn APM
+driver power status messages. In both cases
+.Nm
+exits immediately after setting the desired option.
+.Fl e
+unconditionally enables power status messages.
+.Fl p
+causes power status messages to be displayed only when the
+battery life expectancy changes. This minimized message output
+for those devices that are constantly updating the estimated time
+remaining based upon current processor load.
+.Pp
When a client requests a suspend or stand-by mode,
.Nm
does not wait for positive confirmation that the requested
diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c
index 300367c1d61..2751b126151 100644
--- a/usr.sbin/apmd/apmd.c
+++ b/usr.sbin/apmd/apmd.c
@@ -88,6 +88,16 @@ usage(void)
}
+/*
+ * tell the driver if it should display messages or not.
+ */
+static void
+set_driver_messages(int fd, int mode)
+{
+ if ( ioctl(fd, APM_IOC_PRN_CTL, &mode) == -1 )
+ syslog( LOG_DEBUG, "can't disable driver messages, error: %m" );
+}
+
int
power_status(int fd, int force, struct apm_power_info *pinfo)
{
@@ -111,7 +121,7 @@ power_status(int fd, int force, struct apm_power_info *pinfo)
"estimated battery life %d%% (%d minutes)",
battstate(bstate.battery_state),
ac_state(bstate.ac_state), bstate.battery_life,
- bstate.minutes_left);
+ bstate.minutes_left / 60 );
else
syslog(LOG_NOTICE,
"battery status: %s. external power status: %s. "
@@ -285,12 +295,15 @@ resume(int ctl_fd)
do_etc_file(_PATH_APM_ETC_RESUME);
}
-void
+int
main(int argc, char *argv[])
{
const char *fname = apmdev;
int ctl_fd, sock_fd, ch, ready;
int statonly = 0;
+ int enableonly = 0;
+ int pctonly = 0;
+ int messages = 0;
fd_set devfds;
fd_set selcopy;
struct apm_event_info apmevent;
@@ -299,7 +312,7 @@ main(int argc, char *argv[])
struct timeval tv = {TIMO, 0}, stv;
const char *sockname = sockfile;
- while ((ch = getopt(argc, argv, "qadsf:t:S:")) != -1)
+ while ((ch = getopt(argc, argv, "qadsepmf:t:S:")) != -1)
switch(ch) {
case 'q':
speaker_ok = FALSE;
@@ -324,6 +337,15 @@ main(int argc, char *argv[])
case 's': /* status only */
statonly = 1;
break;
+ case 'e':
+ enableonly = 1;
+ break;
+ case 'p':
+ pctonly = 1;
+ break;
+ case 'm':
+ messages = 1;
+ break;
case '?':
default:
@@ -344,6 +366,17 @@ main(int argc, char *argv[])
power_status(ctl_fd, 1, 0);
if (statonly)
exit(0);
+ if (enableonly) {
+ set_driver_messages(ctl_fd, APM_PRINT_ON);
+ exit(0);
+ }
+ if (pctonly) {
+ set_driver_messages(ctl_fd, APM_PRINT_PCT);
+ exit(0);
+ }
+ if ( ! messages ) {
+ set_driver_messages(ctl_fd, APM_PRINT_OFF);
+ }
(void) signal(SIGTERM, sigexit);
(void) signal(SIGHUP, sigexit);
(void) signal(SIGINT, sigexit);
@@ -426,7 +459,7 @@ main(int argc, char *argv[])
}
}
syslog(LOG_ERR, "select failed: %m");
- exit(1);
+ return 1;
}
void