From mconst@not.there.com Mon Jul 12 17:53:17 1999
Return-Path: <mconst@not.there.com>
Received: from not.there.com (mg131-151.ricochet.net [204.179.131.151])
	by hub.freebsd.org (Postfix) with ESMTP id 2DC7F15256
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 Jul 1999 17:52:44 -0700 (PDT)
	(envelope-from mconst@not.there.com)
Received: (from mconst@localhost)
	by not.there.com (8.9.3/8.9.3) id RAA01409;
	Mon, 12 Jul 1999 17:40:25 -0700 (PDT)
	(envelope-from mconst)
Message-Id: <199907130040.RAA01409@not.there.com>
Date: Mon, 12 Jul 1999 17:40:25 -0700 (PDT)
From: Michael Constant <mconst@csua.berkeley.edu>
Sender: mconst@not.there.com
Reply-To: mconst@csua.berkeley.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] apm -r doesn't respect wall_cmos_clock
X-Send-Pr-Version: 3.2

>Number:         12614
>Category:       bin
>Synopsis:       [patch] apm -r doesn't respect wall_cmos_clock
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 12 18:00:01 PDT 1999
>Closed-Date:    Thu Jul 29 12:22:12 PDT 1999
>Last-Modified:  Thu Jul 29 12:24:09 PDT 1999
>Originator:     Michael Constant
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
>Environment:

    Thinkpad 570 running 4.0-CURRENT, last updated July 11, 1999.

>Description:

    apm -r sets the machine to wake up from suspend mode after the specified
    number of seconds.  However, it always calculates the time to wake up in
    UTC, even if the machine's CMOS clock uses wall time.  The effect is that
    apm -r will wake up your machine either several hours too late (if you're
    west of Greenwich) or not at all (if you're east).
 
    /usr/src/usr.sbin/apm/apm.c includes code to correctly set the wakeup
    time on wall_cmos_clock machines, controlled by the variable "cmos_wall".
    It never actually sets that variable, though, so it always uses the code
    path for UTC CMOS clock machines.  I've included a patch for apm below.

>How-To-Repeat:

    $ ls -l /etc/wall_cmos_clock
    -rw-r--r--  1 root  wheel  0 Jun 19 19:45 /etc/wall_cmos_clock
    $ apm
    APM version: 1.2
    APM Managment: Enabled
    AC Line status: on-line
    Battery status: charging
    Remaining battery life: 92%
    Remaining battery time: unknown
    Number of batteries: 2
    Resume timer: disabled
    Resume on ring indicator: disabled
    APM Capacities:
	    global standby state
	    global suspend state
	    resume timer from suspend
    $ apm -r30
    $ zzz

    The machine suspends, but does not resume 30 seconds later.

>Fix:

    The following patch fixes the problem.

    Note: when testing apm (with or without this patch), do not trust the
    "Resume timer:" line it sometimes outputs.  That's also broken, and I've
    submitted a patch for it as a separate PR.


--- /usr/src/usr.sbin/apm/apm.c.orig	Fri Sep  4 09:08:54 1998
+++ /usr/src/usr.sbin/apm/apm.c	Sat Jul 10 22:22:57 1999
@@ -18,6 +18,8 @@
 	"$Id: apm.c,v 1.14 1998/09/04 16:08:54 imp Exp $";
 #endif /* not lint */
 
+#include <sys/types.h>
+#include <sys/sysctl.h>
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -288,7 +290,12 @@
 	int     display = 0, batt_life = 0, ac_status = 0, standby = 0;
 	int	batt_time = 0, delta = 0;
 	char	*cmdname;
+	size_t	cmos_wall_len;
 
+	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++;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: iwasaki 
State-Changed-When: Thu Jul 29 12:22:12 PDT 1999 
State-Changed-Why:  
Fixed in CURRENT and RELENG_3.  Thanks! 
>Unformatted:
