shell: add TODO comment about BASE#nnn literals
[oweals/busybox.git] / console-tools / setconsole.c
index 87265baf8e65219b6fa08bfffda4aa94815d7501..0bc58724147cf3234eaa7b3cb6bb4aea0e6bb2a0 100644 (file)
@@ -1,12 +1,42 @@
 /* vi: set sw=4 ts=4: */
 /*
- *  setconsole.c - redirect system console output
+ * setconsole.c - redirect system console output
  *
- *  Copyright (C) 2004,2005  Enrik Berkhan <Enrik.Berkhan@inka.de>
- *  Copyright (C) 2008 Bernhard Reutner-Fischer
+ * 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.6 kb)"
+//config:      default y
+//config:      select PLATFORM_LINUX
+//config:      help
+//config:      Redirect writes to /dev/console to another device,
+//config:      like the current tty while logged in via telnet.
+//config:      This does not redirect kernel log, only writes
+//config:      from user space.
+//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_NOEXEC(setconsole, setconsole, BB_DIR_SBIN, BB_SUID_DROP, setconsole))
+
+//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
+
+//usage:#define setconsole_trivial_usage
+//usage:       "[-r] [DEVICE]"
+//usage:#define setconsole_full_usage "\n\n"
+//usage:       "Make writes to /dev/console appear on DEVICE (default: /dev/tty)."
+//usage:   "\n""Does not redirect kernel log output or reads from /dev/console."
+//usage:   "\n"
+//usage:   "\n""       -r      Reset: writes to /dev/console go to kernel log tty(s)"
+
+/* It was a bbox-specific invention, but SUSE does have a similar utility.
+ * SUSE has no -r option, though.
+ */
 
 #include "libbb.h"
 
@@ -14,17 +44,10 @@ 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;
-
-#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
-       static const char setconsole_longopts[] ALIGN1 =
-               "reset\0" No_argument "r"
-               ;
-       applet_long_options = setconsole_longopts;
-#endif
+       int reset;
+
        /* at most one non-option argument */
-       opt_complementary = "?1";
-       reset = getopt32(argv, "r");
+       reset = getopt32(argv, "^" "r" "\0" "?1");
 
        argv += 1 + reset;
        if (*argv) {
@@ -34,6 +57,9 @@ int setconsole_main(int argc UNUSED_PARAM, char **argv)
                        device = DEV_CONSOLE;
        }
 
-       xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
+//TODO: fails if TIOCCONS redir is already active to some tty.
+//I think SUSE version first does TIOCCONS on /dev/console fd (iow: resets)
+//then TIOCCONS to new tty?
+       xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
        return EXIT_SUCCESS;
 }