Add an -f option which allows one to specify a snp device to use.

Previously, watch would always use the first device it could
successfully open, but this isn't always desired.  Specifically, it
may not be desired during debugging (of snp), or if a particular snp
device has different permissions (which makes since after snp.c 1.64).
This commit is contained in:
Dima Dorfman 2001-11-24 15:41:38 +00:00
parent e6cb3c3608
commit 1995d3a484
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=86858
2 changed files with 30 additions and 8 deletions

View File

@ -2,7 +2,7 @@
.\" @(#)watch.8 1.1 (FreeBSD) 2/17/95
.\" $FreeBSD$
.\"
.Dd February 17, 1995
.Dd November 24, 2001
.Dt WATCH 8
.Os
.Sh NAME
@ -11,6 +11,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl ciotnW
.Op Fl f Ar snpdev
.Op Ar tty
.\" watch [-ciotnW] [<tty name>]
.Sh DESCRIPTION
@ -29,6 +30,19 @@ If this option is not specified,
.Nm
will request a new tty if running in interactive mode or exit if running
without a controlling tty.
.It Fl f Ar snpdev
If this option is specified,
.Nm
will use
.Ar snpdev
as the
.Xr snp 4
device.
Without this option,
.Nm
will attempt to find the next available
.Xr snp 4
device.
.It Fl i
Force interactive mode.
Interactive mode is a default if

View File

@ -71,6 +71,7 @@ int opt_interactive = 1;
int opt_timestamp = 0;
int opt_write = 0;
int opt_no_switch = 0;
const char *opt_snpdev;
char dev_name[DEV_NAME_LEN];
int snp_io;
@ -164,12 +165,16 @@ open_snp()
else
mode = O_RDONLY;
for (c = '0'; c <= '9'; c++) {
snp[8] = c;
if ((f = open(snp, mode)) < 0)
continue;
return f;
}
if (opt_snpdev == NULL)
for (c = '0'; c <= '9'; c++) {
snp[8] = c;
if ((f = open(snp, mode)) < 0)
continue;
return f;
}
else
if ((f = open(opt_snpdev, mode)) != -1)
return (f);
fatal(EX_OSFILE, "cannot open snoop device");
return (0);
}
@ -302,7 +307,7 @@ main(ac, av)
opt_interactive = 0;
while ((ch = getopt(ac, av, "Wciotn")) != -1)
while ((ch = getopt(ac, av, "Wciotnf:")) != -1)
switch (ch) {
case 'W':
opt_write = 1;
@ -322,6 +327,9 @@ main(ac, av)
case 'n':
opt_no_switch = 1;
break;
case 'f':
opt_snpdev = optarg;
break;
case '?':
default:
usage();