nginxtra 1.2.5.7 → 1.2.6.7

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nginxtra CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.2.5.7"
3
+ gem "nginxtra", "= 1.2.6.7"
4
4
  gem "thor", "~> 0.16.0"
5
5
  require "nginxtra"
6
6
  Nginxtra::CLI.start
data/bin/nginxtra_rails CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.2.5.7"
3
+ gem "nginxtra", "= 1.2.6.7"
4
4
  gem "thor", "~> 0.16.0"
5
5
  require "nginxtra"
6
6
  Nginxtra::Rails::CLI.start
@@ -6,7 +6,7 @@ module Nginxtra
6
6
  end
7
7
 
8
8
  def to_s
9
- "1.2.5.7"
9
+ "1.2.6.7"
10
10
  end
11
11
  end
12
12
  end
data/vendor/nginx/CHANGES CHANGED
@@ -1,4 +1,15 @@
1
1
 
2
+ Changes with nginx 1.2.6 11 Dec 2012
3
+
4
+ *) Feature: the $request_time and $msec variables can now be used not
5
+ only in the "log_format" directive.
6
+
7
+ *) Bugfix: cache manager and cache loader processes might not be able to
8
+ start if more than 512 listen sockets were used.
9
+
10
+ *) Bugfix: in the ngx_http_dav_module.
11
+
12
+
2
13
  Changes with nginx 1.2.5 13 Nov 2012
3
14
 
4
15
  *) Feature: the "optional_no_ca" parameter of the "ssl_verify_client"
@@ -1,4 +1,15 @@
1
1
 
2
+ Изменения в nginx 1.2.6 11.12.2012
3
+
4
+ *) Добавление: переменные $request_time и $msec теперь можно
5
+ использовать не только в директиве log_format.
6
+
7
+ *) Исправление: cache manager и cache loader могли не запускаться, если
8
+ использовалось более 512 listen-сокетов.
9
+
10
+ *) Исправление: в модуле ngx_http_dav_module.
11
+
12
+
2
13
  Изменения в nginx 1.2.5 13.11.2012
3
14
 
4
15
  *) Добавление: параметр optional_no_ca директивы ssl_verify_client.
@@ -9,8 +9,8 @@
9
9
  #define _NGINX_H_INCLUDED_
10
10
 
11
11
 
12
- #define nginx_version 1002005
13
- #define NGINX_VERSION "1.2.5"
12
+ #define nginx_version 1002006
13
+ #define NGINX_VERSION "1.2.6"
14
14
  #define NGINX_VER "nginx/" NGINX_VERSION
15
15
 
16
16
  #define NGINX_VAR "NGINX"
@@ -749,6 +749,8 @@ ngx_close_listening_sockets(ngx_cycle_t *cycle)
749
749
 
750
750
  ls[i].fd = (ngx_socket_t) -1;
751
751
  }
752
+
753
+ cycle->listening.nelts = 0;
752
754
  }
753
755
 
754
756
 
@@ -447,7 +447,9 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
447
447
  continue;
448
448
  }
449
449
 
450
- if (shm_zone[i].shm.size == oshm_zone[n].shm.size) {
450
+ if (shm_zone[i].tag == oshm_zone[n].tag
451
+ && shm_zone[i].shm.size == oshm_zone[n].shm.size)
452
+ {
451
453
  shm_zone[i].shm.addr = oshm_zone[n].shm.addr;
452
454
 
453
455
  if (shm_zone[i].init(&shm_zone[i], oshm_zone[n].data)
@@ -117,11 +117,11 @@ ngx_shmtx_lock(ngx_shmtx_t *mtx)
117
117
  "sem_wait() failed while waiting on shmtx");
118
118
  break;
119
119
  }
120
-
121
- ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
122
- "shmtx awoke");
123
120
  }
124
121
 
122
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, ngx_cycle->log, 0,
123
+ "shmtx awoke");
124
+
125
125
  continue;
