nginxtra 1.6.3.9 → 1.8.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +358 -14
  6. data/vendor/nginx/CHANGES.ru +372 -18
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/clang +5 -0
  9. data/vendor/nginx/auto/cc/gcc +5 -0
  10. data/vendor/nginx/auto/lib/google-perftools/conf +1 -1
  11. data/vendor/nginx/auto/lib/openssl/make +0 -5
  12. data/vendor/nginx/auto/lib/perl/conf +9 -1
  13. data/vendor/nginx/auto/make +1 -1
  14. data/vendor/nginx/auto/modules +11 -0
  15. data/vendor/nginx/auto/options +10 -2
  16. data/vendor/nginx/auto/os/darwin +0 -1
  17. data/vendor/nginx/auto/os/freebsd +6 -23
  18. data/vendor/nginx/auto/sources +16 -14
  19. data/vendor/nginx/auto/summary +3 -24
  20. data/vendor/nginx/auto/threads +20 -0
  21. data/vendor/nginx/auto/types/sizeof +2 -12
  22. data/vendor/nginx/auto/unix +50 -6
  23. data/vendor/nginx/configure +5 -0
  24. data/vendor/nginx/contrib/vim/syntax/nginx.vim +183 -50
  25. data/vendor/nginx/src/core/nginx.c +21 -9
  26. data/vendor/nginx/src/core/nginx.h +8 -2
  27. data/vendor/nginx/src/core/ngx_buf.c +88 -0
  28. data/vendor/nginx/src/core/ngx_buf.h +15 -1
  29. data/vendor/nginx/src/core/ngx_conf_file.c +4 -1
  30. data/vendor/nginx/src/core/ngx_connection.c +25 -66
  31. data/vendor/nginx/src/core/ngx_connection.h +1 -3
  32. data/vendor/nginx/src/core/ngx_core.h +11 -3
  33. data/vendor/nginx/src/core/ngx_crypt.c +1 -1
  34. data/vendor/nginx/src/core/ngx_cycle.c +7 -1
  35. data/vendor/nginx/src/core/ngx_cycle.h +6 -2
  36. data/vendor/nginx/src/core/ngx_file.c +13 -5
  37. data/vendor/nginx/src/core/ngx_file.h +6 -0
  38. data/vendor/nginx/src/core/ngx_log.c +215 -21
  39. data/vendor/nginx/src/core/ngx_log.h +9 -1
  40. data/vendor/nginx/src/core/ngx_output_chain.c +104 -15
  41. data/vendor/nginx/src/core/ngx_palloc.c +3 -7
  42. data/vendor/nginx/src/core/ngx_rbtree.c +2 -4
  43. data/vendor/nginx/src/core/ngx_rbtree.h +2 -4
  44. data/vendor/nginx/src/core/ngx_regex.c +14 -6
  45. data/vendor/nginx/src/core/ngx_resolver.c +16 -23
  46. data/vendor/nginx/src/core/ngx_resolver.h +8 -7
  47. data/vendor/nginx/src/core/ngx_shmtx.c +1 -1
  48. data/vendor/nginx/src/core/ngx_slab.c +89 -2
  49. data/vendor/nginx/src/core/ngx_slab.h +3 -0
  50. data/vendor/nginx/src/core/ngx_string.c +58 -2
  51. data/vendor/nginx/src/core/ngx_string.h +1 -0
  52. data/vendor/nginx/src/core/ngx_syslog.c +374 -0
  53. data/vendor/nginx/src/core/ngx_syslog.h +30 -0
  54. data/vendor/nginx/src/core/ngx_thread_pool.c +630 -0
  55. data/vendor/nginx/src/core/ngx_thread_pool.h +36 -0
  56. data/vendor/nginx/src/core/ngx_times.c +19 -2
  57. data/vendor/nginx/src/core/ngx_times.h +1 -0
  58. data/vendor/nginx/src/event/modules/ngx_aio_module.c +1 -1
  59. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +9 -24
  60. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +152 -28
  61. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +43 -25
  62. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +86 -156
  63. data/vendor/nginx/src/event/modules/ngx_poll_module.c +21 -37
  64. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +15 -27
  65. data/vendor/nginx/src/event/modules/ngx_select_module.c +10 -12
  66. data/vendor/nginx/src/event/modules/ngx_win32_select_module.c +7 -9
  67. data/vendor/nginx/src/event/ngx_event.c +5 -33
  68. data/vendor/nginx/src/event/ngx_event.h +15 -50
  69. data/vendor/nginx/src/event/ngx_event_accept.c +11 -10
  70. data/vendor/nginx/src/event/ngx_event_connect.c +0 -11
  71. data/vendor/nginx/src/event/ngx_event_connect.h +1 -4
  72. data/vendor/nginx/src/event/ngx_event_openssl.c +622 -38
  73. data/vendor/nginx/src/event/ngx_event_openssl.h +20 -2
  74. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +5 -1
  75. data/vendor/nginx/src/event/ngx_event_pipe.c +45 -19
  76. data/vendor/nginx/src/event/ngx_event_pipe.h +3 -0
  77. data/vendor/nginx/src/event/ngx_event_posted.c +7 -145
  78. data/vendor/nginx/src/event/ngx_event_posted.h +12 -39
  79. data/vendor/nginx/src/event/ngx_event_timer.c +50 -70
  80. data/vendor/nginx/src/event/ngx_event_timer.h +2 -14
  81. data/vendor/nginx/src/http/modules/ngx_http_addition_filter_module.c +1 -1
  82. data/vendor/nginx/src/http/modules/ngx_http_autoindex_module.c +416 -71
  83. data/vendor/nginx/src/http/modules/ngx_http_charset_filter_module.c +19 -15
  84. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +16 -4
  85. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +601 -134
  86. data/vendor/nginx/src/http/modules/ngx_http_geo_module.c +1 -1
  87. data/vendor/nginx/src/http/modules/ngx_http_geoip_module.c +9 -3
  88. data/vendor/nginx/src/http/modules/ngx_http_gunzip_filter_module.c +9 -3
  89. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +9 -3
  90. data/vendor/nginx/src/http/modules/ngx_http_gzip_static_module.c +0 -2
  91. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +197 -91
  92. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -0
  93. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +65 -162
  94. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +53 -67
  95. data/vendor/nginx/src/http/modules/ngx_http_log_module.c +128 -23
  96. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +25 -6
  97. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +1 -1
  98. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +39 -13
  99. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +697 -141
  100. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +5 -1
  101. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +282 -125
  102. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +4 -1
  103. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +44 -1
  104. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.h +2 -0
  105. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +10 -8
  106. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +18 -3
  107. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +641 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +3 -21
  110. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +0 -5
  111. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +449 -125
  112. data/vendor/nginx/src/http/modules/ngx_http_xslt_filter_module.c +4 -2
  113. data/vendor/nginx/src/http/modules/perl/ngx_http_perl_module.c +2 -1
  114. data/vendor/nginx/src/http/ngx_http.c +10 -5
  115. data/vendor/nginx/src/http/ngx_http.h +4 -4
  116. data/vendor/nginx/src/http/ngx_http_cache.h +26 -1
  117. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +109 -68
  118. data/vendor/nginx/src/http/ngx_http_core_module.c +191 -46
  119. data/vendor/nginx/src/http/ngx_http_core_module.h +16 -4
  120. data/vendor/nginx/src/http/ngx_http_file_cache.c +584 -67
  121. data/vendor/nginx/src/http/ngx_http_parse.c +55 -4
  122. data/vendor/nginx/src/http/ngx_http_request.c +14 -6
  123. data/vendor/nginx/src/http/ngx_http_request.h +12 -4
  124. data/vendor/nginx/src/http/ngx_http_request_body.c +114 -28
  125. data/vendor/nginx/src/http/ngx_http_spdy.c +383 -229
  126. data/vendor/nginx/src/http/ngx_http_spdy.h +8 -5
  127. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +12 -4
  128. data/vendor/nginx/src/http/ngx_http_special_response.c +2 -2
  129. data/vendor/nginx/src/http/ngx_http_upstream.c +808 -132
  130. data/vendor/nginx/src/http/ngx_http_upstream.h +33 -3
  131. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +72 -65
  132. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +1 -2
  133. data/vendor/nginx/src/http/ngx_http_variables.c +47 -3
  134. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +15 -6
  135. data/vendor/nginx/src/mail/ngx_mail.c +2 -3
  136. data/vendor/nginx/src/mail/ngx_mail.h +2 -0
  137. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +140 -11
  138. data/vendor/nginx/src/mail/ngx_mail_core_module.c +3 -3
  139. data/vendor/nginx/src/mail/ngx_mail_handler.c +79 -2
  140. data/vendor/nginx/src/mail/ngx_mail_imap_module.c +3 -1
  141. data/vendor/nginx/src/mail/ngx_mail_pop3_module.c +3 -1
  142. data/vendor/nginx/src/mail/ngx_mail_smtp_module.c +3 -1
  143. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +125 -1
  144. data/vendor/nginx/src/mail/ngx_mail_ssl_module.h +8 -0
  145. data/vendor/nginx/src/misc/ngx_cpp_test_module.cpp +1 -1
  146. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +1 -1
  147. data/vendor/nginx/src/os/unix/ngx_channel.c +0 -7
  148. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +0 -3
  149. data/vendor/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +44 -208
  150. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +25 -17
  151. data/vendor/nginx/src/os/unix/ngx_files.c +109 -0
  152. data/vendor/nginx/src/os/unix/ngx_files.h +6 -0
  153. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +0 -6
  154. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +78 -206
  155. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +25 -14
  156. data/vendor/nginx/src/os/unix/ngx_linux_config.h +4 -1
  157. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +235 -194
  158. data/vendor/nginx/src/os/unix/ngx_os.h +25 -3
  159. data/vendor/nginx/src/os/unix/ngx_posix_init.c +4 -2
  160. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +13 -195
  161. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +0 -1
  162. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +27 -108
  163. data/vendor/nginx/src/os/unix/ngx_setproctitle.h +2 -2
  164. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +12 -67
  165. data/vendor/nginx/src/os/unix/ngx_thread.h +26 -83
  166. data/vendor/nginx/src/os/unix/ngx_thread_cond.c +87 -0
  167. data/vendor/nginx/src/os/unix/ngx_thread_id.c +70 -0
  168. data/vendor/nginx/src/os/unix/ngx_thread_mutex.c +174 -0
  169. data/vendor/nginx/src/os/unix/ngx_user.c +2 -20
  170. data/vendor/nginx/src/os/unix/ngx_writev_chain.c +129 -98
  171. metadata +16 -17
  172. data/vendor/nginx/auto/lib/zlib/patch.zlib.h +0 -10
  173. data/vendor/nginx/src/event/ngx_event_busy_lock.c +0 -286
  174. data/vendor/nginx/src/event/ngx_event_busy_lock.h +0 -65
  175. data/vendor/nginx/src/event/ngx_event_mutex.c +0 -70
  176. data/vendor/nginx/src/http/ngx_http_busy_lock.c +0 -307
  177. data/vendor/nginx/src/http/ngx_http_busy_lock.h +0 -54
  178. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +0 -756
  179. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +0 -122
  180. data/vendor/nginx/src/os/unix/ngx_pthread_thread.c +0 -278
  181. data/vendor/nginx/src/os/unix/rfork_thread.S +0 -73
