nginxtra 1.0.15.0 → 1.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/VERSION +1 -1
  2. data/bin/nginxtra +1 -1
  3. data/lib/nginxtra/action.rb +10 -0
  4. data/lib/nginxtra/actions/compile.rb +16 -2
  5. data/lib/nginxtra/actions/start.rb +18 -2
  6. data/lib/nginxtra/actions/status.rb +1 -10
  7. data/lib/nginxtra/actions/stop.rb +18 -0
  8. data/lib/nginxtra/cli.rb +12 -3
  9. data/lib/nginxtra/config.rb +10 -0
  10. data/src/nginx/CHANGES +311 -90
  11. data/src/nginx/CHANGES.ru +315 -88
  12. data/src/nginx/auto/lib/pcre/conf +22 -5
  13. data/src/nginx/auto/lib/pcre/make +1 -1
  14. data/src/nginx/auto/modules +14 -3
  15. data/src/nginx/auto/options +17 -3
  16. data/src/nginx/auto/os/freebsd +8 -0
  17. data/src/nginx/auto/os/linux +5 -4
  18. data/src/nginx/auto/os/solaris +2 -1
  19. data/src/nginx/auto/sources +10 -2
  20. data/src/nginx/auto/summary +2 -0
  21. data/src/nginx/auto/types/sizeof +2 -1
  22. data/src/nginx/auto/types/typedef +1 -1
  23. data/src/nginx/auto/types/uintptr_t +7 -4
  24. data/src/nginx/auto/unix +82 -21
  25. data/src/nginx/conf/fastcgi.conf +1 -0
  26. data/src/nginx/conf/fastcgi_params +1 -0
  27. data/src/nginx/conf/scgi_params +1 -0
  28. data/src/nginx/conf/uwsgi_params +1 -0
  29. data/src/nginx/man/nginx.8 +49 -49
  30. data/src/nginx/src/core/nginx.c +10 -12
  31. data/src/nginx/src/core/nginx.h +2 -2
  32. data/src/nginx/src/core/ngx_buf.c +9 -7
  33. data/src/nginx/src/core/ngx_buf.h +2 -2
  34. data/src/nginx/src/core/ngx_conf_file.c +4 -11
  35. data/src/nginx/src/core/ngx_conf_file.h +1 -1
  36. data/src/nginx/src/core/ngx_connection.c +52 -1
  37. data/src/nginx/src/core/ngx_connection.h +6 -0
  38. data/src/nginx/src/core/ngx_core.h +5 -0
  39. data/src/nginx/src/core/ngx_cycle.c +1 -1
  40. data/src/nginx/src/core/ngx_cycle.h +2 -2
  41. data/src/nginx/src/core/ngx_file.c +1 -1
  42. data/src/nginx/src/core/ngx_inet.c +11 -8
  43. data/src/nginx/src/core/ngx_murmurhash.h +1 -1
  44. data/src/nginx/src/core/ngx_open_file_cache.c +343 -38
  45. data/src/nginx/src/core/ngx_open_file_cache.h +10 -0
  46. data/src/nginx/src/core/ngx_output_chain.c +2 -1
  47. data/src/nginx/src/core/ngx_parse.h +0 -3
  48. data/src/nginx/src/core/ngx_rbtree.c +1 -2
  49. data/src/nginx/src/core/ngx_regex.c +263 -5
  50. data/src/nginx/src/core/ngx_regex.h +6 -2
  51. data/src/nginx/src/core/ngx_resolver.c +88 -21
  52. data/src/nginx/src/core/ngx_resolver.h +7 -8
  53. data/src/nginx/src/core/ngx_shmtx.c +69 -44
  54. data/src/nginx/src/core/ngx_shmtx.h +12 -1
  55. data/src/nginx/src/core/ngx_slab.c +3 -3
  56. data/src/nginx/src/core/ngx_slab.h +1 -1
  57. data/src/nginx/src/core/ngx_string.c +19 -16
  58. data/src/nginx/src/core/ngx_times.c +2 -2
  59. data/src/nginx/src/event/modules/ngx_epoll_module.c +2 -2
  60. data/src/nginx/src/event/modules/ngx_eventport_module.c +1 -1
  61. data/src/nginx/src/event/modules/ngx_kqueue_module.c +1 -1
  62. data/src/nginx/src/event/ngx_event.c +25 -17
  63. data/src/nginx/src/event/ngx_event_openssl.c +3 -1
  64. data/src/nginx/src/event/ngx_event_pipe.c +108 -85
  65. data/src/nginx/src/event/ngx_event_pipe.h +1 -2
  66. data/src/nginx/src/event/ngx_event_timer.c +2 -3
  67. data/src/nginx/src/http/modules/ngx_http_access_module.c +9 -4
  68. data/src/nginx/src/http/modules/ngx_http_browser_module.c +5 -3
  69. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +1 -1
  70. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +1 -1
  71. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +144 -22
  72. data/src/nginx/src/http/modules/ngx_http_flv_module.c +8 -0
  73. data/src/nginx/src/http/modules/ngx_http_geo_module.c +3 -3
  74. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +20 -6
  75. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +8 -0
  76. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +23 -27
  77. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -3
  78. data/src/nginx/src/http/modules/ngx_http_index_module.c +24 -0
  79. data/src/nginx/src/http/modules/ngx_http_limit_conn_module.c +747 -0
  80. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +289 -133
  81. data/src/nginx/src/http/modules/ngx_http_log_module.c +34 -6
  82. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +19 -3
  83. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +8 -0
  84. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +1446 -239
  85. data/src/nginx/src/http/modules/ngx_http_realip_module.c +4 -10
  86. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +90 -21
  87. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +8 -11
  88. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +16 -6
  89. data/src/nginx/src/http/modules/ngx_http_static_module.c +8 -0
  90. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +2 -2
  91. data/src/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +570 -0
  92. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +1 -5
  93. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +77 -26
  94. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +171 -37
  95. data/src/nginx/src/http/modules/perl/nginx.pm +2 -1
  96. data/src/nginx/src/http/modules/perl/nginx.xs +4 -0
  97. data/src/nginx/src/http/ngx_http.c +8 -1
  98. data/src/nginx/src/http/ngx_http.h +1 -0
  99. data/src/nginx/src/http/ngx_http_busy_lock.c +2 -2
  100. data/src/nginx/src/http/ngx_http_cache.h +12 -1
  101. data/src/nginx/src/http/ngx_http_copy_filter_module.c +4 -3
  102. data/src/nginx/src/http/ngx_http_core_module.c +303 -37
  103. data/src/nginx/src/http/ngx_http_core_module.h +15 -0
  104. data/src/nginx/src/http/ngx_http_file_cache.c +226 -52
  105. data/src/nginx/src/http/ngx_http_parse.c +69 -3
  106. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +4 -4
  107. data/src/nginx/src/http/ngx_http_request.c +61 -27
  108. data/src/nginx/src/http/ngx_http_request.h +3 -3
  109. data/src/nginx/src/http/ngx_http_request_body.c +1 -1
  110. data/src/nginx/src/http/ngx_http_script.c +6 -0
  111. data/src/nginx/src/http/ngx_http_upstream.c +200 -47
  112. data/src/nginx/src/http/ngx_http_upstream.h +20 -1
  113. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +22 -6
  114. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +1 -0
  115. data/src/nginx/src/http/ngx_http_variables.c +123 -4
  116. data/src/nginx/src/mail/ngx_mail.c +13 -0
  117. data/src/nginx/src/mail/ngx_mail.h +12 -0
  118. data/src/nginx/src/mail/ngx_mail_core_module.c +100 -15
  119. data/src/nginx/src/os/unix/ngx_daemon.c +2 -1
  120. data/src/nginx/src/os/unix/ngx_darwin.h +3 -0
  121. data/src/nginx/src/os/unix/ngx_darwin_config.h +1 -0
  122. data/src/nginx/src/os/unix/ngx_darwin_init.c +30 -0
  123. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +11 -5
  124. data/src/nginx/src/os/unix/ngx_errno.h +5 -0
  125. data/src/nginx/src/os/unix/ngx_files.h +50 -1
  126. data/src/nginx/src/os/unix/ngx_freebsd.h +2 -1
  127. data/src/nginx/src/os/unix/ngx_freebsd_config.h +2 -0
  128. data/src/nginx/src/os/unix/ngx_freebsd_init.c +4 -3
  129. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +2 -2
  130. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +12 -6
  131. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +1 -1
  132. data/src/nginx/src/os/unix/ngx_linux_config.h +1 -0
  133. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +6 -4
  134. data/src/nginx/src/os/unix/ngx_os.h +0 -1
  135. data/src/nginx/src/os/unix/ngx_posix_config.h +3 -0
  136. data/src/nginx/src/os/unix/ngx_process.c +50 -11
  137. data/src/nginx/src/os/unix/ngx_process.h +1 -0
  138. data/src/nginx/src/os/unix/ngx_process_cycle.c +6 -15
  139. data/src/nginx/src/os/unix/ngx_readv_chain.c +8 -0
  140. data/src/nginx/src/os/unix/ngx_setaffinity.c +69 -0
  141. data/src/nginx/src/os/unix/ngx_setaffinity.h +23 -0
  142. data/src/nginx/src/os/unix/ngx_setproctitle.c +1 -1
  143. data/src/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  144. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +11 -3
  145. data/src/nginx/src/os/unix/ngx_writev_chain.c +7 -3
  146. metadata +7 -4
  147. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +0 -553
