setconsole.c 1020 B

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