126
126
  }
127
127
 
@@ -209,6 +209,11 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
209
209
  ngx_ext_rename_file_t ext;
210
210
  ngx_http_dav_loc_conf_t *dlcf;
211
211
 
212
+ if (r->request_body == NULL || r->request_body->temp_file == NULL) {
213
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
214
+ return;
215
+ }
216
+
212
217
  ngx_http_map_uri_to_path(r, &path, &root, 0);
213
218
 
214
219
  path.len--;
@@ -50,7 +50,7 @@ our @EXPORT = qw(
50
50
  HTTP_INSUFFICIENT_STORAGE
51
51
  );
52
52
 
53
- our $VERSION = '1.2.5';
53
+ our $VERSION = '1.2.6';
54
54
 
55
55
  require XSLoader;
56
56
  XSLoader::load('nginx', $VERSION);
@@ -112,7 +112,7 @@ static ngx_str_t ngx_http_status_lines[] = {
112
112
  #define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX)
113
113
 
114
114
  ngx_string("500 Internal Server Error"),
115
- ngx_string("501 Method Not Implemented"),
115
+ ngx_string("501 Not Implemented"),
116
116
  ngx_string("502 Bad Gateway"),
117
117
  ngx_string("503 Service Temporarily Unavailable"),
118
118
  ngx_string("504 Gateway Time-out"),
@@ -31,9 +31,9 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
31
31
  {
32
32
  size_t preread;
33
33
  ssize_t size;
34
+ ngx_int_t rc;
34
35
  ngx_buf_t *b;
35
36
  ngx_chain_t *cl, **next;
36
- ngx_temp_file_t *tf;
37
37
  ngx_http_request_body_t *rb;
38
38
  ngx_http_core_loc_conf_t *clcf;
39
39
 
@@ -45,12 +45,14 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
45
45
  }
46
46
 
47
47
  if (ngx_http_test_expect(r) != NGX_OK) {
48
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
48
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
49
+ goto done;
49
50
  }
50
51
 
51
52
  rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
52
53
  if (rb == NULL) {
53
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
54
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
55
+ goto done;
54
56
  }
55
57
 
56
58
  r->request_body = rb;
@@ -65,31 +67,9 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
65
67
  if (r->headers_in.content_length_n == 0) {
66
68
 
67
69
  if (r->request_body_in_file_only) {
68
- tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
69
- if (tf == NULL) {
70
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
71
- }
72
-
73
- tf->file.fd = NGX_INVALID_FILE;
74
- tf->file.log = r->connection->log;
75
- tf->path = clcf->client_body_temp_path;
76
- tf->pool = r->pool;
77
- tf->warn = "a client request body is buffered to a temporary file";
78
- tf->log_level = r->request_body_file_log_level;
79
- tf->persistent = r->request_body_in_persistent_file;
80
- tf->clean = r->request_body_in_clean_file;
81
-
82
- if (r->request_body_file_group_access) {
83
- tf->access = 0660;
84
- }
85
-
86
- rb->temp_file = tf;
87
-
88
- if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
89
- tf->persistent, tf->clean, tf->access)
90
- != NGX_OK)
91
- {
92
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
70
+ if (ngx_http_write_request_body(r, NULL) != NGX_OK) {
71
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
72
+ goto done;
93
73
  }
94
74
  }
95
75
 
@@ -119,7 +99,8 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
119
99
 
120
100
  b = ngx_calloc_buf(r->pool);
121
101
  if (b == NULL) {
122
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
102
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
103
+ goto done;
123
104
  }
124
105
 
125
106
  b->temporary = 1;
@@ -130,7 +111,8 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
130
111
 
131
112
  rb->bufs = ngx_alloc_chain_link(r->pool);
132
113
  if (rb->bufs == NULL) {
133
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
114
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
115
+ goto done;
134
116
  }
135
117
 
136
118
  rb->bufs->buf = b;
@@ -148,7 +130,8 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
148
130
 
149
131
  if (r->request_body_in_file_only) {
150
132
  if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) {
151
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
133
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
134
+ goto done;
152
135
  }
153
136
  }