@@ -9,6 +9,7 @@
9
9
  #define _NGX_PROCESS_H_INCLUDED_
10
10
 
11
11
 
12
+ #include <ngx_setaffinity.h>
12
13
  #include <ngx_setproctitle.h>
13
14
 
14
15
 
@@ -62,7 +62,7 @@ ngx_int_t ngx_threads_n;
62
62
  #endif
63
63
 
64
64
 
65
- u_long cpu_affinity;
65
+ uint64_t cpu_affinity;
66
66
  static u_char master_process[] = "master process";
67
67
 
68
68
 
@@ -250,6 +250,10 @@ ngx_master_process_cycle(ngx_cycle_t *cycle)
250
250
  ngx_start_worker_processes(cycle, ccf->worker_processes,
251
251
  NGX_PROCESS_JUST_RESPAWN);
252
252
  ngx_start_cache_manager_processes(cycle, 1);
253
+
254
+ /* allow new processes to start */
255
+ ngx_msleep(100);
256
+
253
257
  live = 1;
254
258
  ngx_signal_worker_processes(cycle,
255
259
  ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
@@ -909,23 +913,10 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
909
913
  }
910
914
  }
911
915
 
912
- #if (NGX_HAVE_SCHED_SETAFFINITY)
913
-
914
916
  if (cpu_affinity) {
915
- ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
916
- "sched_setaffinity(0x%08Xl)", cpu_affinity);
917
-
918
- if (sched_setaffinity(0, sizeof(cpu_affinity),
919
- (cpu_set_t *) &cpu_affinity)
920
- == -1)
921
- {
922
- ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
923
- "sched_setaffinity(0x%08Xl) failed", cpu_affinity);
924
- }
917
+ ngx_setaffinity(cpu_affinity, cycle->log);
925
918
  }
