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 | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 6 | * Copyright (C) 2008 Bernhard Fischer |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 7 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 12 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 13 | int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 14 | int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv) |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 15 | { |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 16 | const char *device = CURRENT_TTY; |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 17 | bool reset; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 18 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 19 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 20 | static const char setconsole_longopts[] ALIGN1 = |
| 21 | "reset\0" No_argument "r" |
| 22 | ; |
Denis Vlasenko | bdc88fd | 2007-07-23 17:14:14 +0000 | [diff] [blame] | 23 | applet_long_options = setconsole_longopts; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 24 | #endif |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 25 | /* at most one non-option argument */ |
| 26 | opt_complementary = "?1"; |
| 27 | reset = getopt32(argv, "r"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 28 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 29 | argv += 1 + reset; |
| 30 | if (*argv) { |
| 31 | device = *argv; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 32 | } else { |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 33 | if (reset) |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 34 | device = DEV_CONSOLE; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 37 | xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 38 | return EXIT_SUCCESS; |
| 39 | } |