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> |
| 6 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 7 | * 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] | 8 | */ |
| 9 | |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 10 | #include "busybox.h" |
| 11 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 12 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 13 | static const struct option setconsole_long_options[] = { |
| 14 | { "reset", 0, NULL, 'r' }, |
| 15 | { 0, 0, 0, 0 } |
| 16 | }; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 17 | #endif |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 18 | |
| 19 | #define OPT_SETCONS_RESET 1 |
| 20 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 21 | int setconsole_main(int argc, char **argv); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 22 | int setconsole_main(int argc, char **argv) |
| 23 | { |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 24 | unsigned long flags; |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 25 | const char *device = CURRENT_TTY; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 26 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 27 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 28 | applet_long_options = setconsole_long_options; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 29 | #endif |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 30 | flags = getopt32(argc, argv, "r"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 31 | |
| 32 | if (argc - optind > 1) |
| 33 | bb_show_usage(); |
| 34 | |
| 35 | if (argc - optind == 1) { |
| 36 | if (flags & OPT_SETCONS_RESET) |
| 37 | bb_show_usage(); |
| 38 | device = argv[optind]; |
| 39 | } else { |
| 40 | if (flags & OPT_SETCONS_RESET) |
Denis Vlasenko | ec27feb | 2007-02-17 15:52:02 +0000 | [diff] [blame] | 41 | device = DEV_CONSOLE; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 44 | if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) { |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 45 | bb_perror_msg_and_die("TIOCCONS"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 46 | } |
| 47 | return EXIT_SUCCESS; |
| 48 | } |