Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * setconsole.c - redirect system console output |
| 4 | * |
| 5 | * Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de> |
Bernhard Reutner-Fischer | 6c4dade | 2008-09-25 12:13:34 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 Bernhard Reutner-Fischer |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame^] | 10 | //config:config SETCONSOLE |
| 11 | //config: bool "setconsole" |
| 12 | //config: default y |
| 13 | //config: select PLATFORM_LINUX |
| 14 | //config: help |
| 15 | //config: This program redirects the system console to another device, |
| 16 | //config: like the current tty while logged in via telnet. |
| 17 | //config: |
| 18 | //config:config FEATURE_SETCONSOLE_LONG_OPTIONS |
| 19 | //config: bool "Enable long options" |
| 20 | //config: default y |
| 21 | //config: depends on SETCONSOLE && LONG_OPTS |
| 22 | //config: help |
| 23 | //config: Support long options for the setconsole applet. |
| 24 | |
| 25 | //applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP)) |
| 26 | |
| 27 | //kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 28 | |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 29 | //usage:#define setconsole_trivial_usage |
| 30 | //usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]" |
| 31 | //usage:#define setconsole_full_usage "\n\n" |
| 32 | //usage: "Redirect system console output to DEVICE (default: /dev/tty)\n" |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 33 | //usage: "\n -r Reset output to /dev/console" |
| 34 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 35 | #include "libbb.h" |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 36 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 37 | int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 38 | int setconsole_main(int argc UNUSED_PARAM, char **argv) |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 39 | { |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 40 | const char *device = CURRENT_TTY; |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 41 | bool reset; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 42 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 43 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 44 | static const char setconsole_longopts[] ALIGN1 = |
| 45 | "reset\0" No_argument "r" |
| 46 | ; |
Denis Vlasenko | bdc88fd | 2007-07-23 17:14:14 +0000 | [diff] [blame] | 47 | applet_long_options = setconsole_longopts; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 48 | #endif |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 49 | /* at most one non-option argument */ |
| 50 | opt_complementary = "?1"; |
| 51 | reset = getopt32(argv, "r"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 52 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 53 | argv += 1 + reset; |
| 54 | if (*argv) { |
| 55 | device = *argv; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 56 | } else { |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 57 | if (reset) |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 58 | device = DEV_CONSOLE; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Peter Korsgaard | 8dc6195 | 2011-05-26 17:51:37 +0200 | [diff] [blame] | 61 | xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 62 | return EXIT_SUCCESS; |
| 63 | } |