summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-10-27 12:21:10 +0000
committercharnier <charnier@FreeBSD.org>1997-10-27 12:21:10 +0000
commit29b9cb9613dfd64280cd6ae61cbd7aeb532a590d (patch)
tree9b74af3f0267a252efb3e0af647044ba602a3b1e /usr.sbin
parentddebc6cdedf0fc290f773e657ed4989449a5c348 (diff)
downloadFreeBSD-src-29b9cb9613dfd64280cd6ae61cbd7aeb532a590d.zip
FreeBSD-src-29b9cb9613dfd64280cd6ae61cbd7aeb532a590d.tar.gz
Use err(3).
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/watch/watch.816
-rw-r--r--usr.sbin/watch/watch.c52
2 files changed, 38 insertions, 30 deletions
diff --git a/usr.sbin/watch/watch.8 b/usr.sbin/watch/watch.8
index c4cc99d..ae7ba5c6 100644
--- a/usr.sbin/watch/watch.8
+++ b/usr.sbin/watch/watch.8
@@ -19,26 +19,26 @@ allows the superuser to examine all data coming through a specified tty.
writes to standard output.
.Pp
The options are as follows:
-.Bl -tag -width "-l nul "
+.Bl -tag -width indent
.It Fl c
Reconnect on close. If the tty observed by
-.Nm watch
+.Nm
is closed, automatically reattach to the same tty.
If this option is not specified,
-.Nm watch
+.Nm
will request a new tty if running in interactive mode or exit if running
without a controlling tty.
.It Fl i
Force interactive mode.
Interactive mode is a default if
-.Nm watch
+.Nm
is started from a tty.
If output is redirected to a file, interactive mode can still be requested
by specifying this option.
.It Fl o
Reconnect on overflow.
The behavior of
-.Nm watch
+.Nm
if the observed tty overflows is similar to the behavior if the observed tty
is closed.
For more info see
@@ -63,14 +63,14 @@ While running in interactive mode, all user input is discarded except for:
.Bl -tag -width "XXXX" -compact
.It Sy "<control-G>"
Exit
-.Nm watch .
+.Nm Ns .
.It Sy "<control-W>"
Clear screen.
.It Sy "<control-X>"
Change attached tty.
.Sh RESTRICTIONS
Only the superuser can run
-.Nm watch .
+.Nm Ns .
.Sh SEE ALSO
.Xr pty 4 ,
.Xr sio 4 ,
@@ -79,7 +79,7 @@ Only the superuser can run
No terminal emulation is performed.
All user output is reproduced as-is.
.Sh AUTHOR
-Ugen J.S. Antsilevich <ugen@NetVision.net.il>
+.An Ugen J.S. Antsilevich Aq ugen@NetVision.net.il
.Sh HISTORY
.Nm Watch
first appeared in
diff --git a/usr.sbin/watch/watch.c b/usr.sbin/watch/watch.c
index ce5be37..9277efb 100644
--- a/usr.sbin/watch/watch.c
+++ b/usr.sbin/watch/watch.c
@@ -13,12 +13,18 @@
* Snoop stuff.
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
#include <sys/types.h>
#include <sys/fcntl.h>
#include <sys/filio.h>
#include <sys/snoop.h>
#include <sys/stat.h>
+#include <err.h>
#include <locale.h>
#include <signal.h>
#include <stdio.h>
@@ -125,8 +131,9 @@ fatal(err, buf)
{
unset_tty();
if (buf)
- fprintf(stderr, "Fatal: %s\n", buf);
- exit(err);
+ errx(err, "fatal: %s", buf);
+ else
+ exit(err);
}
int
@@ -147,7 +154,8 @@ open_snp()
continue;
return f;
}
- fatal(EX_OSFILE, "Cannot open snoop device.");
+ fatal(EX_OSFILE, "cannot open snoop device");
+ return (0);
}
@@ -162,10 +170,10 @@ cleanup()
}
-void
-show_usage()
+static void
+usage()
{
- printf("watch -[ciotnW] [tty name]\n");
+ fprintf(stderr, "usage: watch [-ciotnW] [tty name]\n");
exit(EX_USAGE);
}
@@ -194,7 +202,8 @@ ctoh(c)
if (c >= 'a' && c <= 'f')
return (int) (c - 'a' + 10);
- fatal(EX_DATAERR, "Bad tty number.");
+ fatal(EX_DATAERR, "bad tty number");
+ return (0);
}
@@ -211,7 +220,7 @@ void
attach_snp()
{
if (ioctl(snp_io, SNPSTTY, &snp_tty) != 0)
- fatal(EX_UNAVAILABLE, "Cannot attach to tty.");
+ fatal(EX_UNAVAILABLE, "cannot attach to tty");
if (opt_timestamp)
timestamp("Logging Started.");
}
@@ -235,10 +244,10 @@ set_dev(name)
}
if (*name == '\0' || stat(buf, &sb) < 0)
- fatal(EX_DATAERR, "Bad device name.");
+ fatal(EX_DATAERR, "bad device name");
if ((sb.st_mode & S_IFMT) != S_IFCHR)
- fatal(EX_DATAERR, "Must be a character device.");
+ fatal(EX_DATAERR, "must be a character device");
snp_tty = sb.st_rdev;
attach_snp();
@@ -313,8 +322,7 @@ main(ac, av)
break;
case '?':
default:
- show_usage();
- exit(1);
+ usage();
}
signal(SIGINT, cleanup);
@@ -326,14 +334,14 @@ main(ac, av)
if (opt_interactive && !opt_no_switch)
ask_dev(dev_name, MSG_INIT);
else
- fatal(EX_DATAERR, "No device name given.");
+ fatal(EX_DATAERR, "no device name given");
} else
strncpy(dev_name, *av, DEV_NAME_LEN);
set_dev(dev_name);
if (!(buf = (char *) malloc(b_size)))
- fatal(EX_UNAVAILABLE, "Cannot malloc().");
+ fatal(EX_UNAVAILABLE, "malloc failed");
FD_ZERO(&fd_s);
@@ -345,11 +353,11 @@ main(ac, av)
if (opt_interactive && FD_ISSET(std_in, &fd_s)) {
if ((res = ioctl(std_in, FIONREAD, &nread)) != 0)
- fatal(EX_OSERR, "ioctl() failed.");
+ fatal(EX_OSERR, "ioctl(FIONREAD)");
if (nread > READB_LEN)
nread = READB_LEN;
if (read(std_in,chb,nread)!=nread)
- fatal(EX_IOERR, "read (stdin) failed.");
+ fatal(EX_IOERR, "read (stdin) failed");
switch (chb[0]) {
case CHR_CLEAR:
@@ -367,7 +375,7 @@ main(ac, av)
if (write(snp_io,chb,nread) != nread) {
detach_snp();
if (opt_no_switch)
- fatal(EX_IOERR, "Write failed.");
+ fatal(EX_IOERR, "write failed");
ask_dev(dev_name, MSG_NOWRITE);
set_dev(dev_name);
}
@@ -379,7 +387,7 @@ main(ac, av)
continue;
if ((res = ioctl(snp_io, FIONREAD, &nread)) != 0)
- fatal(EX_OSERR, "ioctl() failed.");
+ fatal(EX_OSERR, "ioctl(FIONREAD)");
switch (nread) {
case SNP_OFLOW:
@@ -403,19 +411,19 @@ main(ac, av)
if (nread < (b_size / 2) && (b_size / 2) > MIN_SIZE) {
free(buf);
if (!(buf = (char *) malloc(b_size / 2)))
- fatal(EX_UNAVAILABLE, "Cannot malloc()");
+ fatal(EX_UNAVAILABLE, "malloc failed");
b_size = b_size / 2;
}
if (nread > b_size) {
b_size = (nread % 2) ? (nread + 1) : (nread);
free(buf);
if (!(buf = (char *) malloc(b_size)))
- fatal(EX_UNAVAILABLE, "Cannot malloc()");
+ fatal(EX_UNAVAILABLE, "malloc failed");
}
if (read(snp_io, buf, nread) < nread)
- fatal(EX_IOERR, "read failed.");
+ fatal(EX_IOERR, "read failed");
if (write(std_out, buf, nread) < nread)
- fatal(EX_IOERR, "write failed.");
+ fatal(EX_IOERR, "write failed");
}
} /* While */
}
OpenPOWER on IntegriCloud