926
919
 
927
- #endif
928
-
929
920
  #if (NGX_HAVE_PR_SET_DUMPABLE)
930
921
 
931
922
  /* allow coredump after setuid() in Linux 2.4.x */
@@ -71,6 +71,10 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
71
71
  iov->iov_len += chain->buf->end - chain->buf->last;
72
72
 
73
73
  } else {
74
+ if (vec.nelts >= IOV_MAX) {
75
+ break;
76
+ }
77
+
74
78
  iov = ngx_array_push(&vec);
75
79
  if (iov == NULL) {
76
80
  return NGX_ERROR;
@@ -195,6 +199,10 @@ ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
195
199
  iov->iov_len += chain->buf->end - chain->buf->last;
196
200
 
197
201
  } else {
202
+ if (vec.nelts >= IOV_MAX) {
203
+ break;
204
+ }
205
+
198
206
  iov = ngx_array_push(&vec);
199
207
  if (iov == NULL) {
200
208
  return NGX_ERROR;
@@ -0,0 +1,69 @@
1
+
2
+ /*
3
+ * Copyright (C) Nginx, Inc.
4
+ */
5
+
6
+
7
+ #include <ngx_config.h>
8
+ #include <ngx_core.h>
9
+
10
+
11
+ #if (NGX_HAVE_CPUSET_SETAFFINITY)
12
+
13
+ #include <sys/cpuset.h>
14
+
15
+ void
16
+ ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
17
+ {
18
+ cpuset_t mask;
19
+ ngx_uint_t i;
20
+
21
+ ngx_log_error(NGX_LOG_NOTICE, log, 0,
22
+ "cpuset_setaffinity(0x%08Xl)", cpu_affinity);
23
+
24
+ CPU_ZERO(&mask);
25
+ i = 0;
26
+ do {
27
+ if (cpu_affinity & 1) {
28
+ CPU_SET(i, &mask);
29
+ }
30
+ i++;
31
+ cpu_affinity >>= 1;
32
+ } while (cpu_affinity);
33
+
34
+ if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
35
+ sizeof(cpuset_t), &mask) == -1)
36
+ {
37
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
38
+ "cpuset_setaffinity() failed");
39
+ }
40
+ }
41
+
42
+ #elif (NGX_HAVE_SCHED_SETAFFINITY)
43
+
44
+ void
45
+ ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
46
+ {
47
+ cpu_set_t mask;
48
+ ngx_uint_t i;
49
+
50
+ ngx_log_error(NGX_LOG_NOTICE, log, 0,
51
+ "sched_setaffinity(0x%08Xl)", cpu_affinity);
52
+
53
+ CPU_ZERO(&mask);
54
+ i = 0;
55
+ do {
56
+ if (cpu_affinity & 1) {
57
+ CPU_SET(i, &mask);
58
+ }
59
+ i++;
60
+ cpu_affinity >>= 1;
61
+ } while (cpu_affinity);
62
+
63
+ if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
64
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
65
+ "sched_setaffinity() failed");
66
+ }
67
+ }
68
+
69
+ #endif
@@ -0,0 +1,23 @@
1
+
2
+ /*
3
+ * Copyright (C) Nginx, Inc.
4
+ */
5
+
6
+ #ifndef _NGX_SETAFFINITY_H_INCLUDED_
7
+ #define _NGX_SETAFFINITY_H_INCLUDED_
8
+
9
+
10
+ #if (NGX_HAVE_SCHED_SETAFFINITY || NGX_HAVE_CPUSET_SETAFFINITY)
11
+
12
+ #define NGX_HAVE_CPU_AFFINITY 1
13
+
14
+ void ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log);
15
+
16
+ #else
17
+
18
+ #define ngx_setaffinity(cpu_affinity, log)
19
+
20
+ #endif
21
+
22
+
23
+ #endif /* _NGX_SETAFFINITY_H_INCLUDED_ */
@@ -21,7 +21,7 @@
21
21
  * from argv[0] for our process title.
