blob: 0aa1d3a3525f6bdc902277714baa28aec6ec8730 [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
Denis Vlasenkof1a71412007-04-10 23:32:37 +000010#include <getopt.h>
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Paul Foxfc2256a2005-08-01 18:12:30 +000012
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000013#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000014static const char setconsole_longopts[] ALIGN1 =
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000015 "reset\0" No_argument "r"
Denis Vlasenko990d0f62007-07-24 15:54:42 +000016 ;
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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000021int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000022int setconsole_main(int argc, char **argv)
23{
Paul Foxfc2256a2005-08-01 18:12:30 +000024 unsigned long flags;
Rob Landley9f0e00f2005-09-08 03:27:06 +000025 const char *device = CURRENT_TTY;
Paul Foxfc2256a2005-08-01 18:12:30 +000026
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000027#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000028 applet_long_options = setconsole_longopts;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000029#endif
Denis Vlasenkofe7cd642007-08-18 15:32:12 +000030 flags = getopt32(argv, "r");
Paul Foxfc2256a2005-08-01 18:12:30 +000031
32 if (argc - optind > 1)
33 bb_show_usage();
34
35 if (argc - optind == 1) {
36 if (flags & OPT_SETCONS_RESET)
37 bb_show_usage();
38 device = argv[optind];
39 } else {
40 if (flags & OPT_SETCONS_RESET)
Denis Vlasenkoec27feb2007-02-17 15:52:02 +000041 device = DEV_CONSOLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000042 }
43
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000044 xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
Paul Foxfc2256a2005-08-01 18:12:30 +000045 return EXIT_SUCCESS;
46}