3
0

setconsole.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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"
  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. //applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
  23. //kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
  24. //usage:#define setconsole_trivial_usage
  25. //usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
  26. //usage:#define setconsole_full_usage "\n\n"
  27. //usage: "Redirect system console output to DEVICE (default: /dev/tty)\n"
  28. //usage: "\n -r Reset output to /dev/console"
  29. #include "libbb.h"
  30. int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  31. int setconsole_main(int argc UNUSED_PARAM, char **argv)
  32. {
  33. const char *device = CURRENT_TTY;
  34. bool reset;
  35. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  36. static const char setconsole_longopts[] ALIGN1 =
  37. "reset\0" No_argument "r"
  38. ;
  39. applet_long_options = setconsole_longopts;
  40. #endif
  41. /* at most one non-option argument */
  42. opt_complementary = "?1";
  43. reset = getopt32(argv, "r");
  44. argv += 1 + reset;
  45. if (*argv) {
  46. device = *argv;
  47. } else {
  48. if (reset)
  49. device = DEV_CONSOLE;
  50. }
  51. xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
  52. return EXIT_SUCCESS;
  53. }