annotate src/http/modules/ngx_http_degradation_module.c @ 7728:485dba3e2a01

Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR. With this change, it is now possible to use ngx_conf_merge_ptr_value() to merge keyval arrays. This change actually follows much earlier changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot() in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22). To preserve compatibility with existing 3rd party modules, both NULL and NGX_CONF_UNSET_PTR are accepted for now.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 22 Oct 2020 18:00:20 +0300
parents 67653855682e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 3794
diff changeset
4 * Copyright (C) Nginx, Inc.
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 size_t sbrk_size;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 } ngx_http_degradation_main_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 ngx_uint_t degrade;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 } ngx_http_degradation_loc_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 static ngx_conf_enum_t ngx_http_degrade[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 { ngx_string("204"), 204 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 { ngx_string("444"), 444 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 { ngx_null_string, 0 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 static void *ngx_http_degradation_create_main_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static void *ngx_http_degradation_create_loc_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 static char *ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 void *child);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 static char *ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 void *conf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 static ngx_int_t ngx_http_degradation_init(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 static ngx_command_t ngx_http_degradation_commands[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 { ngx_string("degradation"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 ngx_http_degradation,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 NGX_HTTP_MAIN_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 NULL },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 { ngx_string("degrade"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 ngx_conf_set_enum_slot,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 NGX_HTTP_LOC_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 offsetof(ngx_http_degradation_loc_conf_t, degrade),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 &ngx_http_degrade },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 ngx_null_command
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 static ngx_http_module_t ngx_http_degradation_module_ctx = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 NULL, /* preconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 ngx_http_degradation_init, /* postconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 ngx_http_degradation_create_main_conf, /* create main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 NULL, /* init main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 NULL, /* create server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 NULL, /* merge server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 ngx_http_degradation_create_loc_conf, /* create location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 ngx_http_degradation_merge_loc_conf /* merge location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 ngx_module_t ngx_http_degradation_module = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 NGX_MODULE_V1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 &ngx_http_degradation_module_ctx, /* module context */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 ngx_http_degradation_commands, /* module directives */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NGX_HTTP_MODULE, /* module type */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 NULL, /* init master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 NULL, /* init module */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 NULL, /* init process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 NULL, /* init thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 NULL, /* exit thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 NULL, /* exit process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 NULL, /* exit master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 NGX_MODULE_V1_PADDING
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 ngx_http_degradation_handler(ngx_http_request_t *r)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
93 ngx_http_degradation_loc_conf_t *dlcf;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
97 if (dlcf->degrade && ngx_http_degraded(r)) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
98 return dlcf->degrade;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
101 return NGX_DECLINED;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
102 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
103
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
104
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
105 ngx_uint_t
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
106 ngx_http_degraded(ngx_http_request_t *r)
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
107 {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
108 time_t now;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
109 ngx_uint_t log;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
110 static size_t sbrk_size;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
111 static time_t sbrk_time;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
112 ngx_http_degradation_main_conf_t *dmcf;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
113
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 if (dmcf->sbrk_size) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
118 log = 0;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 now = ngx_time();
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 /* lock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 if (now != sbrk_time) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 * ELF/i386 is loaded at 0x08000000, 128M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 * ELF/amd64 is loaded at 0x00400000, 4M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 *
4572
67653855682e Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents: 4412
diff changeset
129 * use a function address to subtract the loading address
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 sbrk_time = now;
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
134 log = 1;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 /* unlock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 if (sbrk_size >= dmcf->sbrk_size) {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
140 if (log) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
141 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
142 "degradation sbrk:%uzM",
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
143 sbrk_size / (1024 * 1024));
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
144 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
145
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
146 return 1;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
150 return 0;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 ngx_http_degradation_create_main_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 ngx_http_degradation_main_conf_t *dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 dmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_degradation_main_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 if (dmcf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 return dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 ngx_http_degradation_create_loc_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 ngx_http_degradation_loc_conf_t *conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 conf = ngx_palloc(cf->pool, sizeof(ngx_http_degradation_loc_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 if (conf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 conf->degrade = NGX_CONF_UNSET_UINT;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 return conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 ngx_http_degradation_loc_conf_t *prev = parent;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 ngx_http_degradation_loc_conf_t *conf = child;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 ngx_conf_merge_uint_value(conf->degrade, prev->degrade, 0);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 return NGX_CONF_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 ngx_http_degradation_main_conf_t *dmcf = conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 ngx_str_t *value, s;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 value = cf->args->elts;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 if (ngx_strncmp(value[1].data, "sbrk=", 5) == 0) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 s.len = value[1].len - 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 s.data = value[1].data + 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 dmcf->sbrk_size = ngx_parse_size(&s);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 if (dmcf->sbrk_size == (size_t) NGX_ERROR) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 "invalid sbrk size \"%V\"", &value[1]);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 return NGX_CONF_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 }
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
216
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
217 return NGX_CONF_OK;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
220 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
221 "invalid parameter \"%V\"", &value[1]);
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
222
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
223 return NGX_CONF_ERROR;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 ngx_http_degradation_init(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 ngx_http_handler_pt *h;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 ngx_http_core_main_conf_t *cmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 if (h == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 return NGX_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 *h = ngx_http_degradation_handler;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 return NGX_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 }