blob: 71fe928dabfd2a1c50581193fc768ec5f8ec4bce [file] [log] [blame]
Paul Foxfc2256a2005-08-01 18:12:30 +00001/* 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-Fischerb1629b12006-05-19 19:29:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Paul Foxfc2256a2005-08-01 18:12:30 +00008 */
9
Paul Foxfc2256a2005-08-01 18:12:30 +000010#include "busybox.h"
11
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000012#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Paul Foxfc2256a2005-08-01 18:12:30 +000013static const struct option setconsole_long_options[] = {
14 { "reset", 0, NULL, 'r' },
15 { 0, 0, 0, 0 }
16};
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000017#endif
Paul Foxfc2256a2005-08-01 18:12:30 +000018
19#define OPT_SETCONS_RESET 1
20
21int setconsole_main(int argc, char **argv)
22{
Paul Foxfc2256a2005-08-01 18:12:30 +000023 unsigned long flags;
Rob Landley9f0e00f2005-09-08 03:27:06 +000024 const char *device = CURRENT_TTY;
Paul Foxfc2256a2005-08-01 18:12:30 +000025
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000026#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Paul Foxfc2256a2005-08-01 18:12:30 +000027 bb_applet_long_options = setconsole_long_options;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000028#endif
Paul Foxfc2256a2005-08-01 18:12:30 +000029 flags = bb_getopt_ulflags(argc, argv, "r");
30
31 if (argc - optind > 1)
32 bb_show_usage();
33
34 if (argc - optind == 1) {
35 if (flags & OPT_SETCONS_RESET)
36 bb_show_usage();
37 device = argv[optind];
38 } else {
39 if (flags & OPT_SETCONS_RESET)
Rob Landley9f0e00f2005-09-08 03:27:06 +000040 device = CONSOLE_DEV;
Paul Foxfc2256a2005-08-01 18:12:30 +000041 }
42
Rob Landleyd921b2e2006-08-03 15:41:12 +000043 if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
Rob Landley9f0e00f2005-09-08 03:27:06 +000044 bb_perror_msg_and_die("TIOCCONS");
Paul Foxfc2256a2005-08-01 18:12:30 +000045 }
46 return EXIT_SUCCESS;
47}