blob: 82fe83f228b3b90885a21a4f40077befa763a7c8 [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>
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +00006 * Copyright (C) 2008 Bernhard Fischer
Paul Foxfc2256a2005-08-01 18:12:30 +00007 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Paul Foxfc2256a2005-08-01 18:12:30 +00009 */
10
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Paul Foxfc2256a2005-08-01 18:12:30 +000012
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000013int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000014int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv)
Paul Foxfc2256a2005-08-01 18:12:30 +000015{
Rob Landley9f0e00f2005-09-08 03:27:06 +000016 const char *device = CURRENT_TTY;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000017 bool reset;
Paul Foxfc2256a2005-08-01 18:12:30 +000018
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000019#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000020 static const char setconsole_longopts[] ALIGN1 =
21 "reset\0" No_argument "r"
22 ;
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000023 applet_long_options = setconsole_longopts;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000024#endif
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000025 /* at most one non-option argument */
26 opt_complementary = "?1";
27 reset = getopt32(argv, "r");
Paul Foxfc2256a2005-08-01 18:12:30 +000028
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000029 argv += 1 + reset;
30 if (*argv) {
31 device = *argv;
Paul Foxfc2256a2005-08-01 18:12:30 +000032 } else {
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000033 if (reset)
Denis Vlasenkoec27feb2007-02-17 15:52:02 +000034 device = DEV_CONSOLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000035 }
36
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000037 xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
Paul Foxfc2256a2005-08-01 18:12:30 +000038 return EXIT_SUCCESS;
39}