@@ -66,7 +66,7 @@ ngx_crypt_apr1(ngx_pool_t *pool, u_char *key, u_char *salt, u_char **encrypted)
66
66
  size_t saltlen, keylen;
67
67
  ngx_md5_t md5, ctx1;
68
68
 
69
- /* Apache's apr1 crypt is Paul-Henning Kamp's md5 crypt with $apr1$ magic */
69
+ /* Apache's apr1 crypt is Poul-Henning Kamp's md5 crypt with $apr1$ magic */
70
70
 
71
71
  keylen = ngx_strlen(key);
72
72
 
@@ -26,7 +26,7 @@ static ngx_event_t ngx_cleaner_event;
26
26
  ngx_uint_t ngx_test_config;
27
27
  ngx_uint_t ngx_quiet_mode;
28
28
 
29
- #if (NGX_THREADS)
29
+ #if (NGX_OLD_THREADS)
30
30
  ngx_tls_key_t ngx_core_tls_key;
31
31
  #endif
32
32
 
@@ -1104,6 +1104,8 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
1104
1104
  ngx_close_file_n " \"%s\" failed",
1105
1105
  file[i].name.data);
1106
1106
  }
1107
+
1108
+ continue;
1107
1109
  }
1108
1110
 
1109
1111
  if (fi.st_uid != user) {
@@ -1117,6 +1119,8 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
1117
1119
  ngx_close_file_n " \"%s\" failed",
1118
1120
  file[i].name.data);
