setconsole.c 926 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 Fischer
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  9. */
  10. #include "libbb.h"
  11. int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  12. int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv)
  13. {
  14. const char *device = CURRENT_TTY;
  15. bool reset;
  16. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  17. static const char setconsole_longopts[] ALIGN1 =
  18. "reset\0" No_argument "r"
  19. ;
  20. applet_long_options = setconsole_longopts;
  21. #endif
  22. /* at most one non-option argument */
  23. opt_complementary = "?1";
  24. reset = getopt32(argv, "r");
  25. argv += 1 + reset;
  26. if (*argv) {
  27. device = *argv;
  28. } else {
  29. if (reset)
  30. device = DEV_CONSOLE;
  31. }
  32. xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
  33. return EXIT_SUCCESS;
  34. }