summaryrefslogtreecommitdiffstats
path: root/usr.sbin/watch
diff options
context:
space:
mode:
authorcsjp <csjp@FreeBSD.org>2004-08-10 01:49:46 +0000
committercsjp <csjp@FreeBSD.org>2004-08-10 01:49:46 +0000
commitda80d2d49d209d69172bd6453ddc3967cff72bfb (patch)
tree0e18b0293bc5fc8ad411546e9e30c42651f89143 /usr.sbin/watch
parent7e21ce666c82537fdaf6354b41e681ecfd85640c (diff)
downloadFreeBSD-src-da80d2d49d209d69172bd6453ddc3967cff72bfb.zip
FreeBSD-src-da80d2d49d209d69172bd6453ddc3967cff72bfb.tar.gz
By default, the watch utility will attempt to open /dev/snp0, if
another process already has /dev/snp0 open, the snp(4) will return EBUSY, in which case watch will try to open /dev/snp1..9. Currently watch does not check errno to see if the failure was a result of EBUSY. This results in watch making futile attempts to open snp0..snp9 even though devices may not exist or the caller does not have permissions to access the device. In addition to this, it attempts to setup the screen for snooping even though it may not ever get an snp device. So this patch does two things 1) Checks errno for EBUSY, if open(2) fails for another reason print that reason and exit. 2) setup the terminal for snooping after the snp descriptor has been obtained. Approved by: bmilekic (mentor)
Diffstat (limited to 'usr.sbin/watch')
-rw-r--r--usr.sbin/watch/watch.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/watch/watch.c b/usr.sbin/watch/watch.c
index 1e630db..049fc84 100644
--- a/usr.sbin/watch/watch.c
+++ b/usr.sbin/watch/watch.c
@@ -25,6 +25,7 @@ __FBSDID("$FreeBSD$");
#include <sys/module.h>
#include <err.h>
+#include <errno.h>
#include <locale.h>
#include <paths.h>
#include <signal.h>
@@ -165,8 +166,11 @@ open_snp(void)
if (opt_snpdev == NULL)
for (c = '0'; c <= '9'; c++) {
snp[pos] = c;
- if ((f = open(snp, mode)) < 0)
- continue;
+ if ((f = open(snp, mode)) < 0) {
+ if (errno == EBUSY)
+ continue;
+ err(1, "open %s", snp);
+ }
return f;
}
else
@@ -331,8 +335,8 @@ main(int ac, char *av[])
signal(SIGINT, cleanup);
- setup_scr();
snp_io = open_snp();
+ setup_scr();
if (*(av += optind) == NULL) {
if (opt_interactive && !opt_no_switch)
OpenPOWER on IntegriCloud