154
137
 
@@ -175,7 +158,8 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
175
158
 
176
159
  r->read_event_handler = ngx_http_read_client_request_body_handler;
177
160
 
178
- return ngx_http_do_read_client_request_body(r);
161
+ rc = ngx_http_do_read_client_request_body(r);
162
+ goto done;
179
163
  }
180
164
 
181
165
  next = &rb->bufs->next;
@@ -205,12 +189,14 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
205
189
 
206
190
  rb->buf = ngx_create_temp_buf(r->pool, size);
207
191
  if (rb->buf == NULL) {
208
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
192
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
193
+ goto done;
209
194
  }
210
195
 
211
196
  cl = ngx_alloc_chain_link(r->pool);
212
197
  if (cl == NULL) {
213
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
198
+ rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
199
+ goto done;
214
200
  }
215
201
 
216
202
  cl->buf = rb->buf;
@@ -235,7 +221,15 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
235
221
 
236
222
  r->read_event_handler = ngx_http_read_client_request_body_handler;
237
223
 
238
- return ngx_http_do_read_client_request_body(r);
224
+ rc = ngx_http_do_read_client_request_body(r);
225
+
226
+ done:
227
+
228
+ if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
229
+ r->main->count--;
230
+ }
231
+
232
+ return rc;
239
233
  }
240
234
 
241
235
 
@@ -419,6 +413,19 @@ ngx_http_write_request_body(ngx_http_request_t *r, ngx_chain_t *body)
419
413
  }
420
414
 
421
415
  rb->temp_file = tf;
416
+
417
+ if (body == NULL) {
418
+ /* empty body with r->request_body_in_file_only */
419
+
420
+ if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
421
+ tf->persistent, tf->clean, tf->access)
422
+ != NGX_OK)
423
+ {
424
+ return NGX_ERROR;
425
+ }
426
+
427
+ return NGX_OK;
428
+ }
422
429
  }
423
430
 
424
431
  n = ngx_write_chain_to_temp_file(rb->temp_file, body);
@@ -475,19 +482,21 @@ ngx_http_discard_request_body(ngx_http_request_t *r)
475
482
  }
476
483
  }
477
484
 
485
+ if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
486
+ r->lingering_close = 0;
487
+ return NGX_OK;
488
+ }
489
+
490
+ /* == NGX_AGAIN */
491
+
478
492
  r->read_event_handler = ngx_http_discarded_request_body_handler;
479
493
 
480
494
  if (ngx_handle_read_event(rev, 0) != NGX_OK) {
481
495
  return NGX_HTTP_INTERNAL_SERVER_ERROR;
482
496
  }
483
497
 
484
- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
485
- r->lingering_close = 0;
486
-
487
- } else {
488
- r->count++;
489
- r->discard_body = 1;
490
- }
498
+ r->count++;
499
+ r->discard_body = 1;
491
500
 
492
501
  return NGX_OK;
493
502
  }
@@ -260,9 +260,9 @@ static char ngx_http_error_500_page[] =
260
260
 
261
261
  static char ngx_http_error_501_page[] =
262
262
  "<html>" CRLF
263
- "<head><title>501 Method Not Implemented</title></head>" CRLF
263
+ "<head><title>501 Not Implemented</title></head>" CRLF
264
264
  "<body bgcolor=\"white\">" CRLF
265
- "<center><h1>501 Method Not Implemented</h1></center>" CRLF
265
+ "<center><h1>501 Not Implemented</h1></center>" CRLF
266
266
  ;
267
267
 
268
268
 
@@ -384,6 +384,7 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
384
384
  case NGX_HTTPS_CERT_ERROR:
385
385
  case NGX_HTTPS_NO_CERT:
386
386
  case NGX_HTTP_INTERNAL_SERVER_ERROR:
