diff options
Diffstat (limited to 'share/examples/ses')
-rw-r--r-- | share/examples/ses/sesd/sesd.0 | 7 | ||||
-rw-r--r-- | share/examples/ses/srcs/sesd.c | 53 |
2 files changed, 38 insertions, 22 deletions
diff --git a/share/examples/ses/sesd/sesd.0 b/share/examples/ses/sesd/sesd.0 index 29c0084..7a548c7 100644 --- a/share/examples/ses/sesd/sesd.0 +++ b/share/examples/ses/sesd/sesd.0 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 21, 2000 +.Dd November 5, 2012 .Dt SESD 8 .Os .Sh NAME @@ -39,6 +39,7 @@ .Nd monitor SCSI Environmental Services Devices .Sh SYNOPSIS .Nm +.Op Fl c .Op Fl d .Op Fl t Ar poll-interval .Ar device @@ -57,7 +58,9 @@ poll each device for a change in state. .Pp The following options may be used: .Bl -tag -width Ds -.It Fl p Ar poll-interval +.It Fl c +Try to clear enclosure status after read. +.It Fl t Ar poll-interval Change the interval of polling from the default 30 seconds to the number of seconds specified. .It Fl d diff --git a/share/examples/ses/srcs/sesd.c b/share/examples/ses/srcs/sesd.c index 096eeae..acf9508 100644 --- a/share/examples/ses/srcs/sesd.c +++ b/share/examples/ses/srcs/sesd.c @@ -40,6 +40,7 @@ #include <errno.h> #include <string.h> #include <syslog.h> +#include <unistd.h> #include <sys/ioctl.h> #include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_enc.h> @@ -55,29 +56,33 @@ int main(int a, char **v) { static const char *usage = - "usage: %s [ -d ] [ -t pollinterval ] device [ device ]\n"; - int fd, polltime, dev, devbase, nodaemon; - encioc_enc_status_t stat, *carray; + "usage: %s [ -c ] [ -d ] [ -t pollinterval ] device [ device ]\n"; + int fd, polltime, dev, nodaemon, clear, c; + encioc_enc_status_t stat, nstat, *carray; if (a < 2) { fprintf(stderr, usage, *v); return (1); } - devbase = 1; - - if (strcmp(v[1], "-d") == 0) { - nodaemon = 1; - devbase++; - } else { - nodaemon = 0; - } - - if (a > 2 && strcmp(v[2], "-t") == 0) { - devbase += 2; - polltime = atoi(v[3]); - } else { - polltime = 30; + nodaemon = 0; + polltime = 30; + clear = 0; + while ((c = getopt(a, v, "cdt:")) != -1) { + switch (c) { + case 'c': + clear = 1; + break; + case 'd': + nodaemon = 1; + break; + case 't': + polltime = atoi(optarg); + break; + default: + fprintf(stderr, usage, *v); + return (1); + } } carray = malloc(a); @@ -85,13 +90,13 @@ main(int a, char **v) perror("malloc"); return (1); } - for (dev = devbase; dev < a; dev++) + for (dev = optind; dev < a; dev++) carray[dev] = (encioc_enc_status_t) -1; /* * Check to make sure we can open all devices */ - for (dev = devbase; dev < a; dev++) { + for (dev = optind; dev < a; dev++) { fd = open(v[dev], O_RDWR); if (fd < 0) { perror(v[dev]); @@ -115,7 +120,7 @@ main(int a, char **v) } for (;;) { - for (dev = devbase; dev < a; dev++) { + for (dev = optind; dev < a; dev++) { fd = open(v[dev], O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", v[dev]); @@ -131,6 +136,14 @@ main(int a, char **v) (void) close(fd); continue; } + if (stat != 0 && clear) { + nstat = 0; + if (ioctl(fd, ENCIOC_SETENCSTAT, + (caddr_t) &nstat) < 0) { + syslog(LOG_ERR, + "%s: ENCIOC_SETENCSTAT- %m", v[dev]); + } + } (void) close(fd); if (stat == carray[dev]) |