summaryrefslogtreecommitdiffstats
path: root/sbin/conscontrol
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2004-06-18 06:33:44 +0000
committergreen <green@FreeBSD.org>2004-06-18 06:33:44 +0000
commit0202a062592d069b559866afd66d44b25d273eeb (patch)
tree01ac4d28e1b4c7b0c31196d100566eed58a3bd93 /sbin/conscontrol
parent70a732669be740b5518c07625a38b3e82a13f6d4 (diff)
downloadFreeBSD-src-0202a062592d069b559866afd66d44b25d273eeb.zip
FreeBSD-src-0202a062592d069b559866afd66d44b25d273eeb.tar.gz
Add to conscontrol(8) "set" and "unset" commands which modify the
virtual console set-up. Specifically, "conscontrol unset" will cause printf(9) output to start going to the console again.
Diffstat (limited to 'sbin/conscontrol')
-rw-r--r--sbin/conscontrol/conscontrol.85
-rw-r--r--sbin/conscontrol/conscontrol.c42
2 files changed, 43 insertions, 4 deletions
diff --git a/sbin/conscontrol/conscontrol.8 b/sbin/conscontrol/conscontrol.8
index 35293b7..ed6d2c9 100644
--- a/sbin/conscontrol/conscontrol.8
+++ b/sbin/conscontrol/conscontrol.8
@@ -89,6 +89,11 @@ the name of the directory may be omitted.
Change the state of console muting.
All console output is suppressed when console muting is
.Cm on .
+.It Cm set Ar console | Cm unset
+Set or unset the virtual console.
+When unset, output from the system, such as the kernel
+.Xr printf 9 ,
+always goes out to the real main console.
.El
.Sh SEE ALSO
.Xr sio 4 ,
diff --git a/sbin/conscontrol/conscontrol.c b/sbin/conscontrol/conscontrol.c
index 4f4f865..d8e5bc5 100644
--- a/sbin/conscontrol/conscontrol.c
+++ b/sbin/conscontrol/conscontrol.c
@@ -29,9 +29,12 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+#include <sys/ttycom.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -43,10 +46,11 @@ static void __dead2
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n",
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: conscontrol [list]",
" conscontrol mute on | off",
- " conscontrol add | delete console");
+ " conscontrol add | delete console",
+ " conscontrol set console | unset");
exit(1);
}
@@ -148,6 +152,32 @@ consdel(char *devnam)
free(buf);
}
+static void
+consset(char *devnam)
+{
+ int ttyfd, flag = 1;
+
+ ttyfd = open(devnam, O_RDONLY);
+ if (ttyfd == -1)
+ err(1, "opening %s", devnam);
+ if (ioctl(ttyfd, TIOCCONS, &flag) == -1)
+ err(1, "could not set %s as virtual console", devnam);
+ close(ttyfd);
+}
+
+static void
+consunset(void)
+{
+ int ttyfd, flag = 0;
+
+ ttyfd = open(DEVDIR "console", O_RDONLY);
+ if (ttyfd == -1)
+ err(1, "opening virtual console");
+ if (ioctl(ttyfd, TIOCCONS, &flag) == -1)
+ err(1, "could not unset virtual console");
+ close(ttyfd);
+}
+
int
main(int argc, char **argv)
{
@@ -158,14 +188,18 @@ main(int argc, char **argv)
argv += optind;
if (argc > 0 && strcmp(argv[0], "list") != 0) {
- if (argc != 2)
+ if (argc == 1 && strcmp(argv[0], "unset") == 0)
+ consunset();
+ else if (argc != 2)
usage();
- if (strcmp(argv[0], "mute") == 0)
+ else if (strcmp(argv[0], "mute") == 0)
consmute(argv[1]);
else if (strcmp(argv[0], "add") == 0)
consadd(argv[1]);
else if (strcmp(argv[0], "delete") == 0)
consdel(argv[1]);
+ else if (strcmp(argv[0], "set") == 0)
+ consset(argv[1]);
else
usage();
}
OpenPOWER on IntegriCloud