Fossil SCM

Improvements to error logging. Only log fossil_panic() calls, not fossil_fatal() calls.

drh 2018-07-15 18:31 trunk
Commit 06d4751a4471c220a35c9300f73faf23596b36bda720d2a95bee0bc96760aac1
+1 -1
--- src/cgi.c
+++ src/cgi.c
@@ -343,11 +343,11 @@
343343
CGIDEBUG(("DONE\n"));
344344
345345
/* After the webpage has been sent, do any useful background
346346
** processing.
347347
*/
348
- if( iReplyStatus==200 ){
348
+ if( iReplyStatus==200 && fossil_strcmp(zContentType,"test/html")==0 ){
349349
email_auto_exec();
350350
}
351351
}
352352
353353
/*
354354
--- src/cgi.c
+++ src/cgi.c
@@ -343,11 +343,11 @@
343 CGIDEBUG(("DONE\n"));
344
345 /* After the webpage has been sent, do any useful background
346 ** processing.
347 */
348 if( iReplyStatus==200 ){
349 email_auto_exec();
350 }
351 }
352
353 /*
354
--- src/cgi.c
+++ src/cgi.c
@@ -343,11 +343,11 @@
343 CGIDEBUG(("DONE\n"));
344
345 /* After the webpage has been sent, do any useful background
346 ** processing.
347 */
348 if( iReplyStatus==200 && fossil_strcmp(zContentType,"test/html")==0 ){
349 email_auto_exec();
350 }
351 }
352
353 /*
354
+46 -68
--- src/printf.c
+++ src/printf.c
@@ -1026,14 +1026,49 @@
10261026
** The following variable becomes true while processing a fatal error
10271027
** or a panic. If additional "recursive-fatal" errors occur while
10281028
** shutting down, the recursive errors are silently ignored.
10291029
*/
10301030
static int mainInFatalError = 0;
1031
+
1032
+/*
1033
+** Write error message output
1034
+*/
1035
+static int fossil_print_error(int rc, const char *z){
1036
+#ifdef FOSSIL_ENABLE_JSON
1037
+ if( g.json.isJsonMode ){
1038
+ json_err( 0, z, 1 );
1039
+ if( g.isHTTP ){
1040
+ rc = 0 /* avoid HTTP 500 */;
1041
+ }
1042
+ }
1043
+ else
1044
+#endif
1045
+ if( g.cgiOutput==1 && g.db ){
1046
+ g.cgiOutput = 2;
1047
+ cgi_reset_content();
1048
+ cgi_set_content_type("text/html");
1049
+ style_header("Bad Request");
1050
+ @ <p class="generalError">%h(z)</p>
1051
+ cgi_set_status(400, "Bad Request");
1052
+ style_footer();
1053
+ cgi_reply();
1054
+ }else if( !g.fQuiet ){
1055
+ fossil_force_newline();
1056
+ fossil_trace("%s\n", z);
1057
+ }
1058
+ return rc;
1059
+}
10311060
10321061
/*
10331062
** Print an error message, rollback all databases, and quit. These
10341063
** routines never return.
1064
+**
1065
+** Use fossil_fatal() for malformed inputs that should be reported back
1066
+** to the user, but which do not represent a configuration problem or bug.
1067
+**
1068
+** Use fossil_panic() for any kind of error that should be brought to the
1069
+** attention of the system administrator.
10351070
*/
10361071
NORETURN void fossil_panic(const char *zFormat, ...){
10371072
va_list ap;
10381073
int rc = 1;
10391074
char z[1000];
@@ -1045,67 +1080,22 @@
10451080
db_force_rollback();
10461081
va_start(ap, zFormat);
10471082
sqlite3_vsnprintf(sizeof(z),z,zFormat, ap);
10481083
va_end(ap);
10491084
fossil_errorlog("panic: %s", z);
1050
-#ifdef FOSSIL_ENABLE_JSON
1051
- if( g.json.isJsonMode ){
1052
- json_err( 0, z, 1 );
1053
- if( g.isHTTP ){
1054
- rc = 0 /* avoid HTTP 500 */;
1055
- }
1056
- }
1057
- else
1058
-#endif
1059
- {
1060
- if( g.cgiOutput ){
1061
- cgi_printf("<p class=\"generalError\">%h</p>", z);
1062
- cgi_set_status(500, "Internal Server Error");
1063
- cgi_reply();
1064
- }else if( !g.fQuiet ){
1065
- fossil_force_newline();
1066
- fossil_puts("Fossil internal error: ", 1);
1067
- fossil_puts(z, 1);
1068
- fossil_puts("\n", 1);
1069
- }
1070
- }
1085
+ rc = fossil_print_error(rc, z);
10711086
exit(rc);
10721087
}
1073
-
10741088
NORETURN void fossil_fatal(const char *zFormat, ...){
10751089
char *z;
10761090
int rc = 1;
10771091
va_list ap;
10781092
mainInFatalError = 1;
10791093
va_start(ap, zFormat);
10801094
z = vmprintf(zFormat, ap);
10811095
va_end(ap);
1082
- fossil_errorlog("fatal: %s", z);
1083
-#ifdef FOSSIL_ENABLE_JSON
1084
- if( g.json.isJsonMode ){
1085
- json_err( g.json.resultCode, z, 1 );
1086
- if( g.isHTTP ){
1087
- rc = 0 /* avoid HTTP 500 */;
1088
- }
1089
- }
1090
- else
1091
-#endif
1092
- {
1093
- if( g.cgiOutput==1 && g.db ){
1094
- g.cgiOutput = 2;
1095
- cgi_reset_content();
1096
- cgi_set_content_type("text/html");
1097
- style_header("Bad Request");
1098
- @ <p class="generalError">%h(z)</p>
1099
- cgi_set_status(400, "Bad Request");
1100
- style_footer();
1101
- cgi_reply();
1102
- }else if( !g.fQuiet ){
1103
- fossil_force_newline();
1104
- fossil_trace("%s\n", z);
1105
- }
1106
- }
1096
+ rc = fossil_print_error(rc, z);
11071097
fossil_free(z);
11081098
db_force_rollback();
11091099
fossil_exit(rc);
11101100
}
11111101
@@ -1125,36 +1115,24 @@
11251115
if( mainInFatalError ) return;
11261116
mainInFatalError = 1;
11271117
va_start(ap, zFormat);
11281118
z = vmprintf(zFormat, ap);
11291119
va_end(ap);
1130
- fossil_errorlog("fatal: %s", z);
1131
-#ifdef FOSSIL_ENABLE_JSON
1132
- if( g.json.isJsonMode ){
1133
- json_err( g.json.resultCode, z, 1 );
1134
- if( g.isHTTP ){
1135
- rc = 0 /* avoid HTTP 500 */;
1136
- }
1137
- } else
1138
-#endif
1139
- {
1140
- if( g.cgiOutput ){
1141
- g.cgiOutput = 0;
1142
- cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
1143
- cgi_set_status(400, "Bad Request");
1144
- cgi_reply();
1145
- }else{
1146
- fossil_force_newline();
1147
- fossil_trace("%s\n", z);
1148
- }
1149
- }
1120
+ rc = fossil_print_error(rc, z);
11501121
db_force_rollback();
11511122
fossil_exit(rc);
11521123
}
11531124
11541125
1155
-/* Print a warning message */
1126
+/* Print a warning message.
1127
+**
1128
+** Unlike fossil_fatal() and fossil_panic(), this routine does return
1129
+** and processing attempts to continue. A message is written to the
1130
+** error log, however, so this routine should only be used for situations
1131
+** that require administrator or developer attention. Minor problems
1132
+** in user inputs should not use this routine.
1133
+*/
11561134
void fossil_warning(const char *zFormat, ...){
11571135
char *z;
11581136
va_list ap;
11591137
va_start(ap, zFormat);
11601138
z = vmprintf(zFormat, ap);
11611139
--- src/printf.c
+++ src/printf.c
@@ -1026,14 +1026,49 @@
1026 ** The following variable becomes true while processing a fatal error
1027 ** or a panic. If additional "recursive-fatal" errors occur while
1028 ** shutting down, the recursive errors are silently ignored.
1029 */
1030 static int mainInFatalError = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1031
1032 /*
1033 ** Print an error message, rollback all databases, and quit. These
1034 ** routines never return.
 
 
 
 
 
 
1035 */
1036 NORETURN void fossil_panic(const char *zFormat, ...){
1037 va_list ap;
1038 int rc = 1;
1039 char z[1000];
@@ -1045,67 +1080,22 @@
1045 db_force_rollback();
1046 va_start(ap, zFormat);
1047 sqlite3_vsnprintf(sizeof(z),z,zFormat, ap);
1048 va_end(ap);
1049 fossil_errorlog("panic: %s", z);
1050 #ifdef FOSSIL_ENABLE_JSON
1051 if( g.json.isJsonMode ){
1052 json_err( 0, z, 1 );
1053 if( g.isHTTP ){
1054 rc = 0 /* avoid HTTP 500 */;
1055 }
1056 }
1057 else
1058 #endif
1059 {
1060 if( g.cgiOutput ){
1061 cgi_printf("<p class=\"generalError\">%h</p>", z);
1062 cgi_set_status(500, "Internal Server Error");
1063 cgi_reply();
1064 }else if( !g.fQuiet ){
1065 fossil_force_newline();
1066 fossil_puts("Fossil internal error: ", 1);
1067 fossil_puts(z, 1);
1068 fossil_puts("\n", 1);
1069 }
1070 }
1071 exit(rc);
1072 }
1073
1074 NORETURN void fossil_fatal(const char *zFormat, ...){
1075 char *z;
1076 int rc = 1;
1077 va_list ap;
1078 mainInFatalError = 1;
1079 va_start(ap, zFormat);
1080 z = vmprintf(zFormat, ap);
1081 va_end(ap);
1082 fossil_errorlog("fatal: %s", z);
1083 #ifdef FOSSIL_ENABLE_JSON
1084 if( g.json.isJsonMode ){
1085 json_err( g.json.resultCode, z, 1 );
1086 if( g.isHTTP ){
1087 rc = 0 /* avoid HTTP 500 */;
1088 }
1089 }
1090 else
1091 #endif
1092 {
1093 if( g.cgiOutput==1 && g.db ){
1094 g.cgiOutput = 2;
1095 cgi_reset_content();
1096 cgi_set_content_type("text/html");
1097 style_header("Bad Request");
1098 @ <p class="generalError">%h(z)</p>
1099 cgi_set_status(400, "Bad Request");
1100 style_footer();
1101 cgi_reply();
1102 }else if( !g.fQuiet ){
1103 fossil_force_newline();
1104 fossil_trace("%s\n", z);
1105 }
1106 }
1107 fossil_free(z);
1108 db_force_rollback();
1109 fossil_exit(rc);
1110 }
1111
@@ -1125,36 +1115,24 @@
1125 if( mainInFatalError ) return;
1126 mainInFatalError = 1;
1127 va_start(ap, zFormat);
1128 z = vmprintf(zFormat, ap);
1129 va_end(ap);
1130 fossil_errorlog("fatal: %s", z);
1131 #ifdef FOSSIL_ENABLE_JSON
1132 if( g.json.isJsonMode ){
1133 json_err( g.json.resultCode, z, 1 );
1134 if( g.isHTTP ){
1135 rc = 0 /* avoid HTTP 500 */;
1136 }
1137 } else
1138 #endif
1139 {
1140 if( g.cgiOutput ){
1141 g.cgiOutput = 0;
1142 cgi_printf("<p class=\"generalError\">\n%h\n</p>\n", z);
1143 cgi_set_status(400, "Bad Request");
1144 cgi_reply();
1145 }else{
1146 fossil_force_newline();
1147 fossil_trace("%s\n", z);
1148 }
1149 }
1150 db_force_rollback();
1151 fossil_exit(rc);
1152 }
1153
1154
1155 /* Print a warning message */
 
 
 
 
 
 
 
