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
31 * $FreeBSD: src/libexec/xtend/status.c,v 1.8 1999/08/28 00:10:30 peter Exp $
32 * $DragonFly: src/libexec/xtend/status.c,v 1.3 2003/11/14 03:54:32 dillon Exp $
37 #include <sys/param.h>
43 void printstatus (FILE *, STATUS
*);
46 * Initialize the status table from the status files
52 if(lseek(status
, 0, SEEK_SET
) != 0) {
53 fprintf(Log
, "%s: Seek error on status file\n", thedate());
56 if(read(status
, Status
, 16*16*sizeof(STATUS
)) != 16*16*sizeof(STATUS
)) {
57 fprintf(Log
, "%s: Read error on status file\n", thedate());
63 * Checkpoint status of any devices whose status has changed
64 * and notify anyone monitoring those devices.
73 for(h
= 0; h
< 16; h
++) {
74 for(i
= 0; i
< 16; i
++) {
75 if(Status
[h
][i
].changed
) {
76 if(lseek(status
, offset
, SEEK_SET
) != offset
) {
77 fprintf(Log
, "%s: Seek error on status file\n", thedate());
79 if(write(status
, &Status
[h
][i
], sizeof(STATUS
)) != sizeof(STATUS
)) {
80 fprintf(Log
, "%s: Write error on status file\n", thedate());
83 Status
[h
][i
].changed
= 0;
84 for(k
= 0; k
< MAXMON
; k
++) {
86 && Monitor
[k
].house
== h
&& Monitor
[k
].unit
== i
) {
88 * Arrange to catch SIGPIPE in case client has gone away.
91 extern void clientgone();
95 prev
= signal(SIGPIPE
, clientgone
);
96 printstatus(Monitor
[k
].user
, &Status
[h
][i
]);
97 fflush(Monitor
[k
].user
);
98 signal(SIGPIPE
, prev
);
102 offset
+= sizeof(STATUS
);
111 fprintf(Log
, "%s: Deleting monitor table entry %d, client gone\n", thedate(), client
);
112 fclose(Monitor
[client
].user
);
113 Monitor
[client
].inuse
= 0;