123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #define _GNU_SOURCE
- #include "daemonize.h"
- #include "dbus_messaging.h"
- #include "gamemode.h"
- #include "logging.h"
- #include <signal.h>
- #include <string.h>
- #include <unistd.h>
- static void sigint_handler(__attribute__((unused)) int signo)
- {
- LOG_MSG("Quitting by request...\n");
-
- game_mode_context_destroy(game_mode_context_instance());
- exit(EXIT_SUCCESS);
- }
- int main(int argc, char *argv[])
- {
- GameModeContext *context = NULL;
-
- bool daemon = false;
- bool use_syslog = false;
- int opt = 0;
- while ((opt = getopt(argc, argv, "dl")) != -1) {
- switch (opt) {
- case 'd':
- daemon = true;
- break;
- case 'l':
- use_syslog = true;
- break;
- default:
- fprintf(stderr, "Usage: %s [-d] [-l]\n", argv[0]);
- exit(EXIT_FAILURE);
- break;
- }
- }
-
- if (use_syslog) {
- set_use_syslog(argv[0]);
- }
-
- if (daemon) {
- daemonize(argv[0]);
- }
-
- context = game_mode_context_instance();
- game_mode_context_init(context);
-
- if (signal(SIGINT, sigint_handler) == SIG_ERR) {
- FATAL_ERRORNO("Could not catch SIGINT");
- }
-
- game_mode_context_loop(context);
- game_mode_context_destroy(context);
-
- LOG_MSG("Quitting naturally...\n");
- }
|