]> Nishi Git Mirror - tewi.git/commitdiff
logfile works
authorNishi <nishi@nishi.boats>
Sat, 21 Sep 2024 08:47:51 +0000 (08:47 +0000)
committerNishi <nishi@nishi.boats>
Sat, 21 Sep 2024 08:47:51 +0000 (08:47 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@117 8739d7e6-ffea-ec47-b151-bdff447c6205

Server/main.c
Server/server.c

index 433449ea4924181bee1cdd19637fe2e9fd493520..aabee6c580269f6d231dcae5a2e181e70ea07ce7 100644 (file)
@@ -112,6 +112,20 @@ int startup(int argc, char** argv) {
                                                return 1;
                                        }
                                        confpath = argv[i];
+                               } else if(strcmp(argv[i], "--logfile") == 0 || strcmp(argv[i], "-l") == 0) {
+                                       i++;
+                                       if(argv[i] == NULL) {
+                                               fprintf(stderr, "Missing argument\n");
+                                               return 1;
+                                       }
+                                       if(logfile != NULL && logfile != stderr) {
+                                               fclose(logfile);
+                                       }
+                                       logfile = fopen(argv[i], "a");
+                                       if(logfile == NULL) {
+                                               fprintf(stderr, "Failed to open logfile\n");
+                                               return 1;
+                                       }
                                } else if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) {
                                        printf("Tewi HTTPd Tewi/%s\n", tw_get_version());
                                        printf("Under public domain.\n");
index 6f4fda0e3f4c5e77c02f660a506a60415bbb8026..2525ea3d9cf48de24ee06bd9374d7e9a12fbc377 100644 (file)
@@ -456,8 +456,8 @@ int32_t tw_server_pass(void* ptr) {
                char* useragent = cm_strdup("");
 
                int i;
-               for(i = 0; req.headers[i] != NULL; i += 2){
-                       if(cm_strcaseequ(req.headers[i], "User-Agent")){
+               for(i = 0; req.headers[i] != NULL; i += 2) {
+                       if(cm_strcaseequ(req.headers[i], "User-Agent")) {
                                free(useragent);
                                useragent = cm_strdup(req.headers[i + 1]);
                        }