1156 void fossil_warning(const char *zFormat, ...){
1157 char *z;
1158 va_list ap;
1159 va_start(ap, zFormat);
1160 z = vmprintf(zFormat, ap);
1161
--- src/printf.c
+++ src/printf.c
@@ -1026,14 +1026,49 @@
1026 ** The following variable becomes true while processing a fatal error
1027 ** or a panic. If additional "recursive-fatal" errors occur while
1028 ** shutting down, the recursive errors are silently ignored.
1029 */
1030 static int mainInFatalError = 0;
1031
1032 /*
1033 ** Write error message output
1034 */
1035 static int fossil_print_error(int rc, const char *z){
1036 #ifdef FOSSIL_ENABLE_JSON
1037 if( g.json.isJsonMode ){
1038 json_err( 0, z, 1 );
1039 if( g.isHTTP ){
1040 rc = 0 /* avoid HTTP 500 */;
1041 }
1042 }
1043 else
1044 #endif
1045 if( g.cgiOutput==1 && g.db ){
1046 g.cgiOutput = 2;
1047 cgi_reset_content();
1048 cgi_set_content_type("text/html");
1049 style_header("Bad Request");
1050 @ <p class="generalError">%h(z)</p>
1051 cgi_set_status(400, "Bad Request");
1052 style_footer();
1053 cgi_reply();
1054 }else if( !g.fQuiet ){
1055 fossil_force_newline();
1056 fossil_trace("%s\n", z);
1057 }
1058 return rc;
1059 }
1060
1061 /*
1062 ** Print an error message, rollback all databases, and quit. These
1063 ** routines never return.
1064 **
1065 ** Use fossil_fatal() for malformed inputs that should be reported back
1066 ** to the user, but which do not represent a configuration problem or bug.
1067 **
1068 ** Use fossil_panic() for any kind of error that should be brought to the
1069 ** attention of the system administrator.
1070 */
1071 NORETURN void fossil_panic(const char *zFormat, ...){
1072 va_list ap;
1073 int rc = 1;
1074 char z[1000];
@@ -1045,67 +1080,22 @@
1080 db_force_rollback();
1081 va_start(ap, zFormat);
1082 sqlite3_vsnprintf(sizeof(z),z,zFormat, ap);
1083 va_end(ap);
1084 fossil_errorlog("panic: %s", z);
1085 rc = fossil_print_error(rc, z);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1086 exit(rc);
1087 }
 
1088 NORETURN void fossil_fatal(const char *zFormat, ...){
1089 char *z;
1090 int rc = 1;
1091 va_list ap;
1092 mainInFatalError = 1;
1093 va_start(ap, zFormat);
1094 z = vmprintf(zFormat, ap);
1095 va_end(ap);
1096 rc = fossil_print_error(rc, z);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1097 fossil_free(z);
1098 db_force_rollback();
1099 fossil_exit(rc);
1100 }
1101
@@ -1125,36 +1115,24 @@
1115 if( mainInFatalError ) return;
1116 mainInFatalError = 1;
1117 va_start(ap, zFormat);
1118 z = vmprintf(zFormat, ap);
1119 va_end(ap);
1120 rc = fossil_print_error(rc, z);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1121 db_force_rollback();
1122 fossil_exit(rc);
1123 }
1124
1125
1126 /* Print a warning message.
1127 **
1128 ** Unlike fossil_fatal() and fossil_panic(), this routine does return
1129 ** and processing attempts to continue. A message is written to the
1130 ** error log, however, so this routine should only be used for situations
1131 ** that require administrator or developer attention. Minor problems
1132 ** in user inputs should not use this routine.
1133 */
1134 void fossil_warning(const char *zFormat, ...){
1135 char *z;
1136 va_list ap;
1137 va_start(ap, zFormat);
1138 z = vmprintf(zFormat, ap);
1139
--- src/security_audit.c
+++ src/security_audit.c
@@ -414,10 +414,11 @@
414414
if( !g.perm.Setup && !g.perm.Admin ){
415415
login_needed(0);
416416
return;
417417
}
418418
style_header("Server Error Log");
419
+ style_submenu_element("Test", "%R/test-warning");
419420
if( g.zErrlog==0 || fossil_strcmp(g.zErrlog,"-")==0 ){
420421
@ <p>To create a server error log:
421422
@ <ol>
422423
@ <li><p>
423424
@ If the server is running as CGI, then create a line in the CGI file
@@ -453,11 +454,10 @@
453454
@ </form>
454455
style_footer();
455456
return;
456457
}
457458
@ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
458
- style_submenu_element("Test", "%R/test-warning");
459459
style_submenu_element("Download", "%R/errorlog?download");
460460
style_submenu_element("Truncate", "%R/errorlog?truncate");
461461
in = fossil_fopen(g.zErrlog, "rb");
462462
if( in==0 ){
463463
@ <p class='generalError'>Unable top open that file for reading!</p>
464464
--- src/security_audit.c
+++ src/security_audit.c
@@ -414,10 +414,11 @@
414 if( !g.perm.Setup && !g.perm.Admin ){
415 login_needed(0);
416 return;
417 }
418 style_header("Server Error Log");
 
419 if( g.zErrlog==0 || fossil_strcmp(g.zErrlog,"-")==0 ){
420 @ <p>To create a server error log:
421 @ <ol>
422 @ <li><p>
423 @ If the server is running as CGI, then create a line in the CGI file
@@ -453,11 +454,10 @@
453 @ </form>
454 style_footer();
455 return;
456 }
457 @ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
458 style_submenu_element("Test", "%R/test-warning");
459 style_submenu_element("Download", "%R/errorlog?download");
460 style_submenu_element("Truncate", "%R/errorlog?truncate");
461 in = fossil_fopen(g.zErrlog, "rb");
462 if( in==0 ){
463 @ <p class='generalError'>Unable top open that file for reading!</p>
464
--- src/security_audit.c
+++ src/security_audit.c
@@ -414,10 +414,11 @@
414 if( !g.perm.Setup && !g.perm.Admin ){
415 login_needed(0);
416 return;
417 }
418 style_header("Server Error Log");
419 style_submenu_element("Test", "%R/test-warning");
420 if( g.zErrlog==0 || fossil_strcmp(g.zErrlog,"-")==0 ){
421 @ <p>To create a server error log:
422 @ <ol>
423 @ <li><p>
424 @ If the server is running as CGI, then create a line in the CGI file
@@ -453,11 +454,10 @@
454 @ </form>
455 style_footer();
456 return;
457 }
458 @ <p>The server error log at "%h(g.zErrlog)" is %,lld(szFile) bytes in size.
 
459 style_submenu_element("Download", "%R/errorlog?download");
460 style_submenu_element("Truncate", "%R/errorlog?truncate");
461 in = fossil_fopen(g.zErrlog, "rb");
462 if( in==0 ){
463 @ <p class='generalError'>Unable top open that file for reading!</p>
464

Keyboard Shortcuts

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