Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 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 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <sys/ioctl.h> |
| 11 | #include <sys/stat.h> |
| 12 | #include <sys/types.h> |
| 13 | #include <fcntl.h> |
| 14 | #include <stdio.h> |
Rob Landley | b7128c6 | 2005-09-11 01:05:30 +0000 | [diff] [blame] | 15 | #include <getopt.h> /* struct option */ |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 16 | |
| 17 | #include "busybox.h" |
| 18 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 19 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 20 | static const struct option setconsole_long_options[] = { |
| 21 | { "reset", 0, NULL, 'r' }, |
| 22 | { 0, 0, 0, 0 } |
| 23 | }; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 24 | #endif |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 25 | |
| 26 | #define OPT_SETCONS_RESET 1 |
| 27 | |
| 28 | int setconsole_main(int argc, char **argv) |
| 29 | { |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 30 | unsigned long flags; |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 31 | const char *device = CURRENT_TTY; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 32 | |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 33 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 34 | bb_applet_long_options = setconsole_long_options; |
Bernhard Reutner-Fischer | 01d23ad | 2006-05-26 20:19:22 +0000 | [diff] [blame] | 35 | #endif |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 36 | flags = bb_getopt_ulflags(argc, argv, "r"); |
| 37 | |
| 38 | if (argc - optind > 1) |
| 39 | bb_show_usage(); |
| 40 | |
| 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) |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 47 | device = CONSOLE_DEV; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 50 | if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) { |
| 51 | bb_perror_msg_and_die("TIOCCONS"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 52 | } |
| 53 | return EXIT_SUCCESS; |
| 54 | } |