387
+ case NGX_HTTP_NOT_IMPLEMENTED:
387
388
  r->keepalive = 0;
388
389
  }
389
390
  }
@@ -1809,9 +1809,16 @@ ngx_http_upstream_test_connect(ngx_connection_t *c)
1809
1809
  #if (NGX_HAVE_KQUEUE)
1810
1810
 
1811
1811
  if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1812
- if (c->write->pending_eof) {
1812
+ if (c->write->pending_eof || c->read->pending_eof) {
1813
+ if (c->write->pending_eof) {
1814
+ err = c->write->kq_errno;
1815
+
1816
+ } else {
1817
+ err = c->read->kq_errno;
1818
+ }
1819
+
1813
1820
  c->log->action = "connecting to upstream";
1814
- (void) ngx_connection_error(c, c->write->kq_errno,
1821
+ (void) ngx_connection_error(c, err,
1815
1822
  "kevent() reported that connect() failed");
1816
1823
  return NGX_ERROR;
1817
1824
  }
@@ -430,6 +430,10 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
430
430
  if (rrp->peers->single) {
431
431
  peer = &rrp->peers->peer[0];
432
432
 
433
+ if (peer->down) {
434
+ goto failed;
435
+ }
436
+
433
437
  } else {
434
438
 
435
439
  /* there are several peers */
@@ -79,6 +79,8 @@ static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
79
79
  ngx_http_variable_value_t *v, uintptr_t data);
80
80
  static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
81
81
  ngx_http_variable_value_t *v, uintptr_t data);
82
+ static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r,
83
+ ngx_http_variable_value_t *v, uintptr_t data);
82
84
  static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,
83
85
  ngx_http_variable_value_t *v, uintptr_t data);
84
86
 
@@ -108,6 +110,8 @@ static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r,
108
110
  ngx_http_variable_value_t *v, uintptr_t data);
109
111
  static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
110
112
  ngx_http_variable_value_t *v, uintptr_t data);
113
+ static ngx_int_t ngx_http_variable_msec(ngx_http_request_t *r,
114
+ ngx_http_variable_value_t *v, uintptr_t data);
111
115
 
112
116
  /*
113
117
  * TODO:
@@ -237,6 +241,9 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
237
241
  ngx_http_variable_request_body_file,
238
242
  0, 0, 0 },
239
243
 
244
+ { ngx_string("request_time"), NULL, ngx_http_variable_request_time,
245
+ 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
246
+
240
247
  { ngx_string("status"), NULL,
241
248
  ngx_http_variable_status, 0,
242
249
  NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -285,6 +292,9 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
285
292
  { ngx_string("pid"), NULL, ngx_http_variable_pid,
286
293
  0, 0, 0 },
287
294
 
295
+ { ngx_string("msec"), NULL, ngx_http_variable_msec,
296
+ 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
297
+
288
298
  #if (NGX_HAVE_TCP_INFO)
289
299
  { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo,
290
300
  0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -1757,7 +1767,7 @@ ngx_http_variable_request_body(ngx_http_request_t *r,
1757
1767
  {
1758
1768
  u_char *p;
1759
1769
  size_t len;
1760
- ngx_buf_t *buf, *next;
1770
+ ngx_buf_t *buf;
1761
1771
  ngx_chain_t *cl;
1762
1772
 
1763
1773
  if (r->request_body == NULL
@@ -1782,8 +1792,13 @@ ngx_http_variable_request_body(ngx_http_request_t *r,
1782
1792
  return NGX_OK;
1783
1793
  }
1784
1794
 
1785
- next = cl->next->buf;
1786
- len = (buf->last - buf->pos) + (next->last - next->pos);
1795
+ len = buf->last - buf->pos;
1796
+ cl = cl->next;
1797
+
1798
+ for ( /* void */ ; cl; cl = cl->next) {
1799
+ buf = cl->buf;
1800
+ len += buf->last - buf->pos;
1801
+ }
1787
1802
 
