setconsole: since SUSE version has no -r, nuke our --reset longopt
[oweals/busybox.git] / console-tools / setconsole.c
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  *  Copyright (C) 2008 Bernhard Reutner-Fischer
7  *
8  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9  */
10 //config:config SETCONSOLE
11 //config:       bool "setconsole (3.7 kb)"
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
23 //applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
24
25 //kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
26
27 //usage:#define setconsole_trivial_usage
28 //usage:       "[-r] [DEVICE]"
29 //usage:#define setconsole_full_usage "\n\n"
30 //usage:       "Redirect system console output to DEVICE (default: /dev/tty)\n"
31 //usage:     "\n        -r      Reset output to /dev/console"
32
33 /* It was a bbox-specific invention, but SUSE does have a similar utility.
34  * SUSE has no -r option, though.
35  */
36
37 #include "libbb.h"
38
39 int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40 int setconsole_main(int argc UNUSED_PARAM, char **argv)
41 {
42         const char *device = CURRENT_TTY;
43         bool reset;
44
45         /* at most one non-option argument */
46         opt_complementary = "?1";
47         reset = getopt32(argv, "r");
48
49         argv += 1 + reset;
50         if (*argv) {
51                 device = *argv;
52         } else {
53                 if (reset)
54                         device = DEV_CONSOLE;
55         }
56
57         xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
58         return EXIT_SUCCESS;
59 }