blob: 7ddef697c66f25d7087b60033e847058317f58d2 [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
Denis Vlasenko06af2162007-02-03 17:28:39 +000021int setconsole_main(int argc, char **argv);
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 Vlasenko67b23e62006-10-03 21:00:06 +000028 applet_long_options = setconsole_long_options;
Bernhard Reutner-Fischer01d23ad2006-05-26 20:19:22 +000029#endif
Denis Vlasenko67b23e62006-10-03 21:00:06 +000030 flags = getopt32(argc, 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
Rob Landleyd921b2e2006-08-03 15:41:12 +000044 if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
Rob Landley9f0e00f2005-09-08 03:27:06 +000045 bb_perror_msg_and_die("TIOCCONS");
Paul Foxfc2256a2005-08-01 18:12:30 +000046 }
47 return EXIT_SUCCESS;
48}