summaryrefslogtreecommitdiffstats
path: root/usr.sbin/usbdevs
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2018-07-01 08:51:50 +0000
committermpi <mpi@openbsd.org>2018-07-01 08:51:50 +0000
commit4524912105570b5ad0bee5601ab0357381c7b931 (patch)
tree9f2b98a1abc7fe5b5a004711d88c0843285c883e /usr.sbin/usbdevs
parentahah. complex tag changes show I need to use the same algorithm as for libs (diff)
downloadwireguard-openbsd-4524912105570b5ad0bee5601ab0357381c7b931.tar.xz
wireguard-openbsd-4524912105570b5ad0bee5601ab0357381c7b931.zip
Tweak output to behave more like pcidump(8):
- Display port info with -vv or more - Always print the corresponding USB controller ok sthen@, deraadt@
Diffstat (limited to 'usr.sbin/usbdevs')
-rw-r--r--usr.sbin/usbdevs/usbdevs.85
-rw-r--r--usr.sbin/usbdevs/usbdevs.c33
2 files changed, 23 insertions, 15 deletions
diff --git a/usr.sbin/usbdevs/usbdevs.8 b/usr.sbin/usbdevs/usbdevs.8
index e930d404a60..6c4dbe9464b 100644
--- a/usr.sbin/usbdevs/usbdevs.8
+++ b/usr.sbin/usbdevs/usbdevs.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: usbdevs.8,v 1.9 2008/06/26 05:42:21 ray Exp $
+.\" $OpenBSD: usbdevs.8,v 1.10 2018/07/01 08:51:50 mpi Exp $
.\" $NetBSD: usbdevs.8,v 1.5 2000/10/15 12:44:11 bjh21 Exp $
.\"
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 26 2008 $
+.Dd $Mdocdate: July 1 2018 $
.Dt USBDEVS 8
.Os
.Sh NAME
@@ -55,6 +55,7 @@ Show the device drivers associated with each device.
Only print information for the given USB controller.
.It Fl v
Be verbose.
+Multiple -v options increase the verbosity.
.El
.Sh FILES
.Bl -tag -width Pa
diff --git a/usr.sbin/usbdevs/usbdevs.c b/usr.sbin/usbdevs/usbdevs.c
index f328d24c100..a043ae7ed65 100644
--- a/usr.sbin/usbdevs/usbdevs.c
+++ b/usr.sbin/usbdevs/usbdevs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: usbdevs.c,v 1.25 2015/12/22 08:36:40 mmcc Exp $ */
+/* $OpenBSD: usbdevs.c,v 1.26 2018/07/01 08:51:50 mpi Exp $ */
/* $NetBSD: usbdevs.c,v 1.19 2002/02/21 00:34:31 christos Exp $ */
/*
@@ -30,15 +30,17 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/types.h>
+#include <dev/usb/usb.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
#include <unistd.h>
-#include <err.h>
-#include <errno.h>
-#include <dev/usb/usb.h>
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -131,7 +133,7 @@ usbdev(int f, int a, int rec)
int s = di.udi_ports[p];
if (s >= USB_MAX_DEVICES) {
- if (verbose) {
+ if (verbose > 1) {
printf("%*sport %d %s\n", indent+1, "", p+1,
s == USB_PORT_ENABLED ? "enabled" :
s == USB_PORT_SUSPENDED ? "suspended" :
@@ -143,7 +145,7 @@ usbdev(int f, int a, int rec)
}
indent++;
printf("%*s", indent, "");
- if (verbose)
+ if (verbose > 1)
printf("port %d ", p+1);
if (s == 0)
printf("addr 0 should never happen!\n");
@@ -167,7 +169,7 @@ usbdump(int f)
void
dumpone(char *name, int f, int addr)
{
- if (verbose)
+ if (!addr)
printf("Controller %s:\n", name);
indent = 0;
memset(done, 0, sizeof done);
@@ -201,7 +203,7 @@ main(int argc, char **argv)
dev = optarg;
break;
case 'v':
- verbose = 1;
+ verbose++;
break;
default:
usage();
@@ -210,6 +212,9 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (argc != 0)
+ usage();
+
if (dev == 0) {
for (ncont = 0, i = 0; i < 10; i++) {
snprintf(buf, sizeof buf, "%s%d", USBDEV, i);
@@ -229,10 +234,12 @@ main(int argc, char **argv)
__progname);
} else {
f = open(dev, O_RDONLY);
- if (f >= 0)
+ if (f >= 0) {
dumpone(dev, f, addr);
- else
+ close(f);
+ } else
err(1, "%s", dev);
}
- exit(0);
+
+ return 0;
}