Persistent count file

Soon after finishing the phase 1 web counter, I realized that it really needed to be able to store the current count somewhere, so that I could just restart the web counter and have it magically continue from where it left off, rather than back at zero.

The first change to accomplish this is to handle the -S option, which lets you specify the name of the file that stores the current web counter value. If you don't specify a -S then nothing different happens—the new version behaves just the same as the old version. Code-wise, this change is trivial—just add "S:" to the getopt() string list in the command line option processor (optproc() in main.c), and put in a handler for that option. The handler saves the value into the global variable optS.

At the end of option processing, if we have a -S option, we read the value from it (by calling read_file()), but only if we haven't specified a -s. The logic here is that if you want to reset the web counter to a particular value, you'd want the -s to override the count from the -S option. (Of course, you could always edit the persistent data file with a text editor once the resource manager has been shut down.)

Once the web counter has started, we're done reading from the persistent count file. All we need to do is update the file whenever we update the counter. This too is a trivial change. After we increment the counter's value in io_read(), we call write_file() to store the value to the persistent file (only if optS is defined; otherwise, there's no file, so no need to save the value).