22
22
  *
23
23
  * The Solaris's standard /bin/ps does not show the changed process title.
24
- * You have to use "/usr/ucb/ps -w" instead. Besides, the UCB ps dos not
24
+ * You have to use "/usr/ucb/ps -w" instead. Besides, the UCB ps does not
25
25
  * show a new title if its length less than the origin command line length.
26
26
  * To avoid it we append to a new title the origin command line in the
27
27
  * parenthesis.
@@ -29,6 +29,7 @@
29
29
  #include <grp.h>
30
30
  #include <dirent.h>
31
31
  #include <glob.h>
32
+ #include <time.h>
32
33
  #include <sys/statvfs.h> /* statvfs() */
33
34
 
34
35
  #include <sys/filio.h> /* FIONBIO */
@@ -99,6 +100,7 @@
99
100
 
100
101
 
101
102
  #define NGX_HAVE_OS_SPECIFIC_INIT 1
103
+ #define ngx_debug_init()
102
104
 
103
105
 
104
106
  extern char **environ;
@@ -74,7 +74,6 @@ ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
74
74
 
75
75
 
76
76
  send = 0;
77
- complete = 0;
78
77
 
79
78
  vec.elts = sfvs;
80
79
  vec.size = sizeof(sendfilevec_t);
@@ -87,6 +86,7 @@ ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
87
86
  fprev = 0;
88
87
  sfv = NULL;
89
88
  eintr = 0;
89
+ complete = 0;
90
90
  sent = 0;
91
91
  prev_send = send;
92
92
 
@@ -94,8 +94,8 @@ ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
94
94
 
95
95
  /* create the sendfilevec and coalesce the neighbouring bufs */
96
96
 
