| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "server.h" | ||
| 5 | #include "config.h" | ||
| 6 | #include "log.h" | ||
| 7 | |||
| 8 | ✗ | int main(int argc, char **argv) { | |
| 9 | ServerConfig config; | ||
| 10 | ✗ | char *config_path = "config.yaml"; | |
| 11 | |||
| 12 | // allow --config <file> | ||
| 13 | ✗ | for (int i = 1; i < argc; i++) { | |
| 14 | ✗ | if (strcmp(argv[i], "--config") == 0 && i + 1 < argc) { | |
| 15 | ✗ | config_path = argv[++i]; | |
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | ✗ | if (load_config(&config, config_path) != 0) { | |
| 20 | ✗ | fprintf(stderr, "Error loading configuration from %s\n", config_path); | |
| 21 | ✗ | return 1; | |
| 22 | } | ||
| 23 | |||
| 24 | ✗ | if (log_init(&config.logging) != 0) { | |
| 25 | ✗ | fprintf(stderr, "Error initializing logging"); | |
| 26 | ✗ | exit(EXIT_FAILURE); | |
| 27 | } | ||
| 28 | |||
| 29 | ✗ | log_message(LOG_LEVEL_INFO, "Starting server on port %d", | |
| 30 | config.port, config.max_connections); | ||
| 31 | |||
| 32 | ✗ | if (start_server(&config) != 0) { | |
| 33 | ✗ | log_message(LOG_LEVEL_ERROR, "Error starting server"); | |
| 34 | ✗ | log_shutdown(); | |
| 35 | ✗ | exit(EXIT_FAILURE); | |
| 36 | } | ||
| 37 | |||
| 38 | ✗ | log_shutdown(); | |
| 39 | ✗ | return EXIT_SUCCESS; | |
| 40 | } | ||
| 41 |