2 * Copyright (c) 2001 Jonathan Lemon <jlemon@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
44 (void)fprintf(stderr, "%s\n%s\n%s\n",
45 "usage: conscontrol [list]",
46 " conscontrol mute on | off",
47 " conscontrol add | delete console");
56 char *buf, *p, *avail;
59 if (sysctlbyname("kern.consmute", &mute, &len, NULL, 0) == -1)
60 err(1, "kern.consmute retrieval failed");
61 if (sysctlbyname("kern.console", NULL, &len, NULL, 0) == -1)
62 err(1, "kern.console estimate failed");
63 if ((buf = malloc(len)) == NULL)
64 errx(1, "kern.console malloc failed");
65 if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1)
66 err(1, "kern.console retrieval failed");
67 if ((avail = strchr(buf, '/')) == NULL)
68 errx(1, "kern.console format not understood");
72 *--p = '\0'; /* remove trailing ',' */
73 p = avail + strlen(avail);
75 *--p = '\0'; /* remove trailing ',' */
76 printf("Configured: %s\n", buf);
77 printf(" Available: %s\n", avail);
78 printf(" Muting: %s\n", mute ? "on" : "off");
83 consmute(const char *onoff)
88 if (strcmp(onoff, "on") == 0)
90 else if (strcmp(onoff, "off") == 0)
95 if (sysctlbyname("kern.consmute", NULL, NULL, &mute, len) == -1)
96 err(1, "could not change console muting");
100 consadd(char *devnam)
104 len = strlen(devnam);
105 if (sysctlbyname("kern.console", NULL, NULL, devnam, len) == -1)
106 err(1, "could not add %s as a console", devnam);
110 consdel(const char *devnam)
115 len = strlen(devnam) + sizeof("-");
116 if ((buf = malloc(len)) == NULL)
117 errx(1, "malloc failed");
119 strcpy(buf + 1, devnam);
120 if (sysctlbyname("kern.console", NULL, NULL, buf, len) == -1)
121 err(1, "could not remove %s as a console", devnam);
126 main(int argc, char **argv)
129 if (getopt(argc, argv, "") != -1)
134 if (argc > 0 && strcmp(argv[0], "list") != 0) {
137 if (strcmp(argv[0], "mute") == 0)
139 else if (strcmp(argv[0], "add") == 0)
141 else if (strcmp(argv[0], "delete") == 0)