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