X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=main.cpp;h=e953a8cea29d79da4579adb06a3580e989598a28;hp=064537cd79a0572ef706e66c52106ce522f8026d;hb=4f4e1384b4299611924a39f59f536b4964806135;hpb=9819131192eec224aa3aef48ef228604b6b098e5 diff --git a/main.cpp b/main.cpp index 064537c..e953a8c 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ #include #include +#include "accesslog.h" #include "acceptor.h" #include "config.h" #include "input.h" @@ -29,7 +30,9 @@ using namespace std; +AccessLogThread *access_log = NULL; ServerPool *servers = NULL; +vector mark_pools; volatile bool hupped = false; volatile bool stopped = false; @@ -140,7 +143,6 @@ void create_streams(const Config &config, const set &deserialized_stream_ids, map *deserialized_inputs) { - vector mark_pools; // FIXME: leak for (unsigned i = 0; i < config.mark_pools.size(); ++i) { const MarkPoolConfig &mp_config = config.mark_pools[i]; mark_pools.push_back(new MarkPool(mp_config.from, mp_config.to)); @@ -246,9 +248,10 @@ int main(int argc, char **argv) static const option long_options[] = { { "state", required_argument, 0, 's' }, { "test-config", no_argument, 0, 't' }, + { 0, 0, 0, 0 } }; int option_index = 0; - int c = getopt_long (argc, argv, "s:t", long_options, &option_index); + int c = getopt_long(argc, argv, "s:t", long_options, &option_index); if (c == -1) { break; @@ -261,7 +264,8 @@ int main(int argc, char **argv) test_config = true; break; default: - assert(false); + fprintf(stderr, "Unknown option '%s'\n", argv[option_index]); + exit(1); } } @@ -275,11 +279,11 @@ int main(int argc, char **argv) char config_filename_canon[PATH_MAX]; if (realpath(argv[0], argv0_canon) == NULL) { - log_perror("realpath"); + log_perror(argv[0]); exit(1); } if (realpath(config_filename.c_str(), config_filename_canon) == NULL) { - log_perror("realpath"); + log_perror(config_filename.c_str()); exit(1); } @@ -307,6 +311,14 @@ start: open_logs(config.log_destinations); log(INFO, "Cubemap " SERVER_VERSION " starting."); + if (config.access_log_file.empty()) { + // Create a dummy logger. + access_log = new AccessLogThread(); + } else { + access_log = new AccessLogThread(config.access_log_file); + } + access_log->run(); + servers = new ServerPool(config.num_servers); CubemapStateProto loaded_state; @@ -396,6 +408,7 @@ start: if (stats_thread != NULL) { stats_thread->stop(); + delete stats_thread; } for (size_t i = 0; i < acceptors.size(); ++i) { acceptors[i]->stop(); @@ -420,6 +433,14 @@ start: } } delete servers; + + for (unsigned i = 0; i < mark_pools.size(); ++i) { + delete mark_pools[i]; + } + mark_pools.clear(); + + access_log->stop(); + delete access_log; shut_down_logging(); if (stopped) {