2005-08-01 18:12:30 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* setconsole.c - redirect system console output
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
|
2008-09-25 12:13:34 +00:00
|
|
|
* Copyright (C) 2008 Bernhard Reutner-Fischer
|
2005-08-01 18:12:30 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2005-08-01 18:12:30 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-27 21:42:28 +00:00
|
|
|
//usage:#define setconsole_trivial_usage
|
|
|
|
//usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
|
|
|
|
//usage:#define setconsole_full_usage "\n\n"
|
|
|
|
//usage: "Redirect system console output to DEVICE (default: /dev/tty)\n"
|
|
|
|
//usage: "\n -r Reset output to /dev/console"
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2005-08-01 18:12:30 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int setconsole_main(int argc UNUSED_PARAM, char **argv)
|
2005-08-01 18:12:30 +00:00
|
|
|
{
|
2005-09-08 03:27:06 +00:00
|
|
|
const char *device = CURRENT_TTY;
|
2008-05-19 08:18:50 +00:00
|
|
|
bool reset;
|
2005-08-01 18:12:30 +00:00
|
|
|
|
2006-05-26 20:19:22 +00:00
|
|
|
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
2008-05-19 08:18:50 +00:00
|
|
|
static const char setconsole_longopts[] ALIGN1 =
|
|
|
|
"reset\0" No_argument "r"
|
|
|
|
;
|
2007-07-23 17:14:14 +00:00
|
|
|
applet_long_options = setconsole_longopts;
|
2006-05-26 20:19:22 +00:00
|
|
|
#endif
|
2008-05-19 08:18:50 +00:00
|
|
|
/* at most one non-option argument */
|
|
|
|
opt_complementary = "?1";
|
|
|
|
reset = getopt32(argv, "r");
|
2005-08-01 18:12:30 +00:00
|
|
|
|
2008-05-19 08:18:50 +00:00
|
|
|
argv += 1 + reset;
|
|
|
|
if (*argv) {
|
|
|
|
device = *argv;
|
2005-08-01 18:12:30 +00:00
|
|
|
} else {
|
2008-05-19 08:18:50 +00:00
|
|
|
if (reset)
|
2007-02-17 15:52:02 +00:00
|
|
|
device = DEV_CONSOLE;
|
2005-08-01 18:12:30 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 15:51:37 +00:00
|
|
|
xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
|
2005-08-01 18:12:30 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|