Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2012 00:22:33 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r242638 - in head/share/examples/ses: sesd srcs
Message-ID:  <201211060022.qA60MXWI028008@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Tue Nov  6 00:22:33 2012
New Revision: 242638
URL: http://svnweb.freebsd.org/changeset/base/242638

Log:
  Add -c option to sesd to make it clear enclosure status after reading it
  in case if it is not permanent and was fixed.

Modified:
  head/share/examples/ses/sesd/sesd.0
  head/share/examples/ses/srcs/sesd.c

Modified: head/share/examples/ses/sesd/sesd.0
==============================================================================
--- head/share/examples/ses/sesd/sesd.0	Tue Nov  6 00:08:09 2012	(r242637)
+++ head/share/examples/ses/sesd/sesd.0	Tue Nov  6 00:22:33 2012	(r242638)
@@ -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

Modified: head/share/examples/ses/srcs/sesd.c
==============================================================================
--- head/share/examples/ses/srcs/sesd.c	Tue Nov  6 00:08:09 2012	(r242637)
+++ head/share/examples/ses/srcs/sesd.c	Tue Nov  6 00:22:33 2012	(r242638)
@@ -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])



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211060022.qA60MXWI028008>