1119
1121
  }
1122
+
1123
+ continue;
1120
1124
  }
1121
1125
  }
1122
1126
 
@@ -1133,6 +1137,8 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
1133
1137
  ngx_close_file_n " \"%s\" failed",
1134
1138
  file[i].name.data);
1135
1139
  }
1140
+
1141
+ continue;
1136
1142
  }
1137
1143
  }
1138
1144
  }
@@ -103,7 +103,7 @@ typedef struct {
103
103
  ngx_array_t env;
104
104
  char **environment;
105
105
 
106
- #if (NGX_THREADS)
106
+ #if (NGX_OLD_THREADS)
107
107
  ngx_int_t worker_threads;
108
108
  size_t thread_stack_size;
109
109
  #endif
@@ -111,10 +111,14 @@ typedef struct {
111
111
  } ngx_core_conf_t;
112
112
 
113
113
 
114
+ #if (NGX_OLD_THREADS)
115
+
114
116
  typedef struct {
115
117
  ngx_pool_t *pool; /* pcre's malloc() pool */
116
118
  } ngx_core_tls_t;
117
119
 
120
+ #endif
121
+
118
122
 
119
123
  #define ngx_is_init_cycle(cycle) (cycle->conf_ctx == NULL)
120
124
 
@@ -136,7 +140,7 @@ extern ngx_array_t ngx_old_cycles;
136
140
  extern ngx_module_t ngx_core_module;
137
141
  extern ngx_uint_t ngx_test_config;
138
142
  extern ngx_uint_t ngx_quiet_mode;
139
- #if (NGX_THREADS)
143
+ #if (NGX_OLD_THREADS)
140
144
  extern ngx_tls_key_t ngx_core_tls_key;
141
145
  #endif
142
146
 
@@ -114,7 +114,7 @@ ngx_write_chain_to_temp_file(ngx_temp_file_t *tf, ngx_chain_t *chain)
114
114
  rc = ngx_create_temp_file(&tf->file, tf->path, tf->pool,
115
115
  tf->persistent, tf->clean, tf->access);
116
116
 
117
- if (rc == NGX_ERROR || rc == NGX_AGAIN) {
117
+ if (rc != NGX_OK) {
118
118
  return rc;
119
119
  }
120
120
 
@@ -356,7 +356,7 @@ ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
356
356
  }
357
357
 
358
358
  if (ngx_conf_full_name(cf->cycle, &path->name, 0) != NGX_OK) {
359
- return NULL;
359
+ return NGX_CONF_ERROR;
360
360
  }
361
361
 
362
362
  path->conf_file = cf->conf_file->file.name.data;
@@ -372,8 +372,8 @@ ngx_conf_set_path_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
372
372
  path->len += level + 1;
373
373
  }
