setconsole.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. //usage:#define setconsole_trivial_usage
  11. //usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"
  12. //usage:#define setconsole_full_usage "\n\n"
  13. //usage: "Redirect system console output to DEVICE (default: /dev/tty)\n"
  14. //usage: "\n -r Reset output to /dev/console"
  15. #include "libbb.h"
  16. int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  17. int setconsole_main(int argc UNUSED_PARAM, char **argv)
  18. {
  19. const char *device = CURRENT_TTY;
  20. bool reset;
  21. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  22. static const char setconsole_longopts[] ALIGN1 =
  23. "reset\0" No_argument "r"
  24. ;
  25. applet_long_options = setconsole_longopts;
  26. #endif
  27. /* at most one non-option argument */
  28. opt_complementary = "?1";
  29. reset = getopt32(argv, "r");
  30. argv += 1 + reset;
  31. if (*argv) {
  32. device = *argv;
  33. } else {
  34. if (reset)
  35. device = DEV_CONSOLE;
  36. }
  37. xioctl(xopen(device, O_WRONLY), TIOCCONS, NULL);
  38. return EXIT_SUCCESS;
  39. }