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 | * |
| 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 | |
| 22 | #include <sys/ioctl.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <fcntl.h> |
| 26 | #include <stdio.h> |
Rob Landley | b7128c6 | 2005-09-11 01:05:30 +0000 | [diff] [blame] | 27 | #include <getopt.h> /* struct option */ |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 28 | |
| 29 | #include "busybox.h" |
| 30 | |
| 31 | static const struct option setconsole_long_options[] = { |
| 32 | { "reset", 0, NULL, 'r' }, |
| 33 | { 0, 0, 0, 0 } |
| 34 | }; |
| 35 | |
| 36 | #define OPT_SETCONS_RESET 1 |
| 37 | |
| 38 | int setconsole_main(int argc, char **argv) |
| 39 | { |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 40 | unsigned long flags; |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 41 | const char *device = CURRENT_TTY; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 42 | |
| 43 | bb_applet_long_options = setconsole_long_options; |
| 44 | flags = bb_getopt_ulflags(argc, argv, "r"); |
| 45 | |
| 46 | if (argc - optind > 1) |
| 47 | bb_show_usage(); |
| 48 | |
| 49 | if (argc - optind == 1) { |
| 50 | if (flags & OPT_SETCONS_RESET) |
| 51 | bb_show_usage(); |
| 52 | device = argv[optind]; |
| 53 | } else { |
| 54 | if (flags & OPT_SETCONS_RESET) |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 55 | device = CONSOLE_DEV; |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 58 | if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) { |
| 59 | bb_perror_msg_and_die("TIOCCONS"); |
Paul Fox | fc2256a | 2005-08-01 18:12:30 +0000 | [diff] [blame] | 60 | } |
| 61 | return EXIT_SUCCESS; |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | Local Variables: |
| 66 | c-file-style: "linux" |
| 67 | c-basic-offset: 4 |
| 68 | tab-width: 4 |
| 69 | End: |
| 70 | */ |