changeset 1085:bfe79fc710da draft

Cleanup chvt
author Rob Landley <rob@landley.net>
date Tue, 08 Oct 2013 15:58:08 -0500
parents 4f30bf230196
children 162bb45b0387
files toys/other/chvt.c
diffstat 1 files changed, 5 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/toys/other/chvt.c	Tue Oct 08 12:25:02 2013 -0500
+++ b/toys/other/chvt.c	Tue Oct 08 15:58:08 2013 -0500
@@ -19,29 +19,16 @@
 
 #include "toys.h"
 
-/* Note: get_console_fb() will need to be moved into a seperate lib section */
-int get_console_fd()
-{
-  int fd;
-  char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc;
-
-  cc = consoles;
-  while (*cc) {
-    fd = open(*cc++, O_RDWR);
-    if (fd >= 0) return fd;
-  }
-
-  return -1;
-}
-
 void chvt_main(void)
 {
   int vtnum, fd;
+  char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc;
 
   vtnum=atoi(*toys.optargs);
+  for (cc = consoles; *cc; cc++)
+    if (-1 != (fd = open(*cc, O_RDWR))) break;
 
-  fd=get_console_fd();
   // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h
-  if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
-    perror_exit(NULL);
+  if (!*cc || fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
+    perror_exit(0);
 }