]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/xtend/status.c
This commit was generated by cvs2svn to compensate for changes in r91830,
[FreeBSD/FreeBSD.git] / libexec / xtend / status.c
1 /*-
2  * Copyright (c) 1992, 1993, 1995 Eugene W. Stark
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
18  *
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
29  * SUCH DAMAGE.
30  */
31
32 #ifndef lint
33 static const char rcsid[] =
34   "$FreeBSD$";
35 #endif /* not lint */
36
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <sys/param.h>
40 #include <sys/stat.h>
41 #include "xtend.h"
42 #include "xten.h"
43 #include "paths.h"
44
45 void printstatus(FILE *, STATUS *);
46
47 /*
48  * Initialize the status table from the status files
49  */
50
51 void
52 initstatus(void)
53 {
54   if(lseek(status, 0, SEEK_SET) != 0) {
55     fprintf(Log, "%s:  Seek error on status file\n", thedate());
56     return;
57   }
58   if(read(status, Status, 16*16*sizeof(STATUS)) != 16*16*sizeof(STATUS)) {
59         fprintf(Log, "%s:  Read error on status file\n", thedate());
60         return;
61   }
62 }
63
64 /*
65  * Checkpoint status of any devices whose status has changed
66  * and notify anyone monitoring those devices.
67  */
68
69 void
70 checkpoint_status(void)
71 {
72   int h, i, k, offset;
73
74   offset = 0;
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());
80         } else {
81           if(write(status, &Status[h][i], sizeof(STATUS)) != sizeof(STATUS)) {
82             fprintf(Log, "%s:  Write error on status file\n", thedate());
83           }
84         }
85         Status[h][i].changed = 0;
86         for(k = 0; k < MAXMON; k++) {
87           if(Monitor[k].inuse
88              && Monitor[k].house == h && Monitor[k].unit == i) {
89             /*
90              * Arrange to catch SIGPIPE in case client has gone away.
91              */
92             extern int client;
93             extern void clientgone();
94             void (*prev)();
95
96             client = k;
97             prev = signal(SIGPIPE, clientgone);
98             printstatus(Monitor[k].user, &Status[h][i]);
99             fflush(Monitor[k].user);
100             signal(SIGPIPE, prev);
101           }
102         }
103       }
104       offset += sizeof(STATUS);
105     }
106   }
107 }
108
109 int client;
110
111 void
112 clientgone(void)
113 {
114     fprintf(Log, "%s:  Deleting monitor table entry %d, client gone\n", thedate(), client);
115     fclose(Monitor[client].user);
116     Monitor[client].inuse = 0;
117 }