Mercurial > hg > toybox
annotate toys/other/chvt.c @ 656:6df4ccc0acbe
Regularize command headers, update links to standards documents.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 18:08:51 -0500 |
parents | 2986aa63a021 |
children | 786841fdb1e0 |
rev | line source |
---|---|
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
2 * |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
3 * chvt.c - switch virtual terminals |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
4 * |
229 | 5 * Copyright (C) 2008 David Anders <danders@amltd.com> |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
6 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
7 USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN)) |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
8 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
9 config CHVT |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
10 bool "chvt" |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
11 default y |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
12 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
13 usage: chvt N |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
14 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
15 Change to virtual terminal number N. (This only works in text mode.) |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
16 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
17 Virtual terminals are the Linux VGA text mode displays, ordinarily |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
18 switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
19 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
20 */ |
229 | 21 |
22 #include "toys.h" | |
23 | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
24 /* Note: get_console_fb() will need to be moved into a seperate lib section */ |
229 | 25 int get_console_fd() |
26 { | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
27 int fd; |
316
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
28 char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; |
229 | 29 |
316
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
30 cc = consoles; |
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
31 while (*cc) { |
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
32 fd = open(*cc++, O_RDWR); |
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
33 if (fd >= 0) return fd; |
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
34 } |
229 | 35 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
36 return -1; |
229 | 37 } |
38 | |
39 void chvt_main(void) | |
40 { | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
41 int vtnum, fd; |
229 | 42 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
43 vtnum=atoi(*toys.optargs); |
229 | 44 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
45 fd=get_console_fd(); |
316
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
46 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h |
17c0a2013852
Tighten up chvt, save a few bytes.
Rob Landley <rob@landley.net>
parents:
246
diff
changeset
|
47 if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) |
246
d9ea4ca7ae8c
Have chvt print an error message (and exit with error) when it fails.
Rob Landley <rob@landley.net>
parents:
244
diff
changeset
|
48 perror_exit(NULL); |
229 | 49 } |