aboutsummaryrefslogtreecommitdiff
path: root/console-tools/setconsole.c
diff options
context:
space:
mode:
Diffstat (limited to 'console-tools/setconsole.c')
-rw-r--r--console-tools/setconsole.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c
index ad0f756ca..bad2b76e4 100644
--- a/console-tools/setconsole.c
+++ b/console-tools/setconsole.c
@@ -12,23 +12,31 @@
12//config: default y 12//config: default y
13//config: select PLATFORM_LINUX 13//config: select PLATFORM_LINUX
14//config: help 14//config: help
15//config: This program redirects the system console to another device, 15//config: Redirect writes to /dev/console to another device,
16//config: like the current tty while logged in via telnet. 16//config: like the current tty while logged in via telnet.
17//config: This does not redirect kernel log, only writes
18//config: from user space.
17//config: 19//config:
18//config:config FEATURE_SETCONSOLE_LONG_OPTIONS 20//config:config FEATURE_SETCONSOLE_LONG_OPTIONS
19//config: bool "Enable long options" 21//config: bool "Enable long options"
20//config: default y 22//config: default y
21//config: depends on SETCONSOLE && LONG_OPTS 23//config: depends on SETCONSOLE && LONG_OPTS
22 24
23//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP)) 25//applet:IF_SETCONSOLE(APPLET_NOEXEC(setconsole, setconsole, BB_DIR_SBIN, BB_SUID_DROP, setconsole))
24 26
25//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o 27//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
26 28
27//usage:#define setconsole_trivial_usage 29//usage:#define setconsole_trivial_usage
28//usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]" 30//usage: "[-r] [DEVICE]"
29//usage:#define setconsole_full_usage "\n\n" 31//usage:#define setconsole_full_usage "\n\n"
30//usage: "Redirect system console output to DEVICE (default: /dev/tty)\n" 32//usage: "Make writes to /dev/console appear on DEVICE (default: /dev/tty)."
31//usage: "\n -r Reset output to /dev/console" 33//usage: "\n""Does not redirect kernel log output or reads from /dev/console."
34//usage: "\n"
35//usage: "\n"" -r Reset: writes to /dev/console go to kernel log tty(s)"
36
37/* It was a bbox-specific invention, but SUSE does have a similar utility.
38 * SUSE has no -r option, though.
39 */
32 40
33#include "libbb.h" 41#include "libbb.h"
34 42
@@ -36,17 +44,10 @@ int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
36int setconsole_main(int argc UNUSED_PARAM, char **argv) 44int setconsole_main(int argc UNUSED_PARAM, char **argv)
37{ 45{
38 const char *device = CURRENT_TTY; 46 const char *device = CURRENT_TTY;
39 bool reset; 47 int reset;
40 48
41#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
42 static const char setconsole_longopts[] ALIGN1 =
43 "reset\0" No_argument "r"
44 ;
45 applet_long_options = setconsole_longopts;
46#endif
47 /* at most one non-option argument */ 49 /* at most one non-option argument */
48 opt_complementary = "?1"; 50 reset = getopt32(argv, "^" "r" "\0" "?1");
49 reset = getopt32(argv, "r");
50 51
51 argv += 1 + reset; 52 argv += 1 + reset;
52 if (*argv) { 53 if (*argv) {
@@ -56,6 +57,9 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
56 device = DEV_CONSOLE; 57 device = DEV_CONSOLE;
57 } 58 }
58 59
60//TODO: fails if TIOCCONS redir is already active to some tty.
61//I think SUSE version first does TIOCCONS on /dev/console fd (iow: resets)
62//then TIOCCONS to new tty?
59 xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL); 63 xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
60 return EXIT_SUCCESS; 64 return EXIT_SUCCESS;
61} 65}