Mercurial > hg > toybox
comparison toys/chvt.c @ 229:87390c3700c1
Add chvt from David Anders.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 06 Jan 2008 16:01:11 -0600 |
parents | |
children | d4176f3f3835 |
comparison
equal
deleted
inserted
replaced
228:90f763207f56 | 229:87390c3700c1 |
---|---|
1 /* vi: set sw=4 ts=4: */ | |
2 /* | |
3 * chvt.c switch virtual terminals | |
4 * | |
5 * Copyright (C) 2008 David Anders <danders@amltd.com> | |
6 * | |
7 */ | |
8 | |
9 #include "toys.h" | |
10 | |
11 #define VT_ACTIVATE 0x5606 | |
12 #define VT_WAITACTIVE 0x5607 | |
13 | |
14 /* note get_console_fb() will need to be moved into a seperate lib section */ | |
15 int get_console_fd() | |
16 { | |
17 int fd; | |
18 | |
19 fd = open("/dev/console", O_RDWR); | |
20 if (fd >= 0) | |
21 return fd; | |
22 | |
23 fd = open("/dev/vc/0", O_RDWR); | |
24 if (fd >= 0) | |
25 return fd; | |
26 | |
27 fd = open("/dev/tty", O_RDWR); | |
28 if (fd >= 0) | |
29 return fd; | |
30 | |
31 return -1; | |
32 } | |
33 | |
34 void chvt_main(void) | |
35 { | |
36 int vtnum,fd; | |
37 | |
38 | |
39 if(!*toys.optargs) | |
40 return; | |
41 | |
42 vtnum=atoi(*toys.optargs); | |
43 | |
44 fd=get_console_fd(); | |
45 if (fd < 0) | |
46 return; | |
47 | |
48 if (ioctl(fd,VT_ACTIVATE,vtnum)) | |
49 return; | |
50 | |
51 if (ioctl(fd,VT_WAITACTIVE,vtnum)) | |
52 return; | |
53 | |
54 } |