374
374
 
375
- while (i < 3) {
376
- path->level[i++] = 0;
375
+ if (path->len > 10 + i) {
376
+ return "invalid value";
377
377
  }
378
378
 
379
379
  *slot = path;
@@ -1035,10 +1035,18 @@ ngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)
1035
1035
  ctx->access = ngx_de_access(&dir);
1036
1036
  ctx->mtime = ngx_de_mtime(&dir);
1037
1037
 
1038
- if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) {
1038
+ rc = ctx->pre_tree_handler(ctx, &file);
1039
+
1040
+ if (rc == NGX_ABORT) {
1039
1041
  goto failed;
1040
1042
  }
1041
1043
 
1044
+ if (rc == NGX_DECLINED) {
1045
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,
1046
+ "tree skip dir \"%s\"", file.data);
1047
+ continue;
1048
+ }
1049
+
1042
1050
  if (ngx_walk_tree(ctx, &file) == NGX_ABORT) {
1043
1051
  goto failed;
1044
1052
  }
@@ -23,6 +23,12 @@ struct ngx_file_s {
23
23
 
24
24
  ngx_log_t *log;
25
25
 
26
+ #if (NGX_THREADS)
27
+ ngx_int_t (*thread_handler)(ngx_thread_task_t *task,
28
+ ngx_file_t *file);
29
+ void *thread_ctx;
30
+ #endif
31
+
26
32
  #if (NGX_HAVE_FILE_AIO)
27
33
  ngx_event_aio_t *aio;
28
34
  #endif
@@ -14,6 +14,23 @@ static char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
14
14
  static void ngx_log_insert(ngx_log_t *log, ngx_log_t *new_log);
15
15
 
16
16
 
17
+ #if (NGX_DEBUG)
18
+
19
+ static void ngx_log_memory_writer(ngx_log_t *log, ngx_uint_t level,
20
+ u_char *buf, size_t len);
21
+ static void ngx_log_memory_cleanup(void *data);
22
+
23
+
24
+ typedef struct {
25
+ u_char *start;
26
+ u_char *end;
27
+ u_char *pos;
28
+ ngx_atomic_t written;
29
+ } ngx_log_memory_buf_t;
30
+
31
+ #endif
32
+
33
+
17
34
  static ngx_command_t ngx_errlog_commands[] = {
18
35
 
19
36
  {ngx_string("error_log"),
@@ -91,15 +108,14 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
91
108
  va_list args;
92
109
  #endif
93
110
  u_char *p, *last, *msg;
94
- u_char errstr[NGX_MAX_ERROR_STR];
111
+ ssize_t n;
95
112
  ngx_uint_t wrote_stderr, debug_connection;
113
+ u_char errstr[NGX_MAX_ERROR_STR];
96
114
 
97
115
  last = errstr + NGX_MAX_ERROR_STR;
98
116
 
99
- ngx_memcpy(errstr, ngx_cached_err_log_time.data,
100
- ngx_cached_err_log_time.len);
101
-
102
- p = errstr + ngx_cached_err_log_time.len;
117
+ p = ngx_cpymem(errstr, ngx_cached_err_log_time.data,
118
+ ngx_cached_err_log_time.len);
103
119
 
104
120
  p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
105
121
 
@@ -148,12 +164,34 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
148
164
  break;
149
165
  }
150
166
 
151
- (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
167
+ if (log->writer) {
168
+ log->writer(log, level, errstr, p - errstr);
169
+ goto next;
170
+ }
171
+
172
+ if (ngx_time() == log->disk_full_time) {
173
+
174
+ /*
175
+ * on FreeBSD writing to a full filesystem with enabled softupdates
176
+ * may block process for much longer time than writing to non-full
177
+ * filesystem, so we skip writing to a log for one second
178
+ */
179
+
180
+ goto next;
181
+ }
182
+
183
+ n = ngx_write_fd(log->file->fd, errstr, p - errstr);
184
+
185
+ if (n == -1 && ngx_errno == NGX_ENOSPC) {
186
+ log->disk_full_time = ngx_time();
187
+ }
152
188
 
153
189
  if (log->file->fd == ngx_stderr) {
154
190
  wrote_stderr = 1;
155
191
  }
156
192
 
193
+ next:
194
+
157
195
  log = log->next;
158
196
  }
159
197
 
@@ -225,9 +263,8 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...)
225
263
  u_char errstr[NGX_MAX_ERROR_STR];
226
264
 
227
265
  last = errstr + NGX_MAX_ERROR_STR;
228
- p = errstr + 7;
229
266
 
230
- ngx_memcpy(errstr, "nginx: ", 7);
267
+ p = ngx_cpymem(errstr, "nginx: ", 7);
231
268
 
232
269
  va_start(args, fmt);
233
270
  p = ngx_vslprintf(p, last, fmt, args);
@@ -366,15 +403,35 @@ ngx_log_init(u_char *prefix)
366
403
  ngx_int_t
367
404
  ngx_log_open_default(ngx_cycle_t *cycle)
368
405
  {
369
- static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
406
+ ngx_log_t *log;
407
+ static ngx_str_t error_log = ngx_string(NGX_ERROR_LOG_PATH);
370
408
 
371
- if (cycle->new_log.file == NULL) {
372
- cycle->new_log.file = ngx_conf_open_file(cycle, &error_log);
373
- if (cycle->new_log.file == NULL) {
409
+ if (ngx_log_get_file_log(&cycle->new_log) != NULL) {
410
+ return NGX_OK;
411
+ }
412
+
413
+ if (cycle->new_log.log_level != 0) {
414
+ /* there are some error logs, but no files */
415
+
416
+ log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
417
+ if (log == NULL) {
374
418
  return NGX_ERROR;
375
419
  }
376
420
 
377
- cycle->new_log.log_level = NGX_LOG_ERR;
421
+ } else {
422
+ /* no error logs at all */
423
+ log = &cycle->new_log;
424
+ }
425
+
426
+ log->log_level = NGX_LOG_ERR;
427
+
428
+ log->file = ngx_conf_open_file(cycle, &error_log);
429
+ if (log->file == NULL) {
430
+ return NGX_ERROR;
431
+ }
432
+
433
+ if (log != &cycle->new_log) {
434
+ ngx_log_insert(&cycle->new_log, log);
378
435
  }
379
436
 
380
437
  return NGX_OK;
@@ -390,7 +447,8 @@ ngx_log_redirect_stderr(ngx_cycle_t *cycle)
390
447
  return NGX_OK;
391
448
  }
392
449
 
393
- fd = cycle->log->file->fd;
450
+ /* file log always exists when we are called */
451
+ fd = ngx_log_get_file_log(cycle->log)->file->fd;
394
452
 
395
453
  if (fd != ngx_stderr) {
396
454
  if (ngx_set_stderr(fd) == NGX_FILE_ERROR) {
@@ -405,6 +463,21 @@ ngx_log_redirect_stderr(ngx_cycle_t *cycle)
405
463
  }
406
464
 
407
465
 
466
+ ngx_log_t *
467
+ ngx_log_get_file_log(ngx_log_t *head)
468
+ {
469
+ ngx_log_t *log;
470
+
471
+ for (log = head; log; log = log->next) {
472
+ if (log->file != NULL) {
473
+ return log;
474
+ }
475
+ }
476
+
477
+ return NULL;
478
+ }
479
+
480
+
408
481
  static char *
409
482
  ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
410
483
  {
@@ -482,8 +555,9 @@ ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
482
555
  char *
483
556
  ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head)
484
557
  {
485
- ngx_log_t *new_log;
486
- ngx_str_t *value, name;
558
+ ngx_log_t *new_log;
559
+ ngx_str_t *value, name;
560
+ ngx_syslog_peer_t *peer;
487
561
 
488
562
  if (*head != NULL && (*head)->log_level == 0) {
489
563
  new_log = *head;
@@ -506,13 +580,88 @@ ngx_log_set_log(ngx_conf_t *cf, ngx_log_t **head)
506
580
  ngx_str_null(&name);
507
581
  cf->cycle->log_use_stderr = 1;
508
582
 
509
- } else {
510
- name = value[1];
511
- }
583
+ new_log->file = ngx_conf_open_file(cf->cycle, &name);
584
+ if (new_log->file == NULL) {
585
+ return NGX_CONF_ERROR;
586
+ }
587
+
588
+ } else if (ngx_strncmp(value[1].data, "memory:", 7) == 0) {
589
+
590
+ #if (NGX_DEBUG)
591
+ size_t size, needed;
592
+ ngx_pool_cleanup_t *cln;
593
+ ngx_log_memory_buf_t *buf;
594
+
595
+ value[1].len -= 7;
596
+ value[1].data += 7;
597
+
598
+ needed = sizeof("MEMLOG :" NGX_LINEFEED)
599
+ + cf->conf_file->file.name.len
600
+ + NGX_SIZE_T_LEN
601
+ + NGX_INT_T_LEN
602
+ + NGX_MAX_ERROR_STR;
603
+
604
+ size = ngx_parse_size(&value[1]);
605
+
606
+ if (size == (size_t) NGX_ERROR || size < needed) {
607
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
608
+ "invalid buffer size \"%V\"", &value[1]);
609
+ return NGX_CONF_ERROR;
610
+ }
611
+
612
+ buf = ngx_palloc(cf->pool, sizeof(ngx_log_memory_buf_t));
613
+ if (buf == NULL) {
614
+ return NGX_CONF_ERROR;
615
+ }
616
+
617
+ buf->start = ngx_pnalloc(cf->pool, size);
618
+ if (buf->start == NULL) {
619
+ return NGX_CONF_ERROR;
620
+ }
621
+
622
+ buf->end = buf->start + size;
623
+
624
+ buf->pos = ngx_slprintf(buf->start, buf->end, "MEMLOG %uz %V:%ui%N",
625
+ size, &cf->conf_file->file.name,
626
+ cf->conf_file->line);
627
+
628
+ ngx_memset(buf->pos, ' ', buf->end - buf->pos);
629
+
630
+ cln = ngx_pool_cleanup_add(cf->pool, 0);
631
+ if (cln == NULL) {
632
+ return NGX_CONF_ERROR;
633
+ }
634
+
635
+ cln->data = new_log;
636
+ cln->handler = ngx_log_memory_cleanup;
637
+
638
+ new_log->writer = ngx_log_memory_writer;
639
+ new_log->wdata = buf;
512
640
 
513
- new_log->file = ngx_conf_open_file(cf->cycle, &name);
514
- if (new_log->file == NULL) {
641
+ #else
642
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
643
+ "nginx was built without debug support");
515
644
  return NGX_CONF_ERROR;
645
+ #endif
646
+
647
+ } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) {
648
+ peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t));
649
+ if (peer == NULL) {
650
+ return NGX_CONF_ERROR;
651
+ }
652
+
653
+ if (ngx_syslog_process_conf(cf, peer) != NGX_CONF_OK) {
654
+ return NGX_CONF_ERROR;
655
+ }
656
+
657
+ new_log->writer = ngx_syslog_writer;
658
+ new_log->wdata = peer;
659
+
660
+ } else {
661
+ new_log->file = ngx_conf_open_file(cf->cycle, &value[1]);
662
+ if (new_log->file == NULL) {
663
+ return NGX_CONF_ERROR;
664
+ }
516
665
  }
