UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / doc / techlogs / 1999 / kes08Dec99
blob112fd904faba7d1e5bdea20c84a79823e9168a28
1          Technical notes on my code submission of 8 Dec 99
2                         Kern Sibbald
4 General:
5 - Please delete apccontrol.sh and apccontrol.sh.in from the
6   scripts directory.
7 - Please delete apcnetlib.c from the cgi directory.
8 - With Carl Erhorn's help, we got apcupsd running on
9   Solaris, and we believe that we have resolved the
10   problems for the HP-UX as well.
11 - New html manual in doc/manual.  It still needs more
12   work, but a lot of the sections are pretty well 
13   documented.
14 - I added new directories for the Sun and HP-UX named
15   distributions/sun and distributions/hpux.  They
16   contain skeletions of the necessary files.
17 - I added automatic detection of the Sun and HP systems 
18   to the configure script.
19 - Due to the differences in the shutdown procedures
20   (calls to shutdown) between the Solaris operating
21   system and Linux, I had to move apccontrol.sh.in
22   from the scripts directory to each of the machine
23   dependent files (distributions/redhat, ...).
24 - Because of the problems with Solaris, I eliminated
25   the action process by combining it with the serial
26   port process.                          
27 - I corrected the CGI programs to properly recognize 
28   different battery voltages (12, 24, and 48). I did
29   the same for the line voltages (100, 120, 220).
31 Changes submitted this submission:
32 - I corrected the compile and link flags in Makefile.in
33   for the Sun as suggested by Carl.
34 - I modified the installation part of Makefile.in to
35   pull apccontrol.sh from the appropriate distributions
36   subdirectory. This way, apccontrol.sh can be adapted for
37   the different operating systems.
38 - Removed an old le[] from apcaccess and aligned some
39   code.
40 - Modified apcupsd.c apcserial.c and apcaction.c so that
41   the previous action process is eliminated and instead
42   the action code is called immediately after the wait
43   on the serial port. This eliminates a system incompatibility
44   that arose because of the handling of alarm(), and it
45   ensures that any actions are attended to immediately 
46   when they occur. In addition, in future releases, this
47   will permit sending of commands to the UPS as there
48   is now only a single process reading the serial port
49   and taking action.
50 - In writing the documentation, I realized that some of
51   the names of the new configuration directives that I 
52   created are misleading. Consequently, I changed
54     NETSTATUS  ->  NETSERVER
55     STATUSPORT ->  SERVERPORT
56     EVENTFILE  ->  EVENTSFILE
58   For this update, I left the old names in, but in a few
59   weeks, I will remove them.
60 - In order to make the STATUS code work for older style
61   UPSes, I had to move the "flags" variable into the shared
62   memory buffer. This was cleanup of the STATUS code that
63   I had forgotten to do.
64 - During truncating of the temporary EVENTS file, I forgot
65   to rewind() the file after truncating it. This caused the
66   subsequent write back of the old data to be lost.
67 - I changed the name "sun" to "apcsun" in apcipc.c to avoid
68   problems with the Sun compiler as reported by Carl.
69 - The file locking code that detected stale lock files was
70   not working correctly because it didn't take into account
71   the fact that the lock file was created by the parent of
72   the current process. This was observed by Carl and had
73   previously gone undetected because the details of these
74   failures were never logged until my last submission.
75 - In apclog.c, I was writing all events to the temporary
76   events file, but I should have excluded LOG_INFO, which
77   is the DATA logging.  Bug observed by Carl.
78 - Carl noted a problem in apcnet.c pointed out by his compiler,
79   when I looked at the code, I realized that it apparently could
80   never work since it did a read and lock of the shared memory
81   area then entered an infinite loop from which it would never
82   exit. This had the effect of locking out all other processes
83   from reading the shared memory area. I restructure the
84   code.  I also eliminate the alarm() and replaced it by a
85   sleep().
86 - Corrected several casts that caused compiler warnings on
87   Solaris and added INADDR_NONE in apcnetlib.c for Solaris.
88 - Carl reported that apcupsd.log was always created. This was
89   because vestiges of the old data logging remained in the 
90   code. I removed them.
91 - In testing the shutdown code again, I found it did not send
92   the correct commands to the UPS for turning off the power.
93   Consequently, I reworked the logic a bit and made it
94   correctly detect all UPS responses as well as send the
95   correct codes.
96 - In my testing, I noticed that if I disconnected the serial port
97   cable, it took more than 2 minutes for apcupsd to complain.
98   The problem turned out to be the smart_poll() was not so smart
99   after all in that it ignored the error return status. I modified
100   the code to immediately call UPSlinkCheck() if it got an error.
101   This means that loss of serial port communications is detected
102   within 6 seconds and reported within 12 seconds. It also means
103   that only one bad data value is returned if the serial port
104   is disconnect.  Previously, all data values after that point
105   were incorrectly reported.
106 - I moved the flow documentation from the bottom of apcupsd
107   to the top.
108 - I wrote new code to put apcupsd in daemon mode. This was added
109   to apcupsd.c at the end as subroutine daemon_start(). Although
110   the code is a good deal more complicated than the original code,
111   in principal, it now completely detaches from the control 
112   terminal for all operating systems.
113 - I modified the cgi code to use the apcnetlib code in the
114   main source directory.
115 - The search string for the output voltage in upsfetch.c was
116   incorrect causing the output voltage bar graph not to display.
117 - I optimized upsimage.c reducing the volume of code significantly
118   by moving it to subroutines.         
119 - I made the changed necessary to configure.in so that it will run
120   correctly on a Solaris system. These changes were provided by
121   Carl.
122 - I added sun and hpux to the system recognized by configure.
123 - The apccontrol script always executed any user script as well
124   as executing the default behavior. I modified the code so that
125   if the user script is executed and it returns a 99 as a return
126   code, the default action will not be executed.
127 - In the RedHat version of the apcupsd, I removed the killpower
128   option as it is not used, and it is rather dangerous.
129 - I noticed that on a full shutdown, the system would sometimes 
130   automatically reboot (I'm not sure exactly why). As a consequence,
131   I modified the RedHat halt scripts to wait two days after a
132   power kill and then to exit.
133 - Updated the RedHat and SuSe apccontrol.sh.in script to have many
134   of the changes necessary for running on the Sun. These are minor
135   script changes that will make it easier for other systems to
136   take our scripts and modify them for their use.
137 - Eliminated the /sbin/powersc from the unknown directory and
138   replaced it with a call to apccontrol.
139 - Deleted apcstatus.man from the doc directory.
140 - Added a new doc/manual directory containing the new html documentation.
141   Lots of new files.
142 - Updated apcupsd.conf to have the new configuration directive
143   names and added more documentation for the TIMEOUT directive.
144 - Added example STATUS output files to the examples directory.
145   It would be nice to have a STATUS output example for nearly each
146   UPS type.
147 - Updated examples/apcupsd.master.conf and slave.conf.
148 - Added a safe.apccontrol to the examples directory for testing.
149   See the Testing section of the new manual for details.
150 - Added startapcupsd and stopapcupsd examples to the examples directory.
151 - Added the necessary changed to apc_config.h for the Sun compler --
152   thanks Carl.
154                 Kern's ToDo List
156 To do:
157 - Complete documentation
158 - Add and test a bunch of events that email a message.
159 - Check and double check killpwr changes (one pass made).
160 - Fix the *** fixme ***s in apcupsd.c and apcconfig.c
161 - Expand Last UPS Self Test field in cgi program
162 - Automatic conversion of old apcupsd.config files
163   to the new format?
164 - Produce a RPM for RedHat
167 Wish list:
168 - Add remaining time before TIMEOUT to STATUS output.
169 - Add more commands (individual variables) to apcnetd
170 - Accumulate time on batteries and number of transfers
171   to batteries. Perhaps save history in file so that the
172   info can be recovered if apcupsd restarts.
173 - Fix apcupsd so that it respawns the server if it
174   dies (limit number of times). This will avoid the
175   possibility that someone can bring down our apcupsd
176   by connecting via Internet (denial of service attack,
177   or exploit possible buffer overflow).
178 - Make apcaccess use the network code as an option.
179 - Remember date and time when apcupsd started.
180 - Eliminate rest of character command codes using new
181   capabilities code in apcsetup.c (for setup stuff).
182 - Eliminate the rest of the printfs().
183 - Eliminate as many error_aborts as possible in making
184   new events.
185 - Possibly retab new cgi/net server code
186 - Apparently during self test, apcupsd thinks that the
187   power was lost. Distinguish this condition!
188 - Check out apmd and see if we should interface to it.
190 Done:
191 - Integrated changes for Solaris provided by Carl.
192 - Add TIMEOUT to STATUS output.
193 - Document TIMEOUT in apcupsd.conf
194 - Inhibit DATA records from being written to the
195   events file.
196 - Fix the battery voltage display in the cgi to handle
197   battery voltages of 12 and 48 volts as well as 
198   24 volts.
199 - Document the new configuration options.   
200 - Document installation.                            
201 - Update apcupsd.man and apcnetd.man, and create
202   new sgml documentation for EVENTS, DATA, LOGGING,
203   and STATUS output as well as documenting the
204   network "programming" interface.
205 - Document the CGI programs (partially).
206 - Document log_event for developers -- especially
207   the LOG_ values.
208   See info in developers/apcupsd.logging