aboutsummaryrefslogtreecommitdiff
path: root/toys/other/chvt.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-10-08 15:58:08 -0500
committerRob Landley <rob@landley.net>2013-10-08 15:58:08 -0500
commitdb494a2fe9a3ffc7a07c5e00334ea8506adba0f1 (patch)
tree7b991e16e868d1cebf0ae2531876dd28cab2f91e /toys/other/chvt.c
parentad1f8a0e598751aaf67d3fbd1611d35b03318f4e (diff)
downloadtoybox-db494a2fe9a3ffc7a07c5e00334ea8506adba0f1.tar.gz
Cleanup chvt
Diffstat (limited to 'toys/other/chvt.c')
-rw-r--r--toys/other/chvt.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/toys/other/chvt.c b/toys/other/chvt.c
index 7a0119c9..5016b9b5 100644
--- a/toys/other/chvt.c
+++ b/toys/other/chvt.c
@@ -19,29 +19,16 @@ config CHVT
#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);
}