busybox/console-tools/setconsole.c
Denys Vlasenko ab23381100 setconsole: since SUSE version has no -r, nuke our --reset longopt
Why we even bother inventing incompatible longopts?!

function                                             old     new   delta
packed_usage                                       31734   31738      +4
static.setconsole_longopts                             9       -      -9
setconsole_main                                       94      84     -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 4/-19)             Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-06 18:54:16 +02:00

60 lines
1.6 KiB
C

/* vi: set sw=4 ts=4: */
/*
* setconsole.c - redirect system console output
*
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
* Copyright (C) 2008 Bernhard Reutner-Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETCONSOLE
//config: bool "setconsole (3.7 kb)"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the system console to another device,
//config: like the current tty while logged in via telnet.
//config:
//config:config FEATURE_SETCONSOLE_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on SETCONSOLE && LONG_OPTS
//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
//usage:#define setconsole_trivial_usage
//usage: "[-r] [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"
/* It was a bbox-specific invention, but SUSE does have a similar utility.
* SUSE has no -r option, though.
*/
#include "libbb.h"
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setconsole_main(int argc UNUSED_PARAM, char **argv)
{
const char *device = CURRENT_TTY;
bool reset;
/* at most one non-option argument */
opt_complementary = "?1";
reset = getopt32(argv, "r");
argv += 1 + reset;
if (*argv) {
device = *argv;
} else {
if (reset)
device = DEV_CONSOLE;
}
xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
return EXIT_SUCCESS;
}