1788
1803
  p = ngx_pnalloc(r->pool, len);
1789
1804
  if (p == NULL) {
@@ -1791,9 +1806,12 @@ ngx_http_variable_request_body(ngx_http_request_t *r,
1791
1806
  }
1792
1807
 
1793
1808
  v->data = p;
1809
+ cl = r->request_body->bufs;
1794
1810
 
1795
- p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
1796
- ngx_memcpy(p, next->pos, next->last - next->pos);
1811
+ for ( /* void */ ; cl; cl = cl->next) {
1812
+ buf = cl->buf;
1813
+ p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
1814
+ }
1797
1815
 
1798
1816
  v->len = len;
1799
1817
  v->valid = 1;
@@ -1824,6 +1842,35 @@ ngx_http_variable_request_body_file(ngx_http_request_t *r,
1824
1842
  }
1825
1843
 
1826
1844
 
1845
+ static ngx_int_t
1846
+ ngx_http_variable_request_time(ngx_http_request_t *r,
1847
+ ngx_http_variable_value_t *v, uintptr_t data)
1848
+ {
1849
+ u_char *p;
1850
+ ngx_time_t *tp;
1851
+ ngx_msec_int_t ms;
1852
+
1853
+ p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
1854
+ if (p == NULL) {
1855
+ return NGX_ERROR;
1856
+ }
1857
+
1858
+ tp = ngx_timeofday();
1859
+
1860
+ ms = (ngx_msec_int_t)
1861
+ ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
1862
+ ms = ngx_max(ms, 0);
1863
+
1864
+ v->len = ngx_sprintf(p, "%T.%03M", ms / 1000, ms % 1000) - p;
1865
+ v->valid = 1;
1866
+ v->no_cacheable = 0;
1867
+ v->not_found = 0;
1868
+ v->data = p;
1869
+
1870
+ return NGX_OK;
1871
+ }
1872
+
1873
+
1827
1874
  static ngx_int_t
1828
1875
  ngx_http_variable_connection(ngx_http_request_t *r,
1829
1876
  ngx_http_variable_value_t *v, uintptr_t data)
@@ -1915,6 +1962,30 @@ ngx_http_variable_pid(ngx_http_request_t *r,
1915
1962
  }
1916
1963
 
1917
1964
 
1965
+ static ngx_int_t
1966
+ ngx_http_variable_msec(ngx_http_request_t *r,
1967
+ ngx_http_variable_value_t *v, uintptr_t data)
1968
+ {
1969
+ u_char *p;
1970
+ ngx_time_t *tp;
1971
+
1972
+ p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
1973
+ if (p == NULL) {
1974
+ return NGX_ERROR;
1975
+ }
1976
+
1977
+ tp = ngx_timeofday();
1978
+
1979
+ v->len = ngx_sprintf(p, "%T.%03M", tp->sec, tp->msec) - p;
1980
+ v->valid = 1;
1981
+ v->no_cacheable = 0;
1982
+ v->not_found = 0;
1983
+ v->data = p;
1984
+
1985
+ return NGX_OK;
1986
+ }
1987
+
1988
+
1918
1989
  void *
1919
1990
  ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_str_t *match)
1920
1991
  {
@@ -241,8 +241,12 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
241
241
  return NGX_ERROR;
242
242
  }
243
243
 
244
+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
245
+ "writev: %d, %z", file->fd, n);
246
+
244
247
  file->sys_offset += n;
245
248
  file->offset += n;
249
+ offset += n;
246
250
  total += n;
247
251
 
248
252
  } while (cl);
@@ -20,7 +20,7 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
20
20
  static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
21
21
  static void ngx_master_process_exit(ngx_cycle_t *cycle);
22
22
  static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
23
- static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority);
23
+ static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
24
24
  static void ngx_worker_process_exit(ngx_cycle_t *cycle);
