setconsole.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #include <sys/ioctl.h>
  22. #include <sys/stat.h>
  23. #include <sys/types.h>
  24. #include <fcntl.h>
  25. #include <stdio.h>
  26. #include <getopt.h> /* struct option */
  27. #include "busybox.h"
  28. static const struct option setconsole_long_options[] = {
  29. { "reset", 0, NULL, 'r' },
  30. { 0, 0, 0, 0 }
  31. };
  32. #define OPT_SETCONS_RESET 1
  33. int setconsole_main(int argc, char **argv)
  34. {
  35. unsigned long flags;
  36. const char *device = CURRENT_TTY;
  37. bb_applet_long_options = setconsole_long_options;
  38. flags = bb_getopt_ulflags(argc, argv, "r");
  39. if (argc - optind > 1)
  40. bb_show_usage();
  41. if (argc - optind == 1) {
  42. if (flags & OPT_SETCONS_RESET)
  43. bb_show_usage();
  44. device = argv[optind];
  45. } else {
  46. if (flags & OPT_SETCONS_RESET)
  47. device = CONSOLE_DEV;
  48. }
  49. if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) {
  50. bb_perror_msg_and_die("TIOCCONS");
  51. }
  52. return EXIT_SUCCESS;
  53. }
  54. /*
  55. Local Variables:
  56. c-file-style: "linux"
  57. c-basic-offset: 4
  58. tab-width: 4
  59. End:
  60. */