setconsole.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 struct option setconsole_long_options[] = {
  13. { "reset", 0, NULL, 'r' },
  14. { 0, 0, 0, 0 }
  15. };
  16. #endif
  17. #define OPT_SETCONS_RESET 1
  18. int setconsole_main(int argc, char **argv);
  19. int setconsole_main(int argc, char **argv)
  20. {
  21. unsigned long flags;
  22. const char *device = CURRENT_TTY;
  23. #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
  24. applet_long_options = setconsole_long_options;
  25. #endif
  26. flags = getopt32(argc, argv, "r");
  27. if (argc - optind > 1)
  28. bb_show_usage();
  29. if (argc - optind == 1) {
  30. if (flags & OPT_SETCONS_RESET)
  31. bb_show_usage();
  32. device = argv[optind];
  33. } else {
  34. if (flags & OPT_SETCONS_RESET)
  35. device = DEV_CONSOLE;
  36. }
  37. if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
  38. bb_perror_msg_and_die("TIOCCONS");
  39. }
  40. return EXIT_SUCCESS;
  41. }