From owner-freebsd-hackers Mon Jul 17 12:40:12 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id ED81537BB6F; Mon, 17 Jul 2000 12:40:04 -0700 (PDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id NAA81720; Mon, 17 Jul 2000 13:40:03 -0600 (MDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id NAA63638; Mon, 17 Jul 2000 13:39:57 -0600 (MDT) Message-Id: <200007171939.NAA63638@harmony.village.org> Subject: Re: sysctl interface for apm? Cc: Hajimu UMEMOTO , nsayer@FreeBSD.ORG, nsayer@sftw.com, freebsd-hackers@FreeBSD.ORG In-reply-to: Your message of "Mon, 17 Jul 2000 13:14:24 MDT." <200007171914.NAA63275@harmony.village.org> References: <200007171914.NAA63275@harmony.village.org> <20000718.033514.59474907.ume@mahoroba.org> <1884.963737703@critter.freebsd.dk> <200007171753.LAA62543@harmony.village.org> <39734D36.5FC7DDA@sftw.com> Date: Mon, 17 Jul 2000 13:39:57 -0600 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <200007171914.NAA63275@harmony.village.org> Warner Losh writes: : Yes. The right answer isn't to kludge this through a sysctl, but : instead it is to fix apm to that it is safe to make it world read : only. Is there a way inside a ioctl to see if you have something open : for write access? OK. I found the answer. Here's my patch. Comments? This way we don't have two, incompatible power interfaces. Warner Index: etc/MAKEDEV =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/etc/MAKEDEV,v retrieving revision 1.260 diff -u -r1.260 MAKEDEV --- etc/MAKEDEV 2000/06/26 15:42:48 1.260 +++ etc/MAKEDEV 2000/07/17 19:39:37 @@ -1364,7 +1364,7 @@ apm) mknod apm c 39 0 root:operator - chmod 660 apm + chmod 664 apm ;; apmctl) Index: usr.sbin/apm/apm.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/usr.sbin/apm/apm.c,v retrieving revision 1.22 diff -u -r1.22 apm.c --- usr.sbin/apm/apm.c 2000/01/22 18:11:58 1.22 +++ usr.sbin/apm/apm.c 2000/07/17 19:39:37 @@ -412,7 +412,10 @@ argv += optind; } finish_option: - fd = open(APMDEV, O_RDWR); + if (haltcpu != -1 || enable != -1 || delta || sleep || standby) + fd = open(APMDEV, O_RDWR); + else + fd = open(APMDEV, O_RDONLY); if (fd == -1) err(1, "can't open %s", APMDEV); if (enable != -1) Index: sys/i386/apm/apm.c =================================================================== RCS file: /home/imp/FreeBSD/CVS/src/sys/i386/apm/apm.c,v retrieving revision 1.114 diff -u -r1.114 apm.c --- sys/i386/apm/apm.c 2000/02/06 14:57:05 1.114 +++ sys/i386/apm/apm.c 2000/07/17 19:39:37 @@ -1169,6 +1169,8 @@ #endif switch (cmd) { case APMIO_SUSPEND: + if ((flag & FWRITE) != 0) + return (EPERM); if (sc->active) apm_suspend(PMST_SUSPEND); else @@ -1176,6 +1178,8 @@ break; case APMIO_STANDBY: + if ((flag & FWRITE) != 0) + return (EPERM); if (sc->active) apm_suspend(PMST_STANDBY); else @@ -1203,23 +1207,35 @@ error = ENXIO; break; case APMIO_ENABLE: + if ((flag & FWRITE) != 0) + return (EPERM); apm_event_enable(); break; case APMIO_DISABLE: + if ((flag & FWRITE) != 0) + return (EPERM); apm_event_disable(); break; case APMIO_HALTCPU: + if ((flag & FWRITE) != 0) + return (EPERM); apm_halt_cpu(); break; case APMIO_NOTHALTCPU: + if ((flag & FWRITE) != 0) + return (EPERM); apm_not_halt_cpu(); break; case APMIO_DISPLAY: + if ((flag & FWRITE) != 0) + return (EPERM); newstate = *(int *)addr; if (apm_display(newstate)) error = ENXIO; break; case APMIO_BIOS: + if ((flag & FWRITE) != 0) + return (EPERM); /* XXX compatibility with the old interface */ args = (struct apm_bios_arg *)addr; sc->bios.r.eax = args->eax; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message