Mercurial > hg > toybox
comparison toys/chvt.c @ 316:17c0a2013852
Tighten up chvt, save a few bytes.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 24 Oct 2008 23:19:38 -0500 |
parents | d9ea4ca7ae8c |
children |
comparison
equal
deleted
inserted
replaced
315:aaac01796688 | 316:17c0a2013852 |
---|---|
21 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back. | 21 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back. |
22 */ | 22 */ |
23 | 23 |
24 #include "toys.h" | 24 #include "toys.h" |
25 | 25 |
26 #define VT_ACTIVATE 0x5606 | |
27 #define VT_WAITACTIVE 0x5607 | |
28 | |
29 /* Note: get_console_fb() will need to be moved into a seperate lib section */ | 26 /* Note: get_console_fb() will need to be moved into a seperate lib section */ |
30 int get_console_fd() | 27 int get_console_fd() |
31 { | 28 { |
32 int fd; | 29 int fd; |
30 char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; | |
33 | 31 |
34 fd = open("/dev/console", O_RDWR); | 32 cc = consoles; |
35 if (fd >= 0) return fd; | 33 while (*cc) { |
36 | 34 fd = open(*cc++, O_RDWR); |
37 fd = open("/dev/vc/0", O_RDWR); | 35 if (fd >= 0) return fd; |
38 if (fd >= 0) return fd; | 36 } |
39 | |
40 fd = open("/dev/tty", O_RDWR); | |
41 if (fd >= 0) return fd; | |
42 | 37 |
43 return -1; | 38 return -1; |
44 } | 39 } |
45 | 40 |
46 void chvt_main(void) | 41 void chvt_main(void) |
47 { | 42 { |
48 int vtnum, fd; | 43 int vtnum, fd; |
49 | 44 |
50 | |
51 if(!*toys.optargs) return; | |
52 | |
53 vtnum=atoi(*toys.optargs); | 45 vtnum=atoi(*toys.optargs); |
54 | 46 |
55 fd=get_console_fd(); | 47 fd=get_console_fd(); |
56 if (fd < 0 || ioctl(fd,VT_ACTIVATE,vtnum) | 48 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h |
57 || ioctl(fd,VT_WAITACTIVE,vtnum)) | 49 if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) |
58 { | |
59 perror_exit(NULL); | 50 perror_exit(NULL); |
60 } | |
61 } | 51 } |