3 * @purpose main and its helper functions, signal handling and cleanup functions
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
15 // --- Custom headers --- //
19 // --- Variable definitions --- //
20 Options g_options; // options passed to program through command line arguments
22 // --- Function definitions --- //
25 * Parse command line arguments, initialise g_options
26 * @param argc - Number of arguments
27 * @param argv - Array of argument strings
29 void ParseArguments(int argc, char ** argv)
31 g_options.program = argv[0]; // program name
32 g_options.verbosity = LOGDEBUG; // default log level
33 Log(LOGDEBUG, "Called as %s with %d arguments.", g_options.program, argc);
38 * @param signal - The signal number
40 void SignalHandler(int signal)
42 // At the moment just always exit.
43 // Call `exit` so that Cleanup will be called to... clean up.
44 Log(LOGWARN, "Got signal %d (%s). Exiting.", sig, strsignal(sig));
49 * Cleanup before the program exits
53 Log(LOGDEBUG, "Begin cleanup.");
54 Log(LOGDEBUG, "Finish cleanup.");
59 * Main entry point; start worker threads, setup signal handling, wait for threads to exit, exit
60 * @param argc - Num args
62 * @returns 0 on success, error code on failure
64 int main(int argc, char ** argv)
66 ParseArguments(argc, argv, &g_options);