3
0

setconsole.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. #include <getopt.h>
  10. #include "libbb.h"
  11. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  12. static const char setconsole_longopts[] ALIGN1 =
  13. "reset\0" No_argument "r"
  14. ;
  15. #endif
  16. #define OPT_SETCONS_RESET 1
  17. int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  18. int setconsole_main(int argc, char **argv)
  19. {
  20. unsigned long flags;
  21. const char *device = CURRENT_TTY;
  22. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  23. applet_long_options = setconsole_longopts;
  24. #endif
  25. flags = getopt32(argv, "r");
  26. if (argc - optind > 1)
  27. bb_show_usage();
  28. if (argc - optind == 1) {
  29. if (flags & OPT_SETCONS_RESET)
  30. bb_show_usage();
  31. device = argv[optind];
  32. } else {
  33. if (flags & OPT_SETCONS_RESET)
  34. device = DEV_CONSOLE;
  35. }
  36. xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
  37. return EXIT_SUCCESS;
  38. }