Add a simple program for listing, adding, and removing wsmux devices.

It's not a much used utility, but when you need it it's a pain to
be without.
This commit is contained in:
augustss 2001-10-13 20:05:42 +00:00
parent 5da06efad4
commit 9f01baeb47
4 changed files with 208 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.160 2001/09/13 23:51:39 thorpej Exp $
# $NetBSD: Makefile,v 1.161 2001/10/13 20:05:42 augustss Exp $
# from: @(#)Makefile 5.20 (Berkeley) 6/12/93
.include <bsd.own.mk>
@ -18,7 +18,7 @@ SUBDIR= ac accton altq amd apm apmd arp bad144 bind bootp catman \
sliplogin slstats spray sup sushi syslogd tadpolectl tcpdchk \
tcpdmatch tcpdump timed traceroute trpt trsp unlink \
usbdevs user videomode vipw vnconfig wiconfig wsconscfg \
wsfontload ypbind yppoll ypserv ypset zdump zic
wsfontload wsmuxctl ypbind yppoll ypserv ypset zdump zic
# IPv6
SUBDIR+=faithd ifmcstat mld6query ndp \

View File

@ -0,0 +1,7 @@
# $NetBSD: Makefile,v 1.1 2001/10/13 20:05:43 augustss Exp $
PROG= wsmuxctl
MAN= wsmuxctl.8
SRCS= wsmuxctl.c
.include <bsd.prog.mk>

View File

@ -0,0 +1,42 @@
.\" $NetBSD: wsmuxctl.8,v 1.1 2001/10/13 20:05:43 augustss Exp $
.\"
.Dd October 13, 2001
.Os
.Dt WMUXCTL 8
.Sh NAME
.Nm wsmuxctl
.Nd configure wsmuxes
.Sh SYNOPSIS
.Nm ""
.Op Fl a Ar dev
.Fl f Ar ctldev
.Op Fl l
.Op Fl r Ar dev
.Sh DESCRIPTION
The
.Nm
allows to adding and removing devices to a
.Xr wsmux 4 .
.Pp
Added and removed devices are specified by a name, not a path name.
Simply use
.Em wsmouseN ,
.Em wskbdN ,
or
.Em wsmuxN
where N is the number of the device.
.Pp
The options are:
.Bl -tag -width xxxxxxxxx
.It Fl a Ar dev
Add the specified device to the mux.
.It Fl f Ar ctldev
Specify the control device of wsmux to operate on.
.It Fl l
List all devices connected to a mux.
.It Fl r Ar dev
Remove the specified device from the mux.
.El
.Pp
.Sh SEE ALSO
.Xr wsmux 4

View File

@ -0,0 +1,157 @@
/* $NetBSD: wsmuxctl.c,v 1.1 2001/10/13 20:05:43 augustss Exp $ */
/*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Author: Lennart Augustsson <augustss@carlstedt.se>
* Carlstedt Research & Technology
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <err.h>
#include <errno.h>
#include <dev/wscons/wsconsio.h>
static void usage(void);
int main(int, char**);
const char *devnames[] = { "?", "wsmouse", "wskbd", "wsmux" };
static void
usage(void)
{
fprintf(stderr, "Usage: %s [-a dev] -f wsmux [-l] [-r dev]\n",
getprogname());
exit(1);
}
static void
parsedev(const char *dev, struct wsmux_device *mdev)
{
if (sscanf(dev, "wsmouse%d", &mdev->idx) == 1) {
mdev->type = WSMUX_MOUSE;
return;
}
if (sscanf(dev, "wskbd%d", &mdev->idx) == 1) {
mdev->type = WSMUX_KBD;
return;
}
if (sscanf(dev, "wsmux%d", &mdev->idx) == 1) {
mdev->type = WSMUX_MUX;
return;
}
errx(1, "bad device: `%s', use wsmouse, wskdb, or wsmux\n", dev);
}
int
main(int argc, char **argv)
{
char *wsdev, *dev;
int wsfd, list, c, i, add, rem;
struct wsmux_device_list devs;
struct wsmux_device mdev;
wsdev = NULL;
dev = NULL;
add = 0;
rem = 0;
list = 0;
while ((c = getopt(argc, argv, "a:f:lr:")) != -1) {
switch (c) {
case 'a':
if (dev)
usage();
dev = optarg;
add++;
break;
case 'r':
if (dev)
usage();
dev = optarg;
rem++;
break;
case 'f':
wsdev = optarg;
break;
case 'l':
list++;
break;
case '?':
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
if (wsdev == NULL)
usage();
wsfd = open(wsdev, O_WRONLY, 0);
if (wsfd < 0)
err(2, "%s", wsdev);
if (list) {
if (add || rem)
usage();
if (ioctl(wsfd, WSMUX_LIST_DEVICES, &devs) < 0)
err(1, "WSMUX_LIST_DEVICES");
for (i = 0; i < devs.ndevices; i++)
printf("%s%d\n", devnames[devs.devices[i].type],
devs.devices[i].idx);
exit(0);
}
if (add) {
parsedev(dev, &mdev);
if (ioctl(wsfd, WSMUX_ADD_DEVICE, &mdev) < 0)
err(1, "WSMUX_ADD_DEVICE");
}
if (rem) {
parsedev(dev, &mdev);
if (ioctl(wsfd, WSMUX_REMOVE_DEVICE, &mdev) < 0)
err(1, "WSMUX_REMOVE_DEVICE");
}
close(wsfd);
return (0);
}