1 /* $NetBSD: sesd.c,v 1.4 2001/01/11 02:46:21 lukem Exp $ */
5 * Copyright (c) 2000 by Matthew Jacob
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * the GNU Public License ("GPL").
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 #include <sys/ioctl.h>
46 #define ALLSTAT (SES_ENCSTAT_UNRECOV | SES_ENCSTAT_CRITICAL | \
47 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
48 int main
__P((int, char **));
51 * Monitor named SES devices and note (via syslog) any changes in status.
59 static const char usage
[] =
60 "usage: %s [ -d ] [ -t pollinterval ] device [ device ]\n";
61 int fd
, polltime
, dev
, devbase
, nodaemon
;
62 ses_encstat sestat
, *carray
;
65 fprintf(stderr
, usage
, *v
);
71 if (strcmp(v
[1], "-d") == 0) {
78 if (a
> 2 && strcmp(v
[2], "-t") == 0) {
80 polltime
= atoi(v
[3]);
90 for (dev
= devbase
; dev
< a
; dev
++)
91 carray
[dev
] = (ses_encstat
) -1;
94 * Check to make sure we can open all devices
96 for (dev
= devbase
; dev
< a
; dev
++) {
97 fd
= open(v
[dev
], O_RDWR
);
102 if (ioctl(fd
, SESIOC_INIT
, NULL
) < 0) {
103 fprintf(stderr
, "%s: SESIOC_INIT fails- %s\n",
104 v
[dev
], strerror(errno
));
110 if (daemon(0, 0) < 0) {
114 openlog("sesd", 0, LOG_USER
);
116 openlog("sesd", LOG_PERROR
, LOG_USER
);
120 for (dev
= devbase
; dev
< a
; dev
++) {
121 fd
= open(v
[dev
], O_RDWR
);
123 syslog(LOG_ERR
, "%s: %m", v
[dev
]);
128 * Get the actual current enclosure status.
130 if (ioctl(fd
, SESIOC_GETENCSTAT
, (caddr_t
) &sestat
) < 0) {
132 "%s: SESIOC_GETENCSTAT- %m", v
[dev
]);
138 if (sestat
== carray
[dev
])
141 carray
[dev
] = sestat
;
142 if ((sestat
& ALLSTAT
) == 0) {
144 "%s: Enclosure Status OK", v
[dev
]);
146 if (sestat
& SES_ENCSTAT_INFO
) {
148 "%s: Enclosure Status Has Information",
151 if (sestat
& SES_ENCSTAT_NONCRITICAL
) {
153 "%s: Enclosure Non-Critical", v
[dev
]);
155 if (sestat
& SES_ENCSTAT_CRITICAL
) {
157 "%s: Enclosure Critical", v
[dev
]);
159 if (sestat
& SES_ENCSTAT_UNRECOV
) {
161 "%s: Enclosure Unrecoverable", v
[dev
]);