Rev | Line | |
---|
[2] | 1 | /* $Id: main.c 16 2024-09-13 15:09:52Z nishi $ */
|
---|
| 2 |
|
---|
[16] | 3 | #define SOURCE
|
---|
| 4 |
|
---|
[3] | 5 | #include <stdio.h>
|
---|
| 6 | #include <stdbool.h>
|
---|
| 7 | #include <string.h>
|
---|
[16] | 8 | #include <signal.h>
|
---|
[3] | 9 |
|
---|
[6] | 10 | #include <openssl/opensslv.h>
|
---|
| 11 |
|
---|
[3] | 12 | #include <cm_log.h>
|
---|
| 13 |
|
---|
[4] | 14 | #include "tw_config.h"
|
---|
[8] | 15 | #include "tw_server.h"
|
---|
[3] | 16 | #include "tw_version.h"
|
---|
| 17 |
|
---|
| 18 | extern bool cm_do_log;
|
---|
| 19 |
|
---|
| 20 | int main(int argc, char** argv) {
|
---|
| 21 | int i;
|
---|
[4] | 22 | const char* config = PREFIX "/etc/tewi.conf";
|
---|
[3] | 23 | for(i = 1; i < argc; i++) {
|
---|
| 24 | if(argv[i][0] == '-') {
|
---|
| 25 | if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
---|
| 26 | if(!cm_do_log) {
|
---|
| 27 | cm_do_log = true;
|
---|
[6] | 28 | cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
|
---|
[3] | 29 | } else {
|
---|
| 30 | cm_do_log = true;
|
---|
| 31 | }
|
---|
[6] | 32 | } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
|
---|
[4] | 33 | i++;
|
---|
[6] | 34 | if(argv[i] == NULL) {
|
---|
[4] | 35 | fprintf(stderr, "Missing argument\n");
|
---|
| 36 | return 1;
|
---|
| 37 | }
|
---|
| 38 | config = argv[i];
|
---|
[3] | 39 | } else {
|
---|
| 40 | fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
---|
| 41 | return 1;
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
[6] | 45 | tw_config_init();
|
---|
| 46 | if(tw_config_read(config) != 0) {
|
---|
[4] | 47 | fprintf(stderr, "Could not read the config\n");
|
---|
| 48 | return 1;
|
---|
| 49 | }
|
---|
[8] | 50 | if(tw_server_init() != 0) {
|
---|
| 51 | fprintf(stderr, "Could not initialize the server\n");
|
---|
| 52 | return 1;
|
---|
| 53 | }
|
---|
[3] | 54 | cm_log("Daemon", "Ready");
|
---|
[16] | 55 | #ifndef __MINGW32__
|
---|
| 56 | signal(SIGCHLD, SIG_IGN);
|
---|
| 57 | #endif
|
---|
[9] | 58 | tw_server_loop();
|
---|
[3] | 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.