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.

dmestas 2026-11-21 10:43 UTC small-fixes
Commit 9eec3e7249607a9e72964b31b51b42c4afab1833c7c62e0abaf0369ddb91dab4
1 file changed +9 -6
+9 -6
--- src/cgi.c
+++ src/cgi.c
@@ -1288,26 +1288,29 @@
12881288
** Log HTTP traffic to a file. Begin the log on first use. Close the log
12891289
** when the argument is NULL.
12901290
*/
12911291
void cgi_trace(const char *z){
12921292
static FILE *pLog = 0;
1293
+ static char zFile[50];
12931294
if( g.fHttpTrace==0 ) return;
12941295
if( z==0 ){
12951296
if( pLog ) fclose(pLog);
12961297
pLog = 0;
12971298
return;
12981299
}
12991300
if( pLog==0 ){
1300
- char zFile[50];
1301
+ const char *zMode = zFile[0] ? "ab" : "wb";
1302
+ if( zFile[0]==0 ){
13011303
#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);
13051307
#else
1306
- sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid());
1308
+ sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%05d.txt", getpid());
13071309
#endif
1308
- pLog = fossil_fopen(zFile, "wb");
1310
+ }
1311
+ pLog = fossil_fopen(zFile, zMode);
13091312
if( pLog ){
13101313
fprintf(stderr, "# open log on %s\n", zFile);
13111314
}else{
13121315
fprintf(stderr, "# failed to open %s\n", zFile);
13131316
return;
13141317
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button