Fossil SCM
In cgi_trace(), keep one log file name per process and append to it when the log is opened again, so that --httptrace keeps the request header of a POST instead of overwriting it with the content.
Commit
9eec3e7249607a9e72964b31b51b42c4afab1833c7c62e0abaf0369ddb91dab4
Parent
73a2d5e978b0b00…
1 file changed
+9
-6
+9
-6
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -1288,26 +1288,29 @@ | ||
| 1288 | 1288 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1289 | 1289 | ** when the argument is NULL. |
| 1290 | 1290 | */ |
| 1291 | 1291 | void cgi_trace(const char *z){ |
| 1292 | 1292 | static FILE *pLog = 0; |
| 1293 | + static char zFile[50]; | |
| 1293 | 1294 | if( g.fHttpTrace==0 ) return; |
| 1294 | 1295 | if( z==0 ){ |
| 1295 | 1296 | if( pLog ) fclose(pLog); |
| 1296 | 1297 | pLog = 0; |
| 1297 | 1298 | return; |
| 1298 | 1299 | } |
| 1299 | 1300 | if( pLog==0 ){ |
| 1300 | - char zFile[50]; | |
| 1301 | + const char *zMode = zFile[0] ? "ab" : "wb"; | |
| 1302 | + if( zFile[0]==0 ){ | |
| 1301 | 1303 | #if defined(_WIN32) |
| 1302 | - unsigned r; | |
| 1303 | - sqlite3_randomness(sizeof(r), &r); | |
| 1304 | - sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); | |
| 1304 | + unsigned r; | |
| 1305 | + sqlite3_randomness(sizeof(r), &r); | |
| 1306 | + sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); | |
| 1305 | 1307 | #else |
| 1306 | - sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); | |
| 1308 | + sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); | |
| 1307 | 1309 | #endif |
| 1308 | - pLog = fossil_fopen(zFile, "wb"); | |
| 1310 | + } | |
| 1311 | + pLog = fossil_fopen(zFile, zMode); | |
| 1309 | 1312 | if( pLog ){ |
| 1310 | 1313 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1311 | 1314 | }else{ |
| 1312 | 1315 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1313 | 1316 | return; |
| 1314 | 1317 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -1288,26 +1288,29 @@ | |
| 1288 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1289 | ** when the argument is NULL. |
| 1290 | */ |
| 1291 | void cgi_trace(const char *z){ |
| 1292 | static FILE *pLog = 0; |
| 1293 | if( g.fHttpTrace==0 ) return; |
| 1294 | if( z==0 ){ |
| 1295 | if( pLog ) fclose(pLog); |
| 1296 | pLog = 0; |
| 1297 | return; |
| 1298 | } |
| 1299 | if( pLog==0 ){ |
| 1300 | char zFile[50]; |
| 1301 | #if defined(_WIN32) |
| 1302 | unsigned r; |
| 1303 | sqlite3_randomness(sizeof(r), &r); |
| 1304 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); |
| 1305 | #else |
| 1306 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); |
| 1307 | #endif |
| 1308 | pLog = fossil_fopen(zFile, "wb"); |
| 1309 | if( pLog ){ |
| 1310 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1311 | }else{ |
| 1312 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1313 | return; |
| 1314 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -1288,26 +1288,29 @@ | |
| 1288 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 1289 | ** when the argument is NULL. |
| 1290 | */ |
| 1291 | void cgi_trace(const char *z){ |
| 1292 | static FILE *pLog = 0; |
| 1293 | static char zFile[50]; |
| 1294 | if( g.fHttpTrace==0 ) return; |
| 1295 | if( z==0 ){ |
| 1296 | if( pLog ) fclose(pLog); |
| 1297 | pLog = 0; |
| 1298 | return; |
| 1299 | } |
| 1300 | if( pLog==0 ){ |
| 1301 | const char *zMode = zFile[0] ? "ab" : "wb"; |
| 1302 | if( zFile[0]==0 ){ |
| 1303 | #if defined(_WIN32) |
| 1304 | unsigned r; |
| 1305 | sqlite3_randomness(sizeof(r), &r); |
| 1306 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); |
| 1307 | #else |
| 1308 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid()); |
| 1309 | #endif |
| 1310 | } |
| 1311 | pLog = fossil_fopen(zFile, zMode); |
| 1312 | if( pLog ){ |
| 1313 | fprintf(stderr, "# open log on %s\n", zFile); |
| 1314 | }else{ |
| 1315 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 1316 | return; |
| 1317 |