summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjlemon <jlemon@FreeBSD.org>2001-10-25 16:41:38 +0000
committerjlemon <jlemon@FreeBSD.org>2001-10-25 16:41:38 +0000
commitf82344f52d31219e5ce275d575e773904255424a (patch)
tree81003df881d9d5307b0671a145842773238c34ba
parent064436f6e85481f30c8cd640a55acf3e7b8fe680 (diff)
downloadFreeBSD-src-f82344f52d31219e5ce275d575e773904255424a.zip
FreeBSD-src-f82344f52d31219e5ce275d575e773904255424a.tar.gz
Style and WARNS cleanups.
Submitted by: ru
-rw-r--r--sbin/conscontrol/Makefile1
-rw-r--r--sbin/conscontrol/conscontrol.817
-rw-r--r--sbin/conscontrol/conscontrol.c112
3 files changed, 65 insertions, 65 deletions
diff --git a/sbin/conscontrol/Makefile b/sbin/conscontrol/Makefile
index ddd2434..9014d80 100644
--- a/sbin/conscontrol/Makefile
+++ b/sbin/conscontrol/Makefile
@@ -2,5 +2,6 @@
PROG= conscontrol
MAN= conscontrol.8
+WARNS?= 2
.include <bsd.prog.mk>
diff --git a/sbin/conscontrol/conscontrol.8 b/sbin/conscontrol/conscontrol.8
index ff33792..c9e36bb 100644
--- a/sbin/conscontrol/conscontrol.8
+++ b/sbin/conscontrol/conscontrol.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd Oct 23, 2001
+.Dd October 23, 2001
.Dt CONSCONTROL 8
.Os
.Sh NAME
@@ -34,7 +34,7 @@
.Sh SYNOPSIS
.Nm
.Op Cm list
-.Nm
+.Nm
.Cm mute on | off
.Nm
.Cm add | delete
@@ -43,7 +43,7 @@
The
.Nm
utility is used to examine and modify the physical devices which back
-the virtual console console devices.
+the virtual console devices.
If no arguments
(or only the
.Cm list
@@ -53,7 +53,8 @@ the current console settings are shown.
.Pp
There are two types of logical consoles; a high level console which
is represented by
-.Pa /dev/console , and a low level console.
+.Pa /dev/console ,
+and a low level console.
The low level console is used for kernel
.Xr printf 9
and
@@ -65,8 +66,7 @@ Multiple device support is implemented only for the low level console;
the high level console is set to the first device in the console list.
.Pp
Multiple console support may be invoked by passing the kernel the
-.\" XXX The Fl macro doesn't really apply here
--D
+.Fl D
flag from the boot loader, or by using
.Nm
to change the list of console devices after the system has booted.
@@ -78,9 +78,10 @@ Add or delete a physical device from the logical console.
The device must support low-level console operations.
Adding a device will place it at the front of the list of console
devices; the first device is used for the high level console.
-.It Cm mute Cm on | off
+.It Cm mute on | off
Change the state of console muting.
-All console output is suppressed when console muting is on.
+All console output is suppressed when console muting is
+.Cm on .
.El
.Sh SEE ALSO
.Xr sio 4 ,
diff --git a/sbin/conscontrol/conscontrol.c b/sbin/conscontrol/conscontrol.c
index 87e85f5..329a54b 100644
--- a/sbin/conscontrol/conscontrol.c
+++ b/sbin/conscontrol/conscontrol.c
@@ -22,32 +22,34 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
+#include <unistd.h>
static void __dead2
usage(void)
{
- const char *pname = getprogname();
- fprintf(stderr, "usage: %s [list]\n", pname);
- fprintf(stderr, " %s mute on|off\n", pname);
- fprintf(stderr, " %s add|delete console\n", pname);
+ (void)fprintf(stderr, "%s\n%s\n%s\n",
+ "usage: conscontrol [list]",
+ " conscontrol mute on | off",
+ " conscontrol add | delete console");
exit(1);
}
-#define CONSBUFSIZE 32
-
static void
-constatus(void)
+consstatus(void)
{
int mute;
size_t len;
@@ -55,23 +57,15 @@ constatus(void)
len = sizeof(mute);
if (sysctlbyname("kern.consmute", &mute, &len, NULL, 0) == -1)
- goto fail;
-
- len = 0;
-alloc:
- len += CONSBUFSIZE;
- buf = malloc(len);
- if (buf == NULL)
- err(1, "Could not malloc sysctl buffer");
-
- if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1) {
- if (errno == ENOMEM) {
- free(buf);
- goto alloc;
- }
- goto fail;
- }
- avail = strchr(buf, '/');
+ err(1, "kern.consmute retrieval failed");
+ if (sysctlbyname("kern.console", NULL, &len, NULL, 0) == -1)
+ err(1, "kern.console estimate failed");
+ if ((buf = malloc(len)) == NULL)
+ errx(1, "kern.console malloc failed");
+ if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1)
+ err(1, "kern.console retrieval failed");
+ if ((avail = strchr(buf, '/')) == NULL)
+ errx(1, "kern.console format not understood");
p = avail;
*avail++ = '\0';
if (p != buf)
@@ -83,9 +77,6 @@ alloc:
printf(" Available: %s\n", avail);
printf(" Muting: %s\n", mute ? "on" : "off");
free(buf);
- return;
-fail:
- err(1, "Could not get console information");
}
static void
@@ -102,49 +93,56 @@ consmute(const char *onoff)
usage();
len = sizeof(mute);
if (sysctlbyname("kern.consmute", NULL, NULL, &mute, len) == -1)
- err(1, "Could not change console muting");
+ err(1, "could not change console muting");
}
static void
-consadd(char *devname)
+consadd(char *devnam)
{
size_t len;
- len = strlen(devname);
- if (sysctlbyname("kern.console", NULL, NULL, devname, len) == -1)
- err(1, "Could not add %s as a console", devname);
+ len = strlen(devnam);
+ if (sysctlbyname("kern.console", NULL, NULL, devnam, len) == -1)
+ err(1, "could not add %s as a console", devnam);
}
-#define MAXDEVNAME 32
-
static void
-consdel(const char *devname)
+consdel(const char *devnam)
{
- char buf[MAXDEVNAME];
+ char *buf;
size_t len;
- snprintf(buf, MAXDEVNAME, "-%s", devname);
- len = strlen(buf);
- if (sysctlbyname("kern.console", NULL, NULL, &buf, len) == -1)
- err(1, "Could not remove %s as a console", devname);
+ len = strlen(devnam) + sizeof("-");
+ if ((buf = malloc(len)) == NULL)
+ errx(1, "malloc failed");
+ buf[0] = '-';
+ strcpy(buf + 1, devnam);
+ if (sysctlbyname("kern.console", NULL, NULL, buf, len) == -1)
+ err(1, "could not remove %s as a console", devnam);
+ free(buf);
}
int
main(int argc, char **argv)
{
- if (argc < 2 || strcmp(argv[1], "list") == 0)
- goto done;
- if (argc < 3)
+ if (getopt(argc, argv, "") != -1)
usage();
- if (strcmp(argv[1], "mute") == 0)
- consmute(argv[2]);
- else if (strcmp(argv[1], "add") == 0)
- consadd(argv[2]);
- else if (strcmp(argv[1], "delete") == 0)
- consdel(argv[2]);
- else
- usage();
-done:
- constatus();
+ argc -= optind;
+ argv += optind;
+
+ if (argc > 0 && strcmp(argv[0], "list") != 0) {
+ if (argc != 2)
+ usage();
+ 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
+ usage();
+ }
+ consstatus();
+ exit(0);
}
OpenPOWER on IntegriCloud