2 * Copyright (c) 1992, 1993, 1995 Eugene W. Stark
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Eugene W. Stark.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY EUGENE W. STARK (THE AUTHOR) ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char rcsid[] =
39 #include <sys/param.h>
45 void printstatus(FILE *, STATUS *);
48 * Initialize the status table from the status files
54 if(lseek(status, 0, SEEK_SET) != 0) {
55 fprintf(Log, "%s: Seek error on status file\n", thedate());
58 if(read(status, Status, 16*16*sizeof(STATUS)) != 16*16*sizeof(STATUS)) {
59 fprintf(Log, "%s: Read error on status file\n", thedate());
65 * Checkpoint status of any devices whose status has changed
66 * and notify anyone monitoring those devices.
70 checkpoint_status(void)
75 for(h = 0; h < 16; h++) {
76 for(i = 0; i < 16; i++) {
77 if(Status[h][i].changed) {
78 if(lseek(status, offset, SEEK_SET) != offset) {
79 fprintf(Log, "%s: Seek error on status file\n", thedate());
81 if(write(status, &Status[h][i], sizeof(STATUS)) != sizeof(STATUS)) {
82 fprintf(Log, "%s: Write error on status file\n", thedate());
85 Status[h][i].changed = 0;
86 for(k = 0; k < MAXMON; k++) {
88 && Monitor[k].house == h && Monitor[k].unit == i) {
90 * Arrange to catch SIGPIPE in case client has gone away.
93 extern void clientgone();
97 prev = signal(SIGPIPE, clientgone);
98 printstatus(Monitor[k].user, &Status[h][i]);
99 fflush(Monitor[k].user);
100 signal(SIGPIPE, prev);
104 offset += sizeof(STATUS);
114 fprintf(Log, "%s: Deleting monitor table entry %d, client gone\n", thedate(), client);
115 fclose(Monitor[client].user);
116 Monitor[client].inuse = 0;