3 |
* setconsole.c - redirect system console output |
* setconsole.c - redirect system console output |
4 |
* |
* |
5 |
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de> |
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de> |
6 |
|
* Copyright (C) 2008 Bernhard Reutner-Fischer |
7 |
* |
* |
8 |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 |
*/ |
*/ |
10 |
|
|
11 |
#include "busybox.h" |
#include "libbb.h" |
12 |
|
|
13 |
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
14 |
static const struct option setconsole_long_options[] = { |
int setconsole_main(int argc UNUSED_PARAM, char **argv) |
|
{ "reset", 0, NULL, 'r' }, |
|
|
{ 0, 0, 0, 0 } |
|
|
}; |
|
|
#endif |
|
|
|
|
|
#define OPT_SETCONS_RESET 1 |
|
|
|
|
|
int setconsole_main(int argc, char **argv) |
|
15 |
{ |
{ |
|
unsigned long flags; |
|
16 |
const char *device = CURRENT_TTY; |
const char *device = CURRENT_TTY; |
17 |
|
bool reset; |
18 |
|
|
19 |
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
20 |
applet_long_options = setconsole_long_options; |
static const char setconsole_longopts[] ALIGN1 = |
21 |
|
"reset\0" No_argument "r" |
22 |
|
; |
23 |
|
applet_long_options = setconsole_longopts; |
24 |
#endif |
#endif |
25 |
flags = getopt32(argc, argv, "r"); |
/* at most one non-option argument */ |
26 |
|
opt_complementary = "?1"; |
27 |
if (argc - optind > 1) |
reset = getopt32(argv, "r"); |
28 |
bb_show_usage(); |
|
29 |
|
argv += 1 + reset; |
30 |
if (argc - optind == 1) { |
if (*argv) { |
31 |
if (flags & OPT_SETCONS_RESET) |
device = *argv; |
|
bb_show_usage(); |
|
|
device = argv[optind]; |
|
32 |
} else { |
} else { |
33 |
if (flags & OPT_SETCONS_RESET) |
if (reset) |
34 |
device = CONSOLE_DEV; |
device = DEV_CONSOLE; |
35 |
} |
} |
36 |
|
|
37 |
if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) { |
xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL); |
|
bb_perror_msg_and_die("TIOCCONS"); |
|
|
} |
|
38 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
39 |
} |
} |