25
25
  static void ngx_channel_handler(ngx_event_t *ev);
26
26
  #if (NGX_THREADS)
@@ -62,7 +62,6 @@ ngx_int_t ngx_threads_n;
62
62
  #endif
63
63
 
64
64
 
65
- uint64_t cpu_affinity;
66
65
  static u_char master_process[] = "master process";
67
66
 
68
67
 
@@ -360,10 +359,8 @@ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
360
359
 
361
360
  for (i = 0; i < n; i++) {
362
361
 
363
- cpu_affinity = ngx_get_cpu_affinity(i);
364
-
365
- ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
366
- "worker process", type);
362
+ ngx_spawn_process(cycle, ngx_worker_process_cycle,
363
+ (void *) (intptr_t) i, "worker process", type);
367
364
 
368
365
  ch.pid = ngx_processes[ngx_process_slot].pid;
369
366
  ch.slot = ngx_process_slot;
@@ -371,8 +368,6 @@ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
371
368
 
372
369
  ngx_pass_open_channel(cycle, &ch);
373
370
  }
374
-
375
- cpu_affinity = 0;
376
371
  }
377
372
 
378
373
 
@@ -726,12 +721,14 @@ ngx_master_process_exit(ngx_cycle_t *cycle)
726
721
  static void
727
722
  ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
728
723
  {
724
+ ngx_int_t worker = (intptr_t) data;
725
+
729
726
  ngx_uint_t i;
730
727
  ngx_connection_t *c;
731
728
 
732
729
  ngx_process = NGX_PROCESS_WORKER;
733
730
 
734
- ngx_worker_process_init(cycle, 1);
731
+ ngx_worker_process_init(cycle, worker);
735
732
 
736
733
  ngx_setproctitle("worker process");
737
734
 
@@ -837,9 +834,10 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
837
834
 
838
835
 
839
836
  static void
840
- ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
837
+ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
841
838
  {
842
839
  sigset_t set;
840
+ uint64_t cpu_affinity;
843
841
  ngx_int_t n;
844
842
  ngx_uint_t i;
845
843
  struct rlimit rlmt;
@@ -853,7 +851,7 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
853
851
 
854
852
  ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
855
853
 
856
- if (priority && ccf->priority != 0) {
854
+ if (worker >= 0 && ccf->priority != 0) {
857
855
  if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
858
856
  ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
859
857
  "setpriority(%d) failed", ccf->priority);
@@ -917,8 +915,12 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
917
915
  }
918
916
  }
919
917
 
920
- if (cpu_affinity) {
921
- ngx_setaffinity(cpu_affinity, cycle->log);
918
+ if (worker >= 0) {
919
+ cpu_affinity = ngx_get_cpu_affinity(worker);
920
+
921
+ if (cpu_affinity) {
922
+ ngx_setaffinity(cpu_affinity, cycle->log);
923
+ }
922
924
  }
923
925
 
924
926
  #if (NGX_HAVE_PR_SET_DUMPABLE)
@@ -1294,14 +1296,19 @@ ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data)
1294
1296
  void *ident[4];
1295
1297
  ngx_event_t ev;
1296
1298
 
1297
- cycle->connection_n = 512;
1298
-
1299
+ /*
1300
+ * Set correct process type since closing listening Unix domain socket
1301
+ * in a master process also removes the Unix domain socket file.
1302
+ */
1299
1303
  ngx_process = NGX_PROCESS_HELPER;
1300
1304
 
1301
- ngx_worker_process_init(cycle, 0);
1302
-
1303
1305
  ngx_close_listening_sockets(cycle);
1304
1306
 
1307
+ /* Set a moderate number of connections for a helper process. */
1308
+ cycle->connection_n = 512;
1309
+
1310
+ ngx_worker_process_init(cycle, -1);
1311
+
1305
1312
  ngx_memzero(&ev, sizeof(ngx_event_t));
1306
1313
  ev.handler = ctx->handler;
1307
1314
  ev.data = ident;