/*1* Copyright (c) 2000 by Matthew Jacob2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification, immediately at the beginning of the file.10* 2. The name of the author may not be used to endorse or promote products11* derived from this software without specific prior written permission.12*13* Alternatively, this software may be distributed under the terms of the14* the GNU Public License ("GPL").15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR20* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*28* Matthew Jacob29* Feral Software30* [email protected]31*/32#include <unistd.h>33#include <stdlib.h>34#include <stdio.h>35#include <fcntl.h>36#include <errno.h>37#include <sys/ioctl.h>38#include "ses.h"3940/*41* Continuously monitor all named SES devices42* and turn all but INFO enclosure status43* values into CRITICAL enclosure status.44*/45#define BADSTAT \46(SES_ENCSTAT_UNRECOV|SES_ENCSTAT_CRITICAL|SES_ENCSTAT_NONCRITICAL)47int48main(int a, char **v)49{50int fd, delay, dev;51ses_encstat stat, *carray;5253if (a < 3) {54fprintf(stderr, "usage: %s polling-interval device "55"[ device ... ]\n", *v);56return (1);57}58delay = atoi(v[1]);59carray = malloc(a);60if (carray == NULL) {61perror("malloc");62return (1);63}64bzero((void *)carray, a);6566for (;;) {67for (dev = 2; dev < a; dev++) {68fd = open(v[dev], O_RDWR);69if (fd < 0) {70perror(v[dev]);71continue;72}73/*74* First clear any enclosure status, in case it is75* a latched status.76*/77stat = 0;78if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {79fprintf(stderr, "%s: SESIOC_SETENCSTAT1: %s\n",80v[dev], strerror(errno));81(void) close(fd);82continue;83}84/*85* Now get the actual current enclosure status.86*/87if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &stat) < 0) {88fprintf(stderr, "%s: SESIOC_GETENCSTAT: %s\n",89v[dev], strerror(errno));90(void) close(fd);91continue;92}9394if ((stat & BADSTAT) == 0) {95if (carray[dev]) {96fprintf(stdout, "%s: Clearing CRITICAL "97"condition\n", v[dev]);98carray[dev] = 0;99}100(void) close(fd);101continue;102}103carray[dev] = 1;104fprintf(stdout, "%s: Setting CRITICAL from:", v[dev]);105if (stat & SES_ENCSTAT_UNRECOV)106fprintf(stdout, " UNRECOVERABLE");107108if (stat & SES_ENCSTAT_CRITICAL)109fprintf(stdout, " CRITICAL");110111if (stat & SES_ENCSTAT_NONCRITICAL)112fprintf(stdout, " NONCRITICAL");113putchar('\n');114stat = SES_ENCSTAT_CRITICAL;115if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {116fprintf(stderr, "%s: SESIOC_SETENCSTAT 2: %s\n",117v[dev], strerror(errno));118}119(void) close(fd);120}121sleep(delay);122}123/* NOTREACHED */124}125126127