517
666
 
518
667
  if (ngx_log_set_levels(cf, new_log) != NGX_CONF_OK) {
@@ -559,3 +708,48 @@ ngx_log_insert(ngx_log_t *log, ngx_log_t *new_log)
559
708
 
560
709
  log->next = new_log;
561
710
  }
711
+
712
+
713
+ #if (NGX_DEBUG)
714
+
715
+ static void
716
+ ngx_log_memory_writer(ngx_log_t *log, ngx_uint_t level, u_char *buf,
717
+ size_t len)
718
+ {
719
+ u_char *p;
720
+ size_t avail, written;
721
+ ngx_log_memory_buf_t *mem;
722
+
723
+ mem = log->wdata;
724
+
725
+ if (mem == NULL) {
726
+ return;
727
+ }
728
+
729
+ written = ngx_atomic_fetch_add(&mem->written, len);
730
+
731
+ p = mem->pos + written % (mem->end - mem->pos);
732
+
733
+ avail = mem->end - p;
734
+
735
+ if (avail >= len) {
736
+ ngx_memcpy(p, buf, len);
737
+
738
+ } else {
739
+ ngx_memcpy(p, buf, avail);
740
+ ngx_memcpy(mem->pos, buf + avail, len - avail);
741
+ }
742
+ }
743
+
744
+
745
+ static void
746
+ ngx_log_memory_cleanup(void *data)
747
+ {
748
+ ngx_log_t *log = data;
749
+
750
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "destroy memory log buffer");
751
+
752
+ log->wdata = NULL;
753
+ }
754
+
755
+ #endif