blob: 59c83361cc6d43394585afe1344166b1fb106d24 [file] [log] [blame]
Paul Foxfc2256a2005-08-01 18:12:30 +00001/* 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-Fischer6c4dade2008-09-25 12:13:34 +00006 * Copyright (C) 2008 Bernhard Reutner-Fischer
Paul Foxfc2256a2005-08-01 18:12:30 +00007 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02008 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Paul Foxfc2256a2005-08-01 18:12:30 +00009 */
10
Pere Orga55068c42011-03-27 23:42:28 +020011//usage:#define setconsole_trivial_usage
12//usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
13//usage:#define setconsole_full_usage "\n\n"
14//usage: "Redirect system console output to DEVICE (default: /dev/tty)\n"
15//usage: "\nOptions:"
16//usage: "\n -r Reset output to /dev/console"
17
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000018#include "libbb.h"
Paul Foxfc2256a2005-08-01 18:12:30 +000019
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000020int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000021int setconsole_main(int argc UNUSED_PARAM, char **argv)
Paul Foxfc2256a2005-08-01 18:12:30 +000022{
Rob Landley9f0e00f2005-09-08 03:27:06 +000023 const char *device = CURRENT_TTY;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000024 bool reset;
Paul Foxfc2256a2005-08-01 18:12:30 +000025
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000026#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000027 static const char setconsole_longopts[] ALIGN1 =
28 "reset\0" No_argument "r"
29 ;
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000030 applet_long_options = setconsole_longopts;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000031#endif
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000032 /* at most one non-option argument */
33 opt_complementary = "?1";
34 reset = getopt32(argv, "r");
Paul Foxfc2256a2005-08-01 18:12:30 +000035
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000036 argv += 1 + reset;
37 if (*argv) {
38 device = *argv;
Paul Foxfc2256a2005-08-01 18:12:30 +000039 } else {
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000040 if (reset)
Denis Vlasenkoec27feb2007-02-17 15:52:02 +000041 device = DEV_CONSOLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000042 }
43
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000044 xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
Paul Foxfc2256a2005-08-01 18:12:30 +000045 return EXIT_SUCCESS;
46}