3 * @purpose Entry point to the program, starts threads, handles cleanup on program exit
6 #define _POSIX_C_SOURCE 200809L // For strsignal to work
8 // --- Standard headers --- //
11 #include <signal.h> // for signal handling
12 #include <string.h> // string functions
14 // --- Custom headers --- //
18 // --- Variable definitions --- //
19 Options g_options; // options passed to program through command line arguments
21 // --- Function definitions --- //
24 * @funct ParseArguments
25 * @purpose Parse command line arguments, set up an options variable
26 * @param argc - Num args
27 * @param argv - Array of args
28 * @param opts - Pointer to options. &g_options
30 void ParseArguments(int argc, char ** argv, Options * opts)
32 opts->program = argv[0]; // program name
33 opts->verbosity = LOGDEBUG; // default log level
34 Log(LOGDEBUG, "ParseArguments", "Called as %s with %d arguments.", opts->program, argc);
38 * @funct SignalHandler
39 * @purpose Handle signals
40 * @param sig - The signal
42 void SignalHandler(int sig)
44 // At the moment just always exit.
45 // Call `exit` so that Cleanup will be called to... clean up.
46 Log(LOGWARN, "SignalHandler", "Got signal %d (%s). Exiting.", sig, strsignal(sig));
52 * @purpose Called when program exits
56 Log(LOGDEBUG, "Cleanup", "Begin cleanup.");
57 Log(LOGDEBUG, "Cleanup", "Finish cleanup.");
63 * @purpose Main entry point; start worker threads, setup signal handling, wait for threads to exit, exit
64 * @param argc - Num args
66 * @returns 0 on success, error code on failure
68 int main(int argc, char ** argv)