blob: 8765a7c2edc4ef1c97df6927dbed1380a3d196e7 [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 Vlasenkob6adbf12007-05-26 19:00:18 +000010#include "libbb.h"
Paul Foxfc2256a2005-08-01 18:12:30 +000011
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000012#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000013static const char setconsole_longopts[] ALIGN1 =
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000014 "reset\0" No_argument "r"
Denis Vlasenko990d0f62007-07-24 15:54:42 +000015 ;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000016#endif
Paul Foxfc2256a2005-08-01 18:12:30 +000017
18#define OPT_SETCONS_RESET 1
19
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000020int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000021int 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
Denis Vlasenkobdc88fd2007-07-23 17:14:14 +000027 applet_long_options = setconsole_longopts;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000028#endif
Denis Vlasenkofe7cd642007-08-18 15:32:12 +000029 flags = getopt32(argv, "r");
Paul Foxfc2256a2005-08-01 18:12:30 +000030
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)
Denis Vlasenkoec27feb2007-02-17 15:52:02 +000040 device = DEV_CONSOLE;
Paul Foxfc2256a2005-08-01 18:12:30 +000041 }
42
Denis Vlasenkofb79a2e2007-07-14 22:07:14 +000043 xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
Paul Foxfc2256a2005-08-01 18:12:30 +000044 return EXIT_SUCCESS;
45}