Fossil SCM
Per /chat discussion, replace load_control() calls in selective pages with nice() and move load_control() into process_one_web_page(). There is still work to do here, e.g. allowing certain pages through (namely /chat, to facilitate coordination of site defense) and perhaps checking credentials if the load is too high and always allowing admin users.
Commit
9b0ebcaf23572a78e4a842dcde6dba4022af9a38f0cf51e1fad6dbaf64462e0a
Parent
82510672b8f61c5…
8 files changed
+1
-1
+1
-1
+2
-2
+1
-1
+1
-1
+1
-1
+19
+1
-1
+1
-1
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -3594,11 +3594,11 @@ | ||
| 3594 | 3594 | |
| 3595 | 3595 | /* Gather query parameters */ |
| 3596 | 3596 | login_check_credentials(); |
| 3597 | 3597 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 3598 | 3598 | if( exclude_spiders() ) return; |
| 3599 | - load_control(); | |
| 3599 | + fossil_nice_default(); | |
| 3600 | 3600 | zFilename = P("filename"); |
| 3601 | 3601 | zRevision = PD("checkin",0); |
| 3602 | 3602 | zOrigin = P("origin"); |
| 3603 | 3603 | zLimit = P("limit"); |
| 3604 | 3604 | showLog = PB("log"); |
| 3605 | 3605 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -3594,11 +3594,11 @@ | |
| 3594 | |
| 3595 | /* Gather query parameters */ |
| 3596 | login_check_credentials(); |
| 3597 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 3598 | if( exclude_spiders() ) return; |
| 3599 | load_control(); |
| 3600 | zFilename = P("filename"); |
| 3601 | zRevision = PD("checkin",0); |
| 3602 | zOrigin = P("origin"); |
| 3603 | zLimit = P("limit"); |
| 3604 | showLog = PB("log"); |
| 3605 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -3594,11 +3594,11 @@ | |
| 3594 | |
| 3595 | /* Gather query parameters */ |
| 3596 | login_check_credentials(); |
| 3597 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 3598 | if( exclude_spiders() ) return; |
| 3599 | fossil_nice_default(); |
| 3600 | zFilename = P("filename"); |
| 3601 | zRevision = PD("checkin",0); |
| 3602 | zOrigin = P("origin"); |
| 3603 | zLimit = P("limit"); |
| 3604 | showLog = PB("log"); |
| 3605 |
+1
-1
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1182,11 +1182,11 @@ | ||
| 1182 | 1182 | int bInvert = PB("inv"); |
| 1183 | 1183 | |
| 1184 | 1184 | login_check_credentials(); |
| 1185 | 1185 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1186 | 1186 | login_anonymous_available(); |
| 1187 | - load_control(); | |
| 1187 | + fossil_nice_default(); | |
| 1188 | 1188 | blob_init(&qp, 0, 0); |
| 1189 | 1189 | diffType = preferred_diff_type(); |
| 1190 | 1190 | zRe = P("regex"); |
| 1191 | 1191 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1192 | 1192 | zBranch = P("branch"); |
| 1193 | 1193 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1182,11 +1182,11 @@ | |
| 1182 | int bInvert = PB("inv"); |
| 1183 | |
| 1184 | login_check_credentials(); |
| 1185 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1186 | login_anonymous_available(); |
| 1187 | load_control(); |
| 1188 | blob_init(&qp, 0, 0); |
| 1189 | diffType = preferred_diff_type(); |
| 1190 | zRe = P("regex"); |
| 1191 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1192 | zBranch = P("branch"); |
| 1193 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1182,11 +1182,11 @@ | |
| 1182 | int bInvert = PB("inv"); |
| 1183 | |
| 1184 | login_check_credentials(); |
| 1185 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 1186 | login_anonymous_available(); |
| 1187 | fossil_nice_default(); |
| 1188 | blob_init(&qp, 0, 0); |
| 1189 | diffType = preferred_diff_type(); |
| 1190 | zRe = P("regex"); |
| 1191 | if( zRe ) re_compile(&pRe, zRe, 0); |
| 1192 | zBranch = P("branch"); |
| 1193 |
+2
-2
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -739,11 +739,11 @@ | ||
| 739 | 739 | ** been called. In general, this function should be used sparingly, |
| 740 | 740 | ** e.g. from low-level support functions like fossil_warning() where |
| 741 | 741 | ** there is genuine uncertainty about whether (or not) the JSON setup |
| 742 | 742 | ** has already been called. |
| 743 | 743 | */ |
| 744 | -int json_is_bootstrapped_early(){ | |
| 744 | +int json_is_bootstrapped_early(void){ | |
| 745 | 745 | return ((g.json.gc.v != NULL) && (g.json.gc.a != NULL)); |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /* |
| 749 | 749 | ** Initializes some JSON bits which need to be initialized relatively |
| @@ -758,11 +758,11 @@ | ||
| 758 | 758 | ** up. e.g. it must not use cgi_parameter() and friends because this |
| 759 | 759 | ** must be called before those data are initialized. |
| 760 | 760 | ** |
| 761 | 761 | ** If called multiple times, calls after the first are a no-op. |
| 762 | 762 | */ |
| 763 | -void json_bootstrap_early(){ | |
| 763 | +void json_bootstrap_early(void){ | |
| 764 | 764 | cson_value * v; |
| 765 | 765 | |
| 766 | 766 | if(g.json.gc.v!=NULL){ |
| 767 | 767 | /* Avoid multiple bootstrappings. */ |
| 768 | 768 | return; |
| 769 | 769 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -739,11 +739,11 @@ | |
| 739 | ** been called. In general, this function should be used sparingly, |
| 740 | ** e.g. from low-level support functions like fossil_warning() where |
| 741 | ** there is genuine uncertainty about whether (or not) the JSON setup |
| 742 | ** has already been called. |
| 743 | */ |
| 744 | int json_is_bootstrapped_early(){ |
| 745 | return ((g.json.gc.v != NULL) && (g.json.gc.a != NULL)); |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | ** Initializes some JSON bits which need to be initialized relatively |
| @@ -758,11 +758,11 @@ | |
| 758 | ** up. e.g. it must not use cgi_parameter() and friends because this |
| 759 | ** must be called before those data are initialized. |
| 760 | ** |
| 761 | ** If called multiple times, calls after the first are a no-op. |
| 762 | */ |
| 763 | void json_bootstrap_early(){ |
| 764 | cson_value * v; |
| 765 | |
| 766 | if(g.json.gc.v!=NULL){ |
| 767 | /* Avoid multiple bootstrappings. */ |
| 768 | return; |
| 769 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -739,11 +739,11 @@ | |
| 739 | ** been called. In general, this function should be used sparingly, |
| 740 | ** e.g. from low-level support functions like fossil_warning() where |
| 741 | ** there is genuine uncertainty about whether (or not) the JSON setup |
| 742 | ** has already been called. |
| 743 | */ |
| 744 | int json_is_bootstrapped_early(void){ |
| 745 | return ((g.json.gc.v != NULL) && (g.json.gc.a != NULL)); |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | ** Initializes some JSON bits which need to be initialized relatively |
| @@ -758,11 +758,11 @@ | |
| 758 | ** up. e.g. it must not use cgi_parameter() and friends because this |
| 759 | ** must be called before those data are initialized. |
| 760 | ** |
| 761 | ** If called multiple times, calls after the first are a no-op. |
| 762 | */ |
| 763 | void json_bootstrap_early(void){ |
| 764 | cson_value * v; |
| 765 | |
| 766 | if(g.json.gc.v!=NULL){ |
| 767 | /* Avoid multiple bootstrappings. */ |
| 768 | return; |
| 769 |
+1
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1872,11 +1872,11 @@ | ||
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | 1874 | /* At this point, the appropriate repository database file will have |
| 1875 | 1875 | ** been opened. |
| 1876 | 1876 | */ |
| 1877 | - | |
| 1877 | + load_control(); | |
| 1878 | 1878 | |
| 1879 | 1879 | /* |
| 1880 | 1880 | ** Check to see if the first term of PATH_INFO specifies an |
| 1881 | 1881 | ** alternative skin. This will be the case if the first term of |
| 1882 | 1882 | ** PATH_INFO begins with "draftN/" where N is an integer between 1 |
| 1883 | 1883 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1872,11 +1872,11 @@ | |
| 1872 | } |
| 1873 | |
| 1874 | /* At this point, the appropriate repository database file will have |
| 1875 | ** been opened. |
| 1876 | */ |
| 1877 | |
| 1878 | |
| 1879 | /* |
| 1880 | ** Check to see if the first term of PATH_INFO specifies an |
| 1881 | ** alternative skin. This will be the case if the first term of |
| 1882 | ** PATH_INFO begins with "draftN/" where N is an integer between 1 |
| 1883 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1872,11 +1872,11 @@ | |
| 1872 | } |
| 1873 | |
| 1874 | /* At this point, the appropriate repository database file will have |
| 1875 | ** been opened. |
| 1876 | */ |
| 1877 | load_control(); |
| 1878 | |
| 1879 | /* |
| 1880 | ** Check to see if the first term of PATH_INFO specifies an |
| 1881 | ** alternative skin. This will be the case if the first term of |
| 1882 | ** PATH_INFO begins with "draftN/" where N is an integer between 1 |
| 1883 |
+1
-1
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -963,11 +963,11 @@ | ||
| 963 | 963 | */ |
| 964 | 964 | if( !g.perm.Write && !db_get_boolean("artifact_stats_enable",0) ){ |
| 965 | 965 | login_needed(g.anon.Write); |
| 966 | 966 | return; |
| 967 | 967 | } |
| 968 | - load_control(); | |
| 968 | + fossil_nice_default(); | |
| 969 | 969 | |
| 970 | 970 | style_set_current_feature("stat"); |
| 971 | 971 | style_header("Artifact Statistics"); |
| 972 | 972 | style_submenu_element("Repository Stats", "stat"); |
| 973 | 973 | style_submenu_element("Artifact List", "bloblist"); |
| 974 | 974 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -963,11 +963,11 @@ | |
| 963 | */ |
| 964 | if( !g.perm.Write && !db_get_boolean("artifact_stats_enable",0) ){ |
| 965 | login_needed(g.anon.Write); |
| 966 | return; |
| 967 | } |
| 968 | load_control(); |
| 969 | |
| 970 | style_set_current_feature("stat"); |
| 971 | style_header("Artifact Statistics"); |
| 972 | style_submenu_element("Repository Stats", "stat"); |
| 973 | style_submenu_element("Artifact List", "bloblist"); |
| 974 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -963,11 +963,11 @@ | |
| 963 | */ |
| 964 | if( !g.perm.Write && !db_get_boolean("artifact_stats_enable",0) ){ |
| 965 | login_needed(g.anon.Write); |
| 966 | return; |
| 967 | } |
| 968 | fossil_nice_default(); |
| 969 | |
| 970 | style_set_current_feature("stat"); |
| 971 | style_header("Artifact Statistics"); |
| 972 | style_submenu_element("Repository Stats", "stat"); |
| 973 | style_submenu_element("Artifact List", "bloblist"); |
| 974 |
+1
-1
| --- src/tar.c | ||
| +++ src/tar.c | ||
| @@ -756,11 +756,11 @@ | ||
| 756 | 756 | Blob tarball; /* Tarball accumulated here */ |
| 757 | 757 | const char *z; |
| 758 | 758 | |
| 759 | 759 | login_check_credentials(); |
| 760 | 760 | if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; } |
| 761 | - load_control(); | |
| 761 | + fossil_nice_default(); | |
| 762 | 762 | zName = fossil_strdup(PD("name","")); |
| 763 | 763 | z = P("r"); |
| 764 | 764 | if( z==0 ) z = P("uuid"); |
| 765 | 765 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 766 | 766 | if( z==0 ) z = "trunk"; |
| 767 | 767 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -756,11 +756,11 @@ | |
| 756 | Blob tarball; /* Tarball accumulated here */ |
| 757 | const char *z; |
| 758 | |
| 759 | login_check_credentials(); |
| 760 | if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; } |
| 761 | load_control(); |
| 762 | zName = fossil_strdup(PD("name","")); |
| 763 | z = P("r"); |
| 764 | if( z==0 ) z = P("uuid"); |
| 765 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 766 | if( z==0 ) z = "trunk"; |
| 767 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -756,11 +756,11 @@ | |
| 756 | Blob tarball; /* Tarball accumulated here */ |
| 757 | const char *z; |
| 758 | |
| 759 | login_check_credentials(); |
| 760 | if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; } |
| 761 | fossil_nice_default(); |
| 762 | zName = fossil_strdup(PD("name","")); |
| 763 | z = P("r"); |
| 764 | if( z==0 ) z = P("uuid"); |
| 765 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 766 | if( z==0 ) z = "trunk"; |
| 767 |
+19
| --- src/util.c | ||
| +++ src/util.c | ||
| @@ -896,5 +896,24 @@ | ||
| 896 | 896 | } |
| 897 | 897 | } |
| 898 | 898 | #endif |
| 899 | 899 | return zBrowser; |
| 900 | 900 | } |
| 901 | + | |
| 902 | +/* | |
| 903 | +** On non-Windows systems, calls nice(2) with the given level. Errors | |
| 904 | +** are ignored. On Windows this is a no-op. | |
| 905 | +*/ | |
| 906 | +void fossil_nice(int level){ | |
| 907 | +#ifndef _WIN32 | |
| 908 | + nice(level); | |
| 909 | +#else | |
| 910 | + (void)level; | |
| 911 | +#endif | |
| 912 | +} | |
| 913 | + | |
| 914 | +/* | |
| 915 | +** Calls fossil_nice() with a default level. | |
| 916 | +*/ | |
| 917 | +void fossil_nice_default(void){ | |
| 918 | + fossil_nice(20); | |
| 919 | +} | |
| 901 | 920 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -896,5 +896,24 @@ | |
| 896 | } |
| 897 | } |
| 898 | #endif |
| 899 | return zBrowser; |
| 900 | } |
| 901 |
| --- src/util.c | |
| +++ src/util.c | |
| @@ -896,5 +896,24 @@ | |
| 896 | } |
| 897 | } |
| 898 | #endif |
| 899 | return zBrowser; |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | ** On non-Windows systems, calls nice(2) with the given level. Errors |
| 904 | ** are ignored. On Windows this is a no-op. |
| 905 | */ |
| 906 | void fossil_nice(int level){ |
| 907 | #ifndef _WIN32 |
| 908 | nice(level); |
| 909 | #else |
| 910 | (void)level; |
| 911 | #endif |
| 912 | } |
| 913 | |
| 914 | /* |
| 915 | ** Calls fossil_nice() with a default level. |
| 916 | */ |
| 917 | void fossil_nice_default(void){ |
| 918 | fossil_nice(20); |
| 919 | } |
| 920 |
+1
-1
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -921,11 +921,11 @@ | ||
| 921 | 921 | zType = "SQL"; |
| 922 | 922 | }else{ |
| 923 | 923 | eType = ARCHIVE_ZIP; |
| 924 | 924 | zType = "ZIP"; |
| 925 | 925 | } |
| 926 | - load_control(); | |
| 926 | + fossil_nice_default(); | |
| 927 | 927 | zName = fossil_strdup(PD("name","")); |
| 928 | 928 | z = P("r"); |
| 929 | 929 | if( z==0 ) z = P("uuid"); |
| 930 | 930 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 931 | 931 | if( z==0 ) z = "trunk"; |
| 932 | 932 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -921,11 +921,11 @@ | |
| 921 | zType = "SQL"; |
| 922 | }else{ |
| 923 | eType = ARCHIVE_ZIP; |
| 924 | zType = "ZIP"; |
| 925 | } |
| 926 | load_control(); |
| 927 | zName = fossil_strdup(PD("name","")); |
| 928 | z = P("r"); |
| 929 | if( z==0 ) z = P("uuid"); |
| 930 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 931 | if( z==0 ) z = "trunk"; |
| 932 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -921,11 +921,11 @@ | |
| 921 | zType = "SQL"; |
| 922 | }else{ |
| 923 | eType = ARCHIVE_ZIP; |
| 924 | zType = "ZIP"; |
| 925 | } |
| 926 | fossil_nice_default(); |
| 927 | zName = fossil_strdup(PD("name","")); |
| 928 | z = P("r"); |
| 929 | if( z==0 ) z = P("uuid"); |
| 930 | if( z==0 ) z = tar_uuid_from_name(&zName); |
| 931 | if( z==0 ) z = "trunk"; |
| 932 |