Replace current verbose GPL stuff in libbb/*.c with one-line GPL boilerplate.
[oweals/busybox.git] / console-tools / setconsole.c
1 /* 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  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 #include <sys/ioctl.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <getopt.h> /* struct option */
16
17 #include "busybox.h"
18
19 #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
20 static const struct option setconsole_long_options[] = {
21         { "reset", 0, NULL, 'r' },
22         { 0, 0, 0, 0 }
23 };
24 #endif
25
26 #define OPT_SETCONS_RESET 1
27
28 int setconsole_main(int argc, char **argv)
29 {
30         unsigned long flags;
31         const char *device = CURRENT_TTY;
32
33 #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
34         bb_applet_long_options = setconsole_long_options;
35 #endif
36         flags = bb_getopt_ulflags(argc, argv, "r");
37
38         if (argc - optind > 1)
39                 bb_show_usage();
40
41         if (argc - optind == 1) {
42                 if (flags & OPT_SETCONS_RESET)
43                         bb_show_usage();
44                 device = argv[optind];
45         } else {
46                 if (flags & OPT_SETCONS_RESET)
47                         device = CONSOLE_DEV;
48         }
49
50         if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) {
51                 bb_perror_msg_and_die("TIOCCONS");
52         }
53         return EXIT_SUCCESS;
54 }