3 * @purpose Entry point to the program, starts threads, handles cleanup on program exit
6 // --- Standard headers --- //
9 #include <signal.h> // for signal handling
11 // --- Custom headers --- //
14 // --- Variable definitions --- //
15 Options g_options; // options passed to program through command line arguments
17 // --- Function definitions --- //
20 * @funct ParseArguments
21 * @purpose Parse command line arguments, set up an options variable
22 * @param argc - Num args
23 * @param argv - Array of args
24 * @param opts - Pointer to options. &g_options
26 void ParseArguments(int argc, char ** argv, Options * opts)
28 options.program = argv[0]; // program name
29 options.verbosity = LOGDEBUG; // default log level
31 options.port = atoi(argv[1]); // Allow us change the port for testing (I keep getting "address in use" errors)
33 options.port = 8080; // Using 8080 instead of 80 for now because to use 80 you have to run the program as root
35 Log(LOGDEBUG, "ParseArguments", "Called as %s with %d arguments.", options.program, argc);
39 * @funct SignalHandler
40 * @purpose Handle signals
41 * @param sig - The signal
43 void SignalHandler(int sig)
45 // At the moment just always exit.
46 // Call `exit` so that Cleanup will be called to... clean up.
47 Log(LOGWARN, "SignalHandler", "Got signal %d (%s). Exiting.", sig, strsignal(sig));
53 * @purpose Called when program exits
57 Log(LOGDEBUG, "Cleanup", "Begin cleanup.");
58 Log(LOGDEBUG, "Cleanup", "Finish cleanup.");