Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 May 2001 14:52:09 +0300
From:      Ruslan Ermilov <ru@FreeBSD.ORG>
To:        Nik Clayton <nik@FreeBSD.ORG>
Cc:        arch@FreeBSD.ORG
Subject:   Re: [PATCH] syscons ioctl() to grab text mode buffer
Message-ID:  <20010517145209.C55371@sunbay.com>
In-Reply-To: <20010517121902.A3047@catkin.nothing-going-on.org>; from nik@FreeBSD.ORG on Thu, May 17, 2001 at 12:19:02PM %2B0100
References:  <20010517121902.A3047@catkin.nothing-going-on.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 17, 2001 at 12:19:02PM +0100, Nik Clayton wrote:
> Two things for review.
> 
[...]
> The second, scrshot.c uses the ioctl to dump the contents of the video
> memory to stdout.  Usage is
> 
>     scrshot /dev/ttyv0 > shot.scr
> 
There are some style(9) and -security issues with this:

--- scrshot.c~	Thu May 17 14:42:40 2001
+++ scrshot.c	Thu May 17 14:50:22 2001
@@ -28,9 +28,9 @@
  * $FreeBSD$
  */
 
+#include <sys/types.h>
 #include <sys/consio.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #include <sys/uio.h>
 
 #include <err.h>
@@ -48,7 +48,6 @@
 main(int argc, char *argv[])
 {
 	int fd;
-	int result;
 	scrshot_t shot;
 	vid_info_t info;
 
@@ -56,33 +55,24 @@
 		errx(1, "improper # of args");
 
 	fd = open(argv[1], O_RDWR);
-	if (fd < 0) {
-		perror(argv[1]);
-		exit(1);
-	}
+	if (fd < 0)
+		err(1, "%s", argv[1]);
 	
 	info.size = sizeof(info);
-	result = ioctl(fd, CONS_GETINFO, &info);
-	if (result != 0) {
-		perror("getinfo failed");
-		exit(1);
-	}
+	if (ioctl(fd, CONS_GETINFO, &info) == -1)
+		err(1, "ioctl(CONS_GETINFO)");
 	
 	shot.buf = malloc(info.mv_csz * info.mv_rsz * sizeof(u_int16_t));
-	if (!shot.buf) {
-		perror("couldn't allocate shot space");
-		exit(1);
-	}
+	if (shot.buf == NULL)
+		err(1, "couldn't allocate shot space");
 	
 	shot.xsize = info.mv_csz;
 	shot.ysize = info.mv_rsz;
-	result = ioctl (fd, CONS_SCRSHOT, &shot);
-	if (result != 0) {
-		perror("CONS_SCRSHOT failed");
-		exit(1);
-	}
+	if (ioctl(fd, CONS_SCRSHOT, &shot) == -1)
+		err(1, "ioctl(CONS_SCRSHOT)");
 	
-	write(1, shot.buf, shot.xsize * shot.ysize * sizeof(u_int16_t));
+	(void) write(STDOUT_FILENO, shot.buf,
+	    shot.xsize * shot.ysize * sizeof(u_int16_t));
 
-	return 0;
+	exit(0);
 }


Cheers,
-- 
Ruslan Ermilov		Oracle Developer/DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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