97
- for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next)
98
- {
97
+ for (cl = in; cl && send < limit; cl = cl->next) {
98
+
99
99
  if (ngx_buf_special(cl->buf)) {
100
100
  continue;
101
101
  }
@@ -113,6 +113,10 @@ ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
113
113
  sfv->sfv_len += (size_t) size;
114
114
 
115
115
  } else {
116
+ if (vec.nelts >= IOV_MAX) {
117
+ break;
118
+ }
119
+
116
120
  sfv = ngx_array_push(&vec);
117
121
  if (sfv == NULL) {
118
122
  return NGX_CHAIN_ERROR;
@@ -147,6 +151,10 @@ ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
147
151
  sfv->sfv_len += (size_t) size;
148
152
 
149
153
  } else {
154
+ if (vec.nelts >= IOV_MAX) {
155
+ break;
156
+ }
157
+
150
158
  sfv = ngx_array_push(&vec);
151
159
  if (sfv == NULL) {
152
160
  return NGX_CHAIN_ERROR;
@@ -54,7 +54,6 @@ ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
54
54
  }
55
55
 
56
56
  send = 0;
57
- complete = 0;
58
57
 
59
58
  vec.elts = iovs;
60
59
  vec.size = sizeof(struct iovec);
@@ -65,14 +64,15 @@ ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
65
64
  prev = NULL;
66
65
  iov = NULL;
67
66
  eintr = 0;
67
+ complete = 0;
68
68
  prev_send = send;
69
69
 
70
70
  vec.nelts = 0;
71
71
 
72
72
  /* create the iovec and coalesce the neighbouring bufs */
73
73
 
74
- for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next)
75
- {
74
+ for (cl = in; cl && send < limit; cl = cl->next) {
75
+
76
76
  if (ngx_buf_special(cl->buf)) {
77
77
  continue;
78
78
  }
@@ -93,6 +93,10 @@ ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
93
93
  iov->iov_len += size;
94
94
 
95
95
  } else {
96
+ if (vec.nelts >= IOV_MAX) {
97
+ break;
98
+ }
99
+
96
100
  iov = ngx_array_push(&vec);
97
101
  if (iov == NULL) {
98
102
  return NGX_CHAIN_ERROR;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginxtra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15.0
4
+ version: 1.2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &20403360 !ruby/object:Gem::Requirement
16
+ requirement: &6775360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.15.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20403360
24
+ version_requirements: *6775360
25
25
  description: This gem is intended to provide an easy to use configuration file that
26
26
  will automatically be used to compile nginx and configure the configuration.
27
27
  email: reasonnumber@gmail.com
@@ -245,8 +245,8 @@ files:
245
245
  - src/nginx/src/http/modules/ngx_http_headers_filter_module.c
246
246
  - src/nginx/src/http/modules/ngx_http_image_filter_module.c
247
247
  - src/nginx/src/http/modules/ngx_http_index_module.c
248
+ - src/nginx/src/http/modules/ngx_http_limit_conn_module.c
248
249
  - src/nginx/src/http/modules/ngx_http_limit_req_module.c
249
- - src/nginx/src/http/modules/ngx_http_limit_zone_module.c
250
250
  - src/nginx/src/http/modules/ngx_http_log_module.c
251
251
  - src/nginx/src/http/modules/ngx_http_map_module.c
252
252
  - src/nginx/src/http/modules/ngx_http_memcached_module.c
@@ -269,6 +269,7 @@ files:
269
269
  - src/nginx/src/http/modules/ngx_http_stub_status_module.c
270
270
  - src/nginx/src/http/modules/ngx_http_sub_filter_module.c
271
271
  - src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c
272
+ - src/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c
272
273
  - src/nginx/src/http/modules/ngx_http_userid_filter_module.c
273
274
  - src/nginx/src/http/modules/ngx_http_uwsgi_module.c
274
275
  - src/nginx/src/http/modules/ngx_http_xslt_filter_module.c
@@ -370,6 +371,8 @@ files:
370
371
  - src/nginx/src/os/unix/ngx_readv_chain.c
371
372
  - src/nginx/src/os/unix/ngx_recv.c
372
373
  - src/nginx/src/os/unix/ngx_send.c
374
+ - src/nginx/src/os/unix/ngx_setaffinity.c
375
+ - src/nginx/src/os/unix/ngx_setaffinity.h
373
376
  - src/nginx/src/os/unix/ngx_setproctitle.c
374
377
  - src/nginx/src/os/unix/ngx_setproctitle.h
375
378
  - src/nginx/src/os/unix/ngx_shmem.c
@@ -1,553 +0,0 @@
1
-
2
- /*
3
- * Copyright (C) Igor Sysoev
4
- * Copyright (C) Nginx, Inc.
5
- */
6
-
7
-
8
- #include <ngx_config.h>
9
- #include <ngx_core.h>
10
- #include <ngx_http.h>
11
-
12
-
13
- typedef struct {
14
- u_char color;
15
- u_char len;
16
- u_short conn;
17
- u_char data[1];
18
- } ngx_http_limit_zone_node_t;
19
-
20
-
21
- typedef struct {
22
- ngx_shm_zone_t *shm_zone;
23
- ngx_rbtree_node_t *node;
24
- } ngx_http_limit_zone_cleanup_t;
25
-
26
-
27
- typedef struct {
28
- ngx_rbtree_t *rbtree;
29
- ngx_int_t index;
30
- ngx_str_t var;
31
- } ngx_http_limit_zone_ctx_t;
32
-
33
-
34
- typedef struct {
35
- ngx_shm_zone_t *shm_zone;
36
- ngx_uint_t conn;
37
- ngx_uint_t log_level;
38
- } ngx_http_limit_zone_conf_t;
39
-
40
-
41
- static void ngx_http_limit_zone_cleanup(void *data);
42
-
43
- static void *ngx_http_limit_zone_create_conf(ngx_conf_t *cf);
44
- static char *ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent,
45
- void *child);
46
- static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd,
47
- void *conf);
48
- static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd,
49
- void *conf);
50
- static ngx_int_t ngx_http_limit_zone_init(ngx_conf_t *cf);
51
-
52
-
53
- static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = {
54
- { ngx_string("info"), NGX_LOG_INFO },
55
- { ngx_string("notice"), NGX_LOG_NOTICE },
56
- { ngx_string("warn"), NGX_LOG_WARN },
57
- { ngx_string("error"), NGX_LOG_ERR },
58
- { ngx_null_string, 0 }
59
- };
60
-
61
-
62
- static ngx_command_t ngx_http_limit_zone_commands[] = {
63
-
64
- { ngx_string("limit_zone"),
65
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3,
66
- ngx_http_limit_zone,
67
- 0,
68
- 0,
69
- NULL },
70
-
71
- { ngx_string("limit_conn"),
72
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
73
- ngx_http_limit_conn,
74
- NGX_HTTP_LOC_CONF_OFFSET,
75
- 0,
76
- NULL },
77
-
78
- { ngx_string("limit_conn_log_level"),
79
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
80
- ngx_conf_set_enum_slot,
81
- NGX_HTTP_LOC_CONF_OFFSET,
82
- offsetof(ngx_http_limit_zone_conf_t, log_level),
83
- &ngx_http_limit_conn_log_levels },
84
-
85
- ngx_null_command
86
- };
87
-
88
-
89
- static ngx_http_module_t ngx_http_limit_zone_module_ctx = {
90
- NULL, /* preconfiguration */
91
- ngx_http_limit_zone_init, /* postconfiguration */
92
-
93
- NULL, /* create main configuration */
94
- NULL, /* init main configuration */
95
-
96
- NULL, /* create server configuration */
97
- NULL, /* merge server configuration */
98
-
99
- ngx_http_limit_zone_create_conf, /* create location configuration */
100
- ngx_http_limit_zone_merge_conf /* merge location configuration */
101
- };
102
-
103
-
104
- ngx_module_t ngx_http_limit_zone_module = {
105
- NGX_MODULE_V1,
106
- &ngx_http_limit_zone_module_ctx, /* module context */
107
- ngx_http_limit_zone_commands, /* module directives */
108
- NGX_HTTP_MODULE, /* module type */
109
- NULL, /* init master */
110
- NULL, /* init module */
111
- NULL, /* init process */
112
- NULL, /* init thread */
113
- NULL, /* exit thread */
114
- NULL, /* exit process */
115
- NULL, /* exit master */
116
- NGX_MODULE_V1_PADDING
117
- };
118
-
119
-
120
- static ngx_int_t
121
- ngx_http_limit_zone_handler(ngx_http_request_t *r)
122
- {
123
- size_t len, n;
124
- uint32_t hash;
125
- ngx_int_t rc;
126
- ngx_slab_pool_t *shpool;
127
- ngx_rbtree_node_t *node, *sentinel;
128
- ngx_pool_cleanup_t *cln;
129
- ngx_http_variable_value_t *vv;
130
- ngx_http_limit_zone_ctx_t *ctx;
131
- ngx_http_limit_zone_node_t *lz;
132
- ngx_http_limit_zone_conf_t *lzcf;
133
- ngx_http_limit_zone_cleanup_t *lzcln;
134
-
135
- if (r->main->limit_zone_set) {
136
- return NGX_DECLINED;
137
- }
138
-
139
- lzcf = ngx_http_get_module_loc_conf(r, ngx_http_limit_zone_module);
140
-
141
- if (lzcf->shm_zone == NULL) {
142
- return NGX_DECLINED;
143
- }
144
-
145
- ctx = lzcf->shm_zone->data;
146
-
147
- vv = ngx_http_get_indexed_variable(r, ctx->index);
148
-
149
- if (vv == NULL || vv->not_found) {
150
- return NGX_DECLINED;
151
- }
152
-
153
- len = vv->len;
154
-
155
- if (len == 0) {
156
- return NGX_DECLINED;
157
- }
158
-
159
- if (len > 255) {
160
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
161
- "the value of the \"%V\" variable "
162
- "is more than 255 bytes: \"%v\"",
163
- &ctx->var, vv);
164
- return NGX_DECLINED;
165
- }
166
-
167
- r->main->limit_zone_set = 1;
168
-
169
- hash = ngx_crc32_short(vv->data, len);
170
-
171
- cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_limit_zone_cleanup_t));
172
- if (cln == NULL) {
173
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
174
- }
175
-
176
- shpool = (ngx_slab_pool_t *) lzcf->shm_zone->shm.addr;
177
-
178
- ngx_shmtx_lock(&shpool->mutex);
179
-
180
- node = ctx->rbtree->root;
181
- sentinel = ctx->rbtree->sentinel;
182
-
183
- while (node != sentinel) {
184
-
185
- if (hash < node->key) {
186
- node = node->left;
187
- continue;
188
- }
189
-
190
- if (hash > node->key) {
191
- node = node->right;
192
- continue;
193
- }
194
-
195
- /* hash == node->key */
196
-
197
- lz = (ngx_http_limit_zone_node_t *) &node->color;
198
-
199
- rc = ngx_memn2cmp(vv->data, lz->data, len, (size_t) lz->len);
200
-
201
- if (rc == 0) {
202
- if ((ngx_uint_t) lz->conn < lzcf->conn) {
203
- lz->conn++;
204
- goto done;
205
- }
206
-
207
- ngx_shmtx_unlock(&shpool->mutex);
208
-
209
- ngx_log_error(lzcf->log_level, r->connection->log, 0,
210
- "limiting connections by zone \"%V\"",
211
- &lzcf->shm_zone->shm.name);
212
-
213
- return NGX_HTTP_SERVICE_UNAVAILABLE;
214
- }
215
-
216
- node = (rc < 0) ? node->left : node->right;
217
- }
218
-
219
- n = offsetof(ngx_rbtree_node_t, color)
220
- + offsetof(ngx_http_limit_zone_node_t, data)
221
- + len;
222
-
223
- node = ngx_slab_alloc_locked(shpool, n);
224
- if (node == NULL) {
225
- ngx_shmtx_unlock(&shpool->mutex);
226
- return NGX_HTTP_SERVICE_UNAVAILABLE;
227
- }
228
-
229
- lz = (ngx_http_limit_zone_node_t *) &node->color;
230
-
231
- node->key = hash;
232
- lz->len = (u_char) len;
233
- lz->conn = 1;
234
- ngx_memcpy(lz->data, vv->data, len);
235
-
236
- ngx_rbtree_insert(ctx->rbtree, node);
237
-
238
- done:
239
-
240
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
241
- "limit zone: %08XD %d", node->key, lz->conn);
242
-
243
- ngx_shmtx_unlock(&shpool->mutex);
244
-
245
- cln->handler = ngx_http_limit_zone_cleanup;
246
- lzcln = cln->data;
247
-
248
- lzcln->shm_zone = lzcf->shm_zone;
249
- lzcln->node = node;
250
-
251
- return NGX_DECLINED;
252
- }
253
-
254
-
255
- static void
256
- ngx_http_limit_zone_rbtree_insert_value(ngx_rbtree_node_t *temp,
257
- ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
258
- {
259
- ngx_rbtree_node_t **p;
260
- ngx_http_limit_zone_node_t *lzn, *lznt;
261
-
262
- for ( ;; ) {
263
-
264
- if (node->key < temp->key) {
265
-
266
- p = &temp->left;
267
-
268
- } else if (node->key > temp->key) {
269
-
270
- p = &temp->right;
271
-
272
- } else { /* node->key == temp->key */
273
-
274
- lzn = (ngx_http_limit_zone_node_t *) &node->color;
275
- lznt = (ngx_http_limit_zone_node_t *) &temp->color;
276
-
277
- p = (ngx_memn2cmp(lzn->data, lznt->data, lzn->len, lznt->len) < 0)
278
- ? &temp->left : &temp->right;
279
- }
280
-
281
- if (*p == sentinel) {
282
- break;
283
- }
284
-
285
- temp = *p;
286
- }
287
-
288
- *p = node;
289
- node->parent = temp;
290
- node->left = sentinel;
291
- node->right = sentinel;
292
- ngx_rbt_red(node);
293
- }
294
-
295
-
296
- static void
297
- ngx_http_limit_zone_cleanup(void *data)
298
- {
299
- ngx_http_limit_zone_cleanup_t *lzcln = data;
300
-
301
- ngx_slab_pool_t *shpool;
302
- ngx_rbtree_node_t *node;
303
- ngx_http_limit_zone_ctx_t *ctx;
304
- ngx_http_limit_zone_node_t *lz;
305
-
306
- ctx = lzcln->shm_zone->data;
307
- shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr;
308
- node = lzcln->node;
309
- lz = (ngx_http_limit_zone_node_t *) &node->color;
310
-
311
- ngx_shmtx_lock(&shpool->mutex);
312
-
313
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0,
314
- "limit zone cleanup: %08XD %d", node->key, lz->conn);
315
-
316
- lz->conn--;
317
-
318
- if (lz->conn == 0) {
319
- ngx_rbtree_delete(ctx->rbtree, node);
320
- ngx_slab_free_locked(shpool, node);
321
- }
322
-
323
- ngx_shmtx_unlock(&shpool->mutex);
324
- }
325
-
326
-
327
- static ngx_int_t
328
- ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data)
329
- {
330
- ngx_http_limit_zone_ctx_t *octx = data;
331
-
332
- size_t len;
333
- ngx_slab_pool_t *shpool;
334
- ngx_rbtree_node_t *sentinel;
335
- ngx_http_limit_zone_ctx_t *ctx;
336
-
337
- ctx = shm_zone->data;
338
-
339
- if (octx) {
340
- if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) {
341
- ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
342
- "limit_zone \"%V\" uses the \"%V\" variable "
343
- "while previously it used the \"%V\" variable",
344
- &shm_zone->shm.name, &ctx->var, &octx->var);
345
- return NGX_ERROR;
346
- }
347
-
348
- ctx->rbtree = octx->rbtree;
349
-
350
- return NGX_OK;
351
- }
352
-
353
- shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
354
-
355
- if (shm_zone->shm.exists) {
356
- ctx->rbtree = shpool->data;
357
-
358
- return NGX_OK;
359
- }
360
-
361
- ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
362
- if (ctx->rbtree == NULL) {
363
- return NGX_ERROR;
364
- }
365
-
366
- shpool->data = ctx->rbtree;
367
-
368
- sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
369
- if (sentinel == NULL) {
370
- return NGX_ERROR;
371
- }
372
-
373
- ngx_rbtree_init(ctx->rbtree, sentinel,
374
- ngx_http_limit_zone_rbtree_insert_value);
375
-
376
- len = sizeof(" in limit_zone \"\"") + shm_zone->shm.name.len;
377
-
378
- shpool->log_ctx = ngx_slab_alloc(shpool, len);
379
- if (shpool->log_ctx == NULL) {
380
- return NGX_ERROR;
381
- }
382
-
383
- ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z",
384
- &shm_zone->shm.name);
385
-
386
- return NGX_OK;
387
- }
388
-
389
-
390
- static void *
391
- ngx_http_limit_zone_create_conf(ngx_conf_t *cf)
392
- {
393
- ngx_http_limit_zone_conf_t *conf;
394
-
395
- conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_conf_t));
396
- if (conf == NULL) {
397
- return NULL;
398
- }
399
-
400
- /*
401
- * set by ngx_pcalloc():
402
- *
403
- * conf->shm_zone = NULL;
404
- * conf->conn = 0;
405
- */
406
-
407
- conf->log_level = NGX_CONF_UNSET_UINT;
408
-
409
- return conf;
410
- }
411
-
412
-
413
- static char *
414
- ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent, void *child)
415
- {
416
- ngx_http_limit_zone_conf_t *prev = parent;
417
- ngx_http_limit_zone_conf_t *conf = child;
418
-
419
- if (conf->shm_zone == NULL) {
420
- conf->shm_zone = prev->shm_zone;
421
- conf->conn = prev->conn;
422
- }
423
-
424
- ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR);
425
-
426
- return NGX_CONF_OK;
427
- }
428
-
429
-
430
- static char *
431
- ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
432
- {
433
- ssize_t n;
434
- ngx_str_t *value;
435
- ngx_shm_zone_t *shm_zone;
436
- ngx_http_limit_zone_ctx_t *ctx;
437
-
438
- value = cf->args->elts;
439
-
440
- if (value[2].data[0] != '$') {
441
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
442
- "invalid variable name \"%V\"", &value[2]);
443
- return NGX_CONF_ERROR;
444
- }
445
-
446
- value[2].len--;
447
- value[2].data++;
448
-
449
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_ctx_t));
450
- if (ctx == NULL) {
451
- return NGX_CONF_ERROR;
452
- }
453
-
454
- ctx->index = ngx_http_get_variable_index(cf, &value[2]);
455
- if (ctx->index == NGX_ERROR) {
456
- return NGX_CONF_ERROR;
457
- }
458
-
459
- ctx->var = value[2];
460
-
461
- n = ngx_parse_size(&value[3]);
462
-
463
- if (n == NGX_ERROR) {
464
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
465
- "invalid size of limit_zone \"%V\"", &value[3]);
466
- return NGX_CONF_ERROR;
467
- }
468
-
469
- if (n < (ngx_int_t) (8 * ngx_pagesize)) {
470
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
471
- "limit_zone \"%V\" is too small", &value[1]);
472
- return NGX_CONF_ERROR;
473
- }
474
-
475
-
476
- shm_zone = ngx_shared_memory_add(cf, &value[1], n,
477
- &ngx_http_limit_zone_module);
478
- if (shm_zone == NULL) {
479
- return NGX_CONF_ERROR;
480
- }
481
-
482
- if (shm_zone->data) {
483
- ctx = shm_zone->data;
484
-
485
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
486
- "limit_zone \"%V\" is already bound to variable \"%V\"",
487
- &value[1], &ctx->var);
488
- return NGX_CONF_ERROR;
489
- }
490
-
491
- shm_zone->init = ngx_http_limit_zone_init_zone;
492
- shm_zone->data = ctx;
493
-
494
- return NGX_CONF_OK;
495
- }
496
-
497
-
498
- static char *
499
- ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
500
- {
501
- ngx_http_limit_zone_conf_t *lzcf = conf;
502
-
503
- ngx_int_t n;
504
- ngx_str_t *value;
505
-
506
- if (lzcf->shm_zone) {
507
- return "is duplicate";
508
- }
509
-
510
- value = cf->args->elts;
511
-
512
- lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
513
- &ngx_http_limit_zone_module);
514
- if (lzcf->shm_zone == NULL) {
515
- return NGX_CONF_ERROR;
516
- }
517
-
518
- n = ngx_atoi(value[2].data, value[2].len);
519
- if (n <= 0) {
520
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
521
- "invalid number of connections \"%V\"", &value[2]);
522
- return NGX_CONF_ERROR;
523
- }
524
-
525
- if (n > 65535) {
526
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
527
- "connection limit must be less 65536");
528
- return NGX_CONF_ERROR;
529
- }
530
-
531
- lzcf->conn = n;
532
-
533
- return NGX_CONF_OK;
534
- }
535
-
536
-
537
- static ngx_int_t
538
- ngx_http_limit_zone_init(ngx_conf_t *cf)
539
- {
540
- ngx_http_handler_pt *h;
541
- ngx_http_core_main_conf_t *cmcf;
542
-
543
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
544
-
545
- h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
546
- if (h == NULL) {
547
- return NGX_ERROR;
548
- }
549
-
550
- *h = ngx_http_limit_zone_handler;
551
-
552
- return NGX_OK;
553
- }