Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Jul 2000 13:39:57 -0600
From:      Warner Losh <imp@village.org>
Cc:        Hajimu UMEMOTO <ume@mahoroba.org>, nsayer@FreeBSD.ORG, nsayer@sftw.com, freebsd-hackers@FreeBSD.ORG
Subject:   Re: sysctl interface for apm? 
Message-ID:  <200007171939.NAA63638@harmony.village.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> 

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007171939.NAA63638>