nginxtra 1.0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/VERSION +1 -0
  2. data/bin/nginxtra +5 -0
  3. data/lib/nginxtra.rb +12 -0
  4. data/lib/nginxtra/action.rb +36 -0
  5. data/lib/nginxtra/actions/compile.rb +60 -0
  6. data/lib/nginxtra/actions/install.rb +99 -0
  7. data/lib/nginxtra/actions/reload.rb +14 -0
  8. data/lib/nginxtra/actions/restart.rb +15 -0
  9. data/lib/nginxtra/actions/start.rb +53 -0
  10. data/lib/nginxtra/actions/status.rb +31 -0
  11. data/lib/nginxtra/actions/stop.rb +14 -0
  12. data/lib/nginxtra/cli.rb +77 -0
  13. data/lib/nginxtra/config.rb +339 -0
  14. data/lib/nginxtra/error.rb +13 -0
  15. data/lib/nginxtra/status.rb +57 -0
  16. data/src/nginx/CHANGES +5630 -0
  17. data/src/nginx/CHANGES.ru +5716 -0
  18. data/src/nginx/LICENSE +25 -0
  19. data/src/nginx/README +3 -0
  20. data/src/nginx/auto/cc/acc +15 -0
  21. data/src/nginx/auto/cc/bcc +72 -0
  22. data/src/nginx/auto/cc/ccc +46 -0
  23. data/src/nginx/auto/cc/conf +189 -0
  24. data/src/nginx/auto/cc/gcc +183 -0
  25. data/src/nginx/auto/cc/icc +121 -0
  26. data/src/nginx/auto/cc/msvc +138 -0
  27. data/src/nginx/auto/cc/name +101 -0
  28. data/src/nginx/auto/cc/owc +104 -0
  29. data/src/nginx/auto/cc/sunc +158 -0
  30. data/src/nginx/auto/define +12 -0
  31. data/src/nginx/auto/endianess +45 -0
  32. data/src/nginx/auto/feature +123 -0
  33. data/src/nginx/auto/have +12 -0
  34. data/src/nginx/auto/have_headers +12 -0
  35. data/src/nginx/auto/headers +13 -0
  36. data/src/nginx/auto/include +61 -0
  37. data/src/nginx/auto/init +51 -0
  38. data/src/nginx/auto/install +184 -0
  39. data/src/nginx/auto/lib/conf +83 -0
  40. data/src/nginx/auto/lib/geoip/conf +79 -0
  41. data/src/nginx/auto/lib/google-perftools/conf +45 -0
  42. data/src/nginx/auto/lib/libatomic/conf +43 -0
  43. data/src/nginx/auto/lib/libatomic/make +14 -0
  44. data/src/nginx/auto/lib/libgd/conf +83 -0
  45. data/src/nginx/auto/lib/libxslt/conf +156 -0
  46. data/src/nginx/auto/lib/make +32 -0
  47. data/src/nginx/auto/lib/md5/conf +103 -0
  48. data/src/nginx/auto/lib/md5/make +96 -0
  49. data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
  50. data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
  51. data/src/nginx/auto/lib/md5/makefile.owc +11 -0
  52. data/src/nginx/auto/lib/openssl/conf +74 -0
  53. data/src/nginx/auto/lib/openssl/make +67 -0
  54. data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
  55. data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
  56. data/src/nginx/auto/lib/pcre/conf +180 -0
  57. data/src/nginx/auto/lib/pcre/make +64 -0
  58. data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
  59. data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
  60. data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
  61. data/src/nginx/auto/lib/perl/conf +60 -0
  62. data/src/nginx/auto/lib/perl/make +36 -0
  63. data/src/nginx/auto/lib/sha1/conf +79 -0
  64. data/src/nginx/auto/lib/sha1/make +96 -0
  65. data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
  66. data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
  67. data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
  68. data/src/nginx/auto/lib/test +40 -0
  69. data/src/nginx/auto/lib/zlib/conf +76 -0
  70. data/src/nginx/auto/lib/zlib/make +114 -0
  71. data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
  72. data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
  73. data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
  74. data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
  75. data/src/nginx/auto/make +417 -0
  76. data/src/nginx/auto/modules +479 -0
  77. data/src/nginx/auto/nohave +12 -0
  78. data/src/nginx/auto/options +490 -0
  79. data/src/nginx/auto/os/conf +105 -0
  80. data/src/nginx/auto/os/darwin +116 -0
  81. data/src/nginx/auto/os/freebsd +136 -0
  82. data/src/nginx/auto/os/linux +152 -0
  83. data/src/nginx/auto/os/solaris +60 -0
  84. data/src/nginx/auto/os/win32 +29 -0
  85. data/src/nginx/auto/sources +518 -0
  86. data/src/nginx/auto/stubs +8 -0
  87. data/src/nginx/auto/summary +114 -0
  88. data/src/nginx/auto/types/sizeof +83 -0
  89. data/src/nginx/auto/types/typedef +77 -0
  90. data/src/nginx/auto/types/uintptr_t +42 -0
  91. data/src/nginx/auto/types/value +12 -0
  92. data/src/nginx/auto/unix +719 -0
  93. data/src/nginx/conf/fastcgi.conf +24 -0
  94. data/src/nginx/conf/fastcgi_params +23 -0
  95. data/src/nginx/conf/koi-utf +109 -0
  96. data/src/nginx/conf/koi-win +103 -0
  97. data/src/nginx/conf/mime.types +80 -0
  98. data/src/nginx/conf/nginx.conf +118 -0
  99. data/src/nginx/conf/scgi_params +15 -0
  100. data/src/nginx/conf/uwsgi_params +15 -0
  101. data/src/nginx/conf/win-utf +126 -0
  102. data/src/nginx/configure +108 -0
  103. data/src/nginx/contrib/README +15 -0
  104. data/src/nginx/contrib/geo2nginx.pl +58 -0
  105. data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
  106. data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
  107. data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
  108. data/src/nginx/html/50x.html +18 -0
  109. data/src/nginx/html/index.html +8 -0
  110. data/src/nginx/man/nginx.8 +202 -0
  111. data/src/nginx/src/core/nginx.c +1333 -0
  112. data/src/nginx/src/core/nginx.h +20 -0
  113. data/src/nginx/src/core/ngx_array.c +147 -0
  114. data/src/nginx/src/core/ngx_array.h +53 -0
  115. data/src/nginx/src/core/ngx_buf.c +218 -0
  116. data/src/nginx/src/core/ngx_buf.h +162 -0
  117. data/src/nginx/src/core/ngx_conf_file.c +1506 -0
  118. data/src/nginx/src/core/ngx_conf_file.h +348 -0
  119. data/src/nginx/src/core/ngx_config.h +134 -0
  120. data/src/nginx/src/core/ngx_connection.c +1074 -0
  121. data/src/nginx/src/core/ngx_connection.h +195 -0
  122. data/src/nginx/src/core/ngx_core.h +95 -0
  123. data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
  124. data/src/nginx/src/core/ngx_crc.h +39 -0
  125. data/src/nginx/src/core/ngx_crc32.c +129 -0
  126. data/src/nginx/src/core/ngx_crc32.h +79 -0
  127. data/src/nginx/src/core/ngx_crypt.c +238 -0
  128. data/src/nginx/src/core/ngx_crypt.h +20 -0
  129. data/src/nginx/src/core/ngx_cycle.c +1379 -0
  130. data/src/nginx/src/core/ngx_cycle.h +142 -0
  131. data/src/nginx/src/core/ngx_file.c +993 -0
  132. data/src/nginx/src/core/ngx_file.h +151 -0
  133. data/src/nginx/src/core/ngx_hash.c +976 -0
  134. data/src/nginx/src/core/ngx_hash.h +122 -0
  135. data/src/nginx/src/core/ngx_inet.c +1008 -0
  136. data/src/nginx/src/core/ngx_inet.h +120 -0
  137. data/src/nginx/src/core/ngx_list.c +71 -0
  138. data/src/nginx/src/core/ngx_list.h +83 -0
  139. data/src/nginx/src/core/ngx_log.c +459 -0
  140. data/src/nginx/src/core/ngx_log.h +250 -0
  141. data/src/nginx/src/core/ngx_md5.c +289 -0
  142. data/src/nginx/src/core/ngx_md5.h +60 -0
  143. data/src/nginx/src/core/ngx_murmurhash.c +50 -0
  144. data/src/nginx/src/core/ngx_murmurhash.h +19 -0
  145. data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
  146. data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
  147. data/src/nginx/src/core/ngx_output_chain.c +673 -0
  148. data/src/nginx/src/core/ngx_palloc.c +433 -0
  149. data/src/nginx/src/core/ngx_palloc.h +95 -0
  150. data/src/nginx/src/core/ngx_parse.c +249 -0
  151. data/src/nginx/src/core/ngx_parse.h +24 -0
  152. data/src/nginx/src/core/ngx_queue.c +80 -0
  153. data/src/nginx/src/core/ngx_queue.h +112 -0
  154. data/src/nginx/src/core/ngx_radix_tree.c +291 -0
  155. data/src/nginx/src/core/ngx_radix_tree.h +46 -0
  156. data/src/nginx/src/core/ngx_rbtree.c +383 -0
  157. data/src/nginx/src/core/ngx_rbtree.h +84 -0
  158. data/src/nginx/src/core/ngx_regex.c +206 -0
  159. data/src/nginx/src/core/ngx_regex.h +56 -0
  160. data/src/nginx/src/core/ngx_resolver.c +2201 -0
  161. data/src/nginx/src/core/ngx_resolver.h +149 -0
  162. data/src/nginx/src/core/ngx_sha1.h +31 -0
  163. data/src/nginx/src/core/ngx_shmtx.c +284 -0
  164. data/src/nginx/src/core/ngx_shmtx.h +38 -0
  165. data/src/nginx/src/core/ngx_slab.c +701 -0
  166. data/src/nginx/src/core/ngx_slab.h +54 -0
  167. data/src/nginx/src/core/ngx_spinlock.c +53 -0
  168. data/src/nginx/src/core/ngx_string.c +1837 -0
  169. data/src/nginx/src/core/ngx_string.h +231 -0
  170. data/src/nginx/src/core/ngx_times.c +407 -0
  171. data/src/nginx/src/core/ngx_times.h +51 -0
  172. data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
  173. data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
  174. data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
  175. data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
  176. data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
  177. data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
  178. data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
  179. data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
  180. data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
  181. data/src/nginx/src/event/ngx_event.c +1275 -0
  182. data/src/nginx/src/event/ngx_event.h +573 -0
  183. data/src/nginx/src/event/ngx_event_accept.c +428 -0
  184. data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
  185. data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
  186. data/src/nginx/src/event/ngx_event_connect.c +258 -0
  187. data/src/nginx/src/event/ngx_event_connect.h +76 -0
  188. data/src/nginx/src/event/ngx_event_mutex.c +70 -0
  189. data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
  190. data/src/nginx/src/event/ngx_event_openssl.h +162 -0
  191. data/src/nginx/src/event/ngx_event_pipe.c +996 -0
  192. data/src/nginx/src/event/ngx_event_pipe.h +95 -0
  193. data/src/nginx/src/event/ngx_event_posted.c +173 -0
  194. data/src/nginx/src/event/ngx_event_posted.h +75 -0
  195. data/src/nginx/src/event/ngx_event_timer.c +159 -0
  196. data/src/nginx/src/event/ngx_event_timer.h +102 -0
  197. data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
  198. data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
  199. data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
  200. data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
  201. data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
  202. data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
  203. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
  204. data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
  205. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
  206. data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
  207. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
  208. data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
  209. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
  210. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
  211. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
  212. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
  213. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
  214. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
  215. data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
  216. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
  217. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
  218. data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
  219. data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
  220. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
  221. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
  222. data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
  223. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
  224. data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
  225. data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
  226. data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
  227. data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
  228. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
  229. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
  230. data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
  231. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
  232. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
  233. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
  234. data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
  235. data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
  236. data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
  237. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
  238. data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
  239. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
  240. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
  241. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
  242. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
  243. data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
  244. data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
  245. data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
  246. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
  247. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
  248. data/src/nginx/src/http/modules/perl/typemap +3 -0
  249. data/src/nginx/src/http/ngx_http.c +2073 -0
  250. data/src/nginx/src/http/ngx_http.h +160 -0
  251. data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
  252. data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
  253. data/src/nginx/src/http/ngx_http_cache.h +148 -0
  254. data/src/nginx/src/http/ngx_http_config.h +75 -0
  255. data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
  256. data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
  257. data/src/nginx/src/http/ngx_http_core_module.h +541 -0
  258. data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
  259. data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
  260. data/src/nginx/src/http/ngx_http_parse.c +1734 -0
  261. data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
  262. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
  263. data/src/nginx/src/http/ngx_http_request.c +3181 -0
  264. data/src/nginx/src/http/ngx_http_request.h +573 -0
  265. data/src/nginx/src/http/ngx_http_request_body.c +644 -0
  266. data/src/nginx/src/http/ngx_http_script.c +1752 -0
  267. data/src/nginx/src/http/ngx_http_script.h +257 -0
  268. data/src/nginx/src/http/ngx_http_special_response.c +789 -0
  269. data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
  270. data/src/nginx/src/http/ngx_http_upstream.h +350 -0
  271. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
  272. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
  273. data/src/nginx/src/http/ngx_http_variables.c +2053 -0
  274. data/src/nginx/src/http/ngx_http_variables.h +115 -0
  275. data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
  276. data/src/nginx/src/mail/ngx_mail.c +542 -0
  277. data/src/nginx/src/mail/ngx_mail.h +407 -0
  278. data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
  279. data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
  280. data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
  281. data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
  282. data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
  283. data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
  284. data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
  285. data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
  286. data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
  287. data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
  288. data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
  289. data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
  290. data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
  291. data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
  292. data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
  293. data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
  294. data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
  295. data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
  296. data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
  297. data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
  298. data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
  299. data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
  300. data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
  301. data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
  302. data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
  303. data/src/nginx/src/os/unix/ngx_channel.c +258 -0
  304. data/src/nginx/src/os/unix/ngx_channel.h +34 -0
  305. data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
  306. data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
  307. data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
  308. data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
  309. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
  310. data/src/nginx/src/os/unix/ngx_errno.c +87 -0
  311. data/src/nginx/src/os/unix/ngx_errno.h +68 -0
  312. data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
  313. data/src/nginx/src/os/unix/ngx_files.c +566 -0
  314. data/src/nginx/src/os/unix/ngx_files.h +343 -0
  315. data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
  316. data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
  317. data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
  318. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
  319. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
  320. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
  321. data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
  322. data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
  323. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
  324. data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
  325. data/src/nginx/src/os/unix/ngx_linux.h +18 -0
  326. data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
  327. data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
  328. data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
  329. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
  330. data/src/nginx/src/os/unix/ngx_os.h +84 -0
  331. data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
  332. data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
  333. data/src/nginx/src/os/unix/ngx_process.c +590 -0
  334. data/src/nginx/src/os/unix/ngx_process.h +87 -0
  335. data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
  336. data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
  337. data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
  338. data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
  339. data/src/nginx/src/os/unix/ngx_recv.c +180 -0
  340. data/src/nginx/src/os/unix/ngx_send.c +73 -0
  341. data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
  342. data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
  343. data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
  344. data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
  345. data/src/nginx/src/os/unix/ngx_socket.c +116 -0
  346. data/src/nginx/src/os/unix/ngx_socket.h +64 -0
  347. data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
  348. data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
  349. data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
  350. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
  351. data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
  352. data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
  353. data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
  354. data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
  355. data/src/nginx/src/os/unix/ngx_thread.h +128 -0
  356. data/src/nginx/src/os/unix/ngx_time.c +104 -0
  357. data/src/nginx/src/os/unix/ngx_time.h +66 -0
  358. data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
  359. data/src/nginx/src/os/unix/ngx_user.c +109 -0
  360. data/src/nginx/src/os/unix/ngx_user.h +24 -0
  361. data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
  362. data/src/nginx/src/os/unix/rfork_thread.S +73 -0
  363. metadata +419 -0
@@ -0,0 +1,87 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_PROCESS_H_INCLUDED_
9
+ #define _NGX_PROCESS_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_setproctitle.h>
13
+
14
+
15
+ typedef pid_t ngx_pid_t;
16
+
17
+ #define NGX_INVALID_PID -1
18
+
19
+ typedef void (*ngx_spawn_proc_pt) (ngx_cycle_t *cycle, void *data);
20
+
21
+ typedef struct {
22
+ ngx_pid_t pid;
23
+ int status;
24
+ ngx_socket_t channel[2];
25
+
26
+ ngx_spawn_proc_pt proc;
27
+ void *data;
28
+ char *name;
29
+
30
+ unsigned respawn:1;
31
+ unsigned just_spawn:1;
32
+ unsigned detached:1;
33
+ unsigned exiting:1;
34
+ unsigned exited:1;
35
+ } ngx_process_t;
36
+
37
+
38
+ typedef struct {
39
+ char *path;
40
+ char *name;
41
+ char *const *argv;
42
+ char *const *envp;
43
+ } ngx_exec_ctx_t;
44
+
45
+
46
+ #define NGX_MAX_PROCESSES 1024
47
+
48
+ #define NGX_PROCESS_NORESPAWN -1
49
+ #define NGX_PROCESS_JUST_SPAWN -2
50
+ #define NGX_PROCESS_RESPAWN -3
51
+ #define NGX_PROCESS_JUST_RESPAWN -4
52
+ #define NGX_PROCESS_DETACHED -5
53
+
54
+
55
+ #define ngx_getpid getpid
56
+
57
+ #ifndef ngx_log_pid
58
+ #define ngx_log_pid ngx_pid
59
+ #endif
60
+
61
+
62
+ ngx_pid_t ngx_spawn_process(ngx_cycle_t *cycle,
63
+ ngx_spawn_proc_pt proc, void *data, char *name, ngx_int_t respawn);
64
+ ngx_pid_t ngx_execute(ngx_cycle_t *cycle, ngx_exec_ctx_t *ctx);
65
+ ngx_int_t ngx_init_signals(ngx_log_t *log);
66
+ void ngx_debug_point(void);
67
+
68
+
69
+ #if (NGX_HAVE_SCHED_YIELD)
70
+ #define ngx_sched_yield() sched_yield()
71
+ #else
72
+ #define ngx_sched_yield() usleep(1)
73
+ #endif
74
+
75
+
76
+ extern int ngx_argc;
77
+ extern char **ngx_argv;
78
+ extern char **ngx_os_argv;
79
+
80
+ extern ngx_pid_t ngx_pid;
81
+ extern ngx_socket_t ngx_channel;
82
+ extern ngx_int_t ngx_process_slot;
83
+ extern ngx_int_t ngx_last_process;
84
+ extern ngx_process_t ngx_processes[NGX_MAX_PROCESSES];
85
+
86
+
87
+ #endif /* _NGX_PROCESS_H_INCLUDED_ */
@@ -0,0 +1,1390 @@
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_event.h>
11
+ #include <ngx_channel.h>
12
+
13
+
14
+ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n,
15
+ ngx_int_t type);
16
+ static void ngx_start_cache_manager_processes(ngx_cycle_t *cycle,
17
+ ngx_uint_t respawn);
18
+ static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch);
19
+ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
20
+ static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
21
+ static void ngx_master_process_exit(ngx_cycle_t *cycle);
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);
24
+ static void ngx_worker_process_exit(ngx_cycle_t *cycle);
25
+ static void ngx_channel_handler(ngx_event_t *ev);
26
+ #if (NGX_THREADS)
27
+ static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
28
+ static ngx_thread_value_t ngx_worker_thread_cycle(void *data);
29
+ #endif
30
+ static void ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data);
31
+ static void ngx_cache_manager_process_handler(ngx_event_t *ev);
32
+ static void ngx_cache_loader_process_handler(ngx_event_t *ev);
33
+
34
+
35
+ ngx_uint_t ngx_process;
36
+ ngx_pid_t ngx_pid;
37
+ ngx_uint_t ngx_threaded;
38
+
39
+ sig_atomic_t ngx_reap;
40
+ sig_atomic_t ngx_sigio;
41
+ sig_atomic_t ngx_sigalrm;
42
+ sig_atomic_t ngx_terminate;
43
+ sig_atomic_t ngx_quit;
44
+ sig_atomic_t ngx_debug_quit;
45
+ ngx_uint_t ngx_exiting;
46
+ sig_atomic_t ngx_reconfigure;
47
+ sig_atomic_t ngx_reopen;
48
+
49
+ sig_atomic_t ngx_change_binary;
50
+ ngx_pid_t ngx_new_binary;
51
+ ngx_uint_t ngx_inherited;
52
+ ngx_uint_t ngx_daemonized;
53
+
54
+ sig_atomic_t ngx_noaccept;
55
+ ngx_uint_t ngx_noaccepting;
56
+ ngx_uint_t ngx_restart;
57
+
58
+
59
+ #if (NGX_THREADS)
60
+ volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
61
+ ngx_int_t ngx_threads_n;
62
+ #endif
63
+
64
+
65
+ u_long cpu_affinity;
66
+ static u_char master_process[] = "master process";
67
+
68
+
69
+ static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = {
70
+ ngx_cache_manager_process_handler, "cache manager process", 0
71
+ };
72
+
73
+ static ngx_cache_manager_ctx_t ngx_cache_loader_ctx = {
74
+ ngx_cache_loader_process_handler, "cache loader process", 60000
75
+ };
76
+
77
+
78
+ static ngx_cycle_t ngx_exit_cycle;
79
+ static ngx_log_t ngx_exit_log;
80
+ static ngx_open_file_t ngx_exit_log_file;
81
+
82
+
83
+ void
84
+ ngx_master_process_cycle(ngx_cycle_t *cycle)
85
+ {
86
+ char *title;
87
+ u_char *p;
88
+ size_t size;
89
+ ngx_int_t i;
90
+ ngx_uint_t n, sigio;
91
+ sigset_t set;
92
+ struct itimerval itv;
93
+ ngx_uint_t live;
94
+ ngx_msec_t delay;
95
+ ngx_listening_t *ls;
96
+ ngx_core_conf_t *ccf;
97
+
98
+ sigemptyset(&set);
99
+ sigaddset(&set, SIGCHLD);
100
+ sigaddset(&set, SIGALRM);
101
+ sigaddset(&set, SIGIO);
102
+ sigaddset(&set, SIGINT);
103
+ sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
104
+ sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
105
+ sigaddset(&set, ngx_signal_value(NGX_NOACCEPT_SIGNAL));
106
+ sigaddset(&set, ngx_signal_value(NGX_TERMINATE_SIGNAL));
107
+ sigaddset(&set, ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
108
+ sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
109
+
110
+ if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
111
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
112
+ "sigprocmask() failed");
113
+ }
114
+
115
+ sigemptyset(&set);
116
+
117
+
118
+ size = sizeof(master_process);
119
+
120
+ for (i = 0; i < ngx_argc; i++) {
121
+ size += ngx_strlen(ngx_argv[i]) + 1;
122
+ }
123
+
124
+ title = ngx_pnalloc(cycle->pool, size);
125
+
126
+ p = ngx_cpymem(title, master_process, sizeof(master_process) - 1);
127
+ for (i = 0; i < ngx_argc; i++) {
128
+ *p++ = ' ';
129
+ p = ngx_cpystrn(p, (u_char *) ngx_argv[i], size);
130
+ }
131
+
132
+ ngx_setproctitle(title);
133
+
134
+
135
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
136
+
137
+ ngx_start_worker_processes(cycle, ccf->worker_processes,
138
+ NGX_PROCESS_RESPAWN);
139
+ ngx_start_cache_manager_processes(cycle, 0);
140
+
141
+ ngx_new_binary = 0;
142
+ delay = 0;
143
+ sigio = 0;
144
+ live = 1;
145
+
146
+ for ( ;; ) {
147
+ if (delay) {
148
+ if (ngx_sigalrm) {
149
+ sigio = 0;
150
+ delay *= 2;
151
+ ngx_sigalrm = 0;
152
+ }
153
+
154
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
155
+ "termination cycle: %d", delay);
156
+
157
+ itv.it_interval.tv_sec = 0;
158
+ itv.it_interval.tv_usec = 0;
159
+ itv.it_value.tv_sec = delay / 1000;
160
+ itv.it_value.tv_usec = (delay % 1000 ) * 1000;
161
+
162
+ if (setitimer(ITIMER_REAL, &itv, NULL) == -1) {
163
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
164
+ "setitimer() failed");
165
+ }
166
+ }
167
+
168
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "sigsuspend");
169
+
170
+ sigsuspend(&set);
171
+
172
+ ngx_time_update();
173
+
174
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
175
+ "wake up, sigio %i", sigio);
176
+
177
+ if (ngx_reap) {
178
+ ngx_reap = 0;
179
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "reap children");
180
+
181
+ live = ngx_reap_children(cycle);
182
+ }
183
+
184
+ if (!live && (ngx_terminate || ngx_quit)) {
185
+ ngx_master_process_exit(cycle);
186
+ }
187
+
188
+ if (ngx_terminate) {
189
+ if (delay == 0) {
190
+ delay = 50;
191
+ }
192
+
193
+ if (sigio) {
194
+ sigio--;
195
+ continue;
196
+ }
197
+
198
+ sigio = ccf->worker_processes + 2 /* cache processes */;
199
+
200
+ if (delay > 1000) {
201
+ ngx_signal_worker_processes(cycle, SIGKILL);
202
+ } else {
203
+ ngx_signal_worker_processes(cycle,
204
+ ngx_signal_value(NGX_TERMINATE_SIGNAL));
205
+ }
206
+
207
+ continue;
208
+ }
209
+
210
+ if (ngx_quit) {
211
+ ngx_signal_worker_processes(cycle,
212
+ ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
213
+
214
+ ls = cycle->listening.elts;
215
+ for (n = 0; n < cycle->listening.nelts; n++) {
216
+ if (ngx_close_socket(ls[n].fd) == -1) {
217
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
218
+ ngx_close_socket_n " %V failed",
219
+ &ls[n].addr_text);
220
+ }
221
+ }
222
+ cycle->listening.nelts = 0;
223
+
224
+ continue;
225
+ }
226
+
227
+ if (ngx_reconfigure) {
228
+ ngx_reconfigure = 0;
229
+
230
+ if (ngx_new_binary) {
231
+ ngx_start_worker_processes(cycle, ccf->worker_processes,
232
+ NGX_PROCESS_RESPAWN);
233
+ ngx_start_cache_manager_processes(cycle, 0);
234
+ ngx_noaccepting = 0;
235
+
236
+ continue;
237
+ }
238
+
239
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring");
240
+
241
+ cycle = ngx_init_cycle(cycle);
242
+ if (cycle == NULL) {
243
+ cycle = (ngx_cycle_t *) ngx_cycle;
244
+ continue;
245
+ }
246
+
247
+ ngx_cycle = cycle;
248
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
249
+ ngx_core_module);
250
+ ngx_start_worker_processes(cycle, ccf->worker_processes,
251
+ NGX_PROCESS_JUST_RESPAWN);
252
+ ngx_start_cache_manager_processes(cycle, 1);
253
+ live = 1;
254
+ ngx_signal_worker_processes(cycle,
255
+ ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
256
+ }
257
+
258
+ if (ngx_restart) {
259
+ ngx_restart = 0;
260
+ ngx_start_worker_processes(cycle, ccf->worker_processes,
261
+ NGX_PROCESS_RESPAWN);
262
+ ngx_start_cache_manager_processes(cycle, 0);
263
+ live = 1;
264
+ }
265
+
266
+ if (ngx_reopen) {
267
+ ngx_reopen = 0;
268
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
269
+ ngx_reopen_files(cycle, ccf->user);
270
+ ngx_signal_worker_processes(cycle,
271
+ ngx_signal_value(NGX_REOPEN_SIGNAL));
272
+ }
273
+
274
+ if (ngx_change_binary) {
275
+ ngx_change_binary = 0;
276
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "changing binary");
277
+ ngx_new_binary = ngx_exec_new_binary(cycle, ngx_argv);
278
+ }
279
+
280
+ if (ngx_noaccept) {
281
+ ngx_noaccept = 0;
282
+ ngx_noaccepting = 1;
283
+ ngx_signal_worker_processes(cycle,
284
+ ngx_signal_value(NGX_SHUTDOWN_SIGNAL));
285
+ }
286
+ }
287
+ }
288
+
289
+
290
+ void
291
+ ngx_single_process_cycle(ngx_cycle_t *cycle)
292
+ {
293
+ ngx_uint_t i;
294
+
295
+ if (ngx_set_environment(cycle, NULL) == NULL) {
296
+ /* fatal */
297
+ exit(2);
298
+ }
299
+
300
+ for (i = 0; ngx_modules[i]; i++) {
301
+ if (ngx_modules[i]->init_process) {
302
+ if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
303
+ /* fatal */
304
+ exit(2);
305
+ }
306
+ }
307
+ }
308
+
309
+ for ( ;; ) {
310
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
311
+
312
+ ngx_process_events_and_timers(cycle);
313
+
314
+ if (ngx_terminate || ngx_quit) {
315
+
316
+ for (i = 0; ngx_modules[i]; i++) {
317
+ if (ngx_modules[i]->exit_process) {
318
+ ngx_modules[i]->exit_process(cycle);
319
+ }
320
+ }
321
+
322
+ ngx_master_process_exit(cycle);
323
+ }
324
+
325
+ if (ngx_reconfigure) {
326
+ ngx_reconfigure = 0;
327
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reconfiguring");
328
+
329
+ cycle = ngx_init_cycle(cycle);
330
+ if (cycle == NULL) {
331
+ cycle = (ngx_cycle_t *) ngx_cycle;
332
+ continue;
333
+ }
334
+
335
+ ngx_cycle = cycle;
336
+ }
337
+
338
+ if (ngx_reopen) {
339
+ ngx_reopen = 0;
340
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
341
+ ngx_reopen_files(cycle, (ngx_uid_t) -1);
342
+ }
343
+ }
344
+ }
345
+
346
+
347
+ static void
348
+ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
349
+ {
350
+ ngx_int_t i;
351
+ ngx_channel_t ch;
352
+
353
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start worker processes");
354
+
355
+ ch.command = NGX_CMD_OPEN_CHANNEL;
356
+
357
+ for (i = 0; i < n; i++) {
358
+
359
+ cpu_affinity = ngx_get_cpu_affinity(i);
360
+
361
+ ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
362
+ "worker process", type);
363
+
364
+ ch.pid = ngx_processes[ngx_process_slot].pid;
365
+ ch.slot = ngx_process_slot;
366
+ ch.fd = ngx_processes[ngx_process_slot].channel[0];
367
+
368
+ ngx_pass_open_channel(cycle, &ch);
369
+ }
370
+ }
371
+
372
+
373
+ static void
374
+ ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn)
375
+ {
376
+ ngx_uint_t i, manager, loader;
377
+ ngx_path_t **path;
378
+ ngx_channel_t ch;
379
+
380
+ manager = 0;
381
+ loader = 0;
382
+
383
+ path = ngx_cycle->pathes.elts;
384
+ for (i = 0; i < ngx_cycle->pathes.nelts; i++) {
385
+
386
+ if (path[i]->manager) {
387
+ manager = 1;
388
+ }
389
+
390
+ if (path[i]->loader) {
391
+ loader = 1;
392
+ }
393
+ }
394
+
395
+ if (manager == 0) {
396
+ return;
397
+ }
398
+
399
+ ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
400
+ &ngx_cache_manager_ctx, "cache manager process",
401
+ respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN);
402
+
403
+ ch.command = NGX_CMD_OPEN_CHANNEL;
404
+ ch.pid = ngx_processes[ngx_process_slot].pid;
405
+ ch.slot = ngx_process_slot;
406
+ ch.fd = ngx_processes[ngx_process_slot].channel[0];
407
+
408
+ ngx_pass_open_channel(cycle, &ch);
409
+
410
+ if (loader == 0) {
411
+ return;
412
+ }
413
+
414
+ ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
415
+ &ngx_cache_loader_ctx, "cache loader process",
416
+ respawn ? NGX_PROCESS_JUST_SPAWN : NGX_PROCESS_NORESPAWN);
417
+
418
+ ch.command = NGX_CMD_OPEN_CHANNEL;
419
+ ch.pid = ngx_processes[ngx_process_slot].pid;
420
+ ch.slot = ngx_process_slot;
421
+ ch.fd = ngx_processes[ngx_process_slot].channel[0];
422
+
423
+ ngx_pass_open_channel(cycle, &ch);
424
+ }
425
+
426
+
427
+ static void
428
+ ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch)
429
+ {
430
+ ngx_int_t i;
431
+
432
+ for (i = 0; i < ngx_last_process; i++) {
433
+
434
+ if (i == ngx_process_slot
435
+ || ngx_processes[i].pid == -1
436
+ || ngx_processes[i].channel[0] == -1)
437
+ {
438
+ continue;
439
+ }
440
+
441
+ ngx_log_debug6(NGX_LOG_DEBUG_CORE, cycle->log, 0,
442
+ "pass channel s:%d pid:%P fd:%d to s:%i pid:%P fd:%d",
443
+ ch->slot, ch->pid, ch->fd,
444
+ i, ngx_processes[i].pid,
445
+ ngx_processes[i].channel[0]);
446
+
447
+ /* TODO: NGX_AGAIN */
448
+
449
+ ngx_write_channel(ngx_processes[i].channel[0],
450
+ ch, sizeof(ngx_channel_t), cycle->log);
451
+ }
452
+ }
453
+
454
+
455
+ static void
456
+ ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo)
457
+ {
458
+ ngx_int_t i;
459
+ ngx_err_t err;
460
+ ngx_channel_t ch;
461
+
462
+ #if (NGX_BROKEN_SCM_RIGHTS)
463
+
464
+ ch.command = 0;
465
+
466
+ #else
467
+
468
+ switch (signo) {
469
+
470
+ case ngx_signal_value(NGX_SHUTDOWN_SIGNAL):
471
+ ch.command = NGX_CMD_QUIT;
472
+ break;
473
+
474
+ case ngx_signal_value(NGX_TERMINATE_SIGNAL):
475
+ ch.command = NGX_CMD_TERMINATE;
476
+ break;
477
+
478
+ case ngx_signal_value(NGX_REOPEN_SIGNAL):
479
+ ch.command = NGX_CMD_REOPEN;
480
+ break;
481
+
482
+ default:
483
+ ch.command = 0;
484
+ }
485
+
486
+ #endif
487
+
488
+ ch.fd = -1;
489
+
490
+
491
+ for (i = 0; i < ngx_last_process; i++) {
492
+
493
+ ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
494
+ "child: %d %P e:%d t:%d d:%d r:%d j:%d",
495
+ i,
496
+ ngx_processes[i].pid,
497
+ ngx_processes[i].exiting,
498
+ ngx_processes[i].exited,
499
+ ngx_processes[i].detached,
500
+ ngx_processes[i].respawn,
501
+ ngx_processes[i].just_spawn);
502
+
503
+ if (ngx_processes[i].detached || ngx_processes[i].pid == -1) {
504
+ continue;
505
+ }
506
+
507
+ if (ngx_processes[i].just_spawn) {
508
+ ngx_processes[i].just_spawn = 0;
509
+ continue;
510
+ }
511
+
512
+ if (ngx_processes[i].exiting
513
+ && signo == ngx_signal_value(NGX_SHUTDOWN_SIGNAL))
514
+ {
515
+ continue;
516
+ }
517
+
518
+ if (ch.command) {
519
+ if (ngx_write_channel(ngx_processes[i].channel[0],
520
+ &ch, sizeof(ngx_channel_t), cycle->log)
521
+ == NGX_OK)
522
+ {
523
+ if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
524
+ ngx_processes[i].exiting = 1;
525
+ }
526
+
527
+ continue;
528
+ }
529
+ }
530
+
531
+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
532
+ "kill (%P, %d)" , ngx_processes[i].pid, signo);
533
+
534
+ if (kill(ngx_processes[i].pid, signo) == -1) {
535
+ err = ngx_errno;
536
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
537
+ "kill(%P, %d) failed", ngx_processes[i].pid, signo);
538
+
539
+ if (err == NGX_ESRCH) {
540
+ ngx_processes[i].exited = 1;
541
+ ngx_processes[i].exiting = 0;
542
+ ngx_reap = 1;
543
+ }
544
+
545
+ continue;
546
+ }
547
+
548
+ if (signo != ngx_signal_value(NGX_REOPEN_SIGNAL)) {
549
+ ngx_processes[i].exiting = 1;
550
+ }
551
+ }
552
+ }
553
+
554
+
555
+ static ngx_uint_t
556
+ ngx_reap_children(ngx_cycle_t *cycle)
557
+ {
558
+ ngx_int_t i, n;
559
+ ngx_uint_t live;
560
+ ngx_channel_t ch;
561
+ ngx_core_conf_t *ccf;
562
+
563
+ ch.command = NGX_CMD_CLOSE_CHANNEL;
564
+ ch.fd = -1;
565
+
566
+ live = 0;
567
+ for (i = 0; i < ngx_last_process; i++) {
568
+
569
+ ngx_log_debug7(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
570
+ "child: %d %P e:%d t:%d d:%d r:%d j:%d",
571
+ i,
572
+ ngx_processes[i].pid,
573
+ ngx_processes[i].exiting,
574
+ ngx_processes[i].exited,
575
+ ngx_processes[i].detached,
576
+ ngx_processes[i].respawn,
577
+ ngx_processes[i].just_spawn);
578
+
579
+ if (ngx_processes[i].pid == -1) {
580
+ continue;
581
+ }
582
+
583
+ if (ngx_processes[i].exited) {
584
+
585
+ if (!ngx_processes[i].detached) {
586
+ ngx_close_channel(ngx_processes[i].channel, cycle->log);
587
+
588
+ ngx_processes[i].channel[0] = -1;
589
+ ngx_processes[i].channel[1] = -1;
590
+
591
+ ch.pid = ngx_processes[i].pid;
592
+ ch.slot = i;
593
+
594
+ for (n = 0; n < ngx_last_process; n++) {
595
+ if (ngx_processes[n].exited
596
+ || ngx_processes[n].pid == -1
597
+ || ngx_processes[n].channel[0] == -1)
598
+ {
599
+ continue;
600
+ }
601
+
602
+ ngx_log_debug3(NGX_LOG_DEBUG_CORE, cycle->log, 0,
603
+ "pass close channel s:%i pid:%P to:%P",
604
+ ch.slot, ch.pid, ngx_processes[n].pid);
605
+
606
+ /* TODO: NGX_AGAIN */
607
+
608
+ ngx_write_channel(ngx_processes[n].channel[0],
609
+ &ch, sizeof(ngx_channel_t), cycle->log);
610
+ }
611
+ }
612
+
613
+ if (ngx_processes[i].respawn
614
+ && !ngx_processes[i].exiting
615
+ && !ngx_terminate
616
+ && !ngx_quit)
617
+ {
618
+ if (ngx_spawn_process(cycle, ngx_processes[i].proc,
619
+ ngx_processes[i].data,
620
+ ngx_processes[i].name, i)
621
+ == NGX_INVALID_PID)
622
+ {
623
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
624
+ "could not respawn %s",
625
+ ngx_processes[i].name);
626
+ continue;
627
+ }
628
+
629
+
630
+ ch.command = NGX_CMD_OPEN_CHANNEL;
631
+ ch.pid = ngx_processes[ngx_process_slot].pid;
632
+ ch.slot = ngx_process_slot;
633
+ ch.fd = ngx_processes[ngx_process_slot].channel[0];
634
+
635
+ ngx_pass_open_channel(cycle, &ch);
636
+
637
+ live = 1;
638
+
639
+ continue;
640
+ }
641
+
642
+ if (ngx_processes[i].pid == ngx_new_binary) {
643
+
644
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
645
+ ngx_core_module);
646
+
647
+ if (ngx_rename_file((char *) ccf->oldpid.data,
648
+ (char *) ccf->pid.data)
649
+ != NGX_OK)
650
+ {
651
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
652
+ ngx_rename_file_n " %s back to %s failed "
653
+ "after the new binary process \"%s\" exited",
654
+ ccf->oldpid.data, ccf->pid.data, ngx_argv[0]);
655
+ }
656
+
657
+ ngx_new_binary = 0;
658
+ if (ngx_noaccepting) {
659
+ ngx_restart = 1;
660
+ ngx_noaccepting = 0;
661
+ }
662
+ }
663
+
664
+ if (i == ngx_last_process - 1) {
665
+ ngx_last_process--;
666
+
667
+ } else {
668
+ ngx_processes[i].pid = -1;
669
+ }
670
+
671
+ } else if (ngx_processes[i].exiting || !ngx_processes[i].detached) {
672
+ live = 1;
673
+ }
674
+ }
675
+
676
+ return live;
677
+ }
678
+
679
+
680
+ static void
681
+ ngx_master_process_exit(ngx_cycle_t *cycle)
682
+ {
683
+ ngx_uint_t i;
684
+
685
+ ngx_delete_pidfile(cycle);
686
+
687
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exit");
688
+
689
+ for (i = 0; ngx_modules[i]; i++) {
690
+ if (ngx_modules[i]->exit_master) {
691
+ ngx_modules[i]->exit_master(cycle);
692
+ }
693
+ }
694
+
695
+ ngx_close_listening_sockets(cycle);
696
+
697
+ /*
698
+ * Copy ngx_cycle->log related data to the special static exit cycle,
699
+ * log, and log file structures enough to allow a signal handler to log.
700
+ * The handler may be called when standard ngx_cycle->log allocated from
701
+ * ngx_cycle->pool is already destroyed.
702
+ */
703
+
704
+ ngx_exit_log_file.fd = ngx_cycle->log->file->fd;
705
+
706
+ ngx_exit_log = *ngx_cycle->log;
707
+ ngx_exit_log.file = &ngx_exit_log_file;
708
+
709
+ ngx_exit_cycle.log = &ngx_exit_log;
710
+ ngx_cycle = &ngx_exit_cycle;
711
+
712
+ ngx_destroy_pool(cycle->pool);
713
+
714
+ exit(0);
715
+ }
716
+
717
+
718
+ static void
719
+ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
720
+ {
721
+ ngx_uint_t i;
722
+ ngx_connection_t *c;
723
+
724
+ ngx_process = NGX_PROCESS_WORKER;
725
+
726
+ ngx_worker_process_init(cycle, 1);
727
+
728
+ ngx_setproctitle("worker process");
729
+
730
+ #if (NGX_THREADS)
731
+ {
732
+ ngx_int_t n;
733
+ ngx_err_t err;
734
+ ngx_core_conf_t *ccf;
735
+
736
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
737
+
738
+ if (ngx_threads_n) {
739
+ if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle)
740
+ == NGX_ERROR)
741
+ {
742
+ /* fatal */
743
+ exit(2);
744
+ }
745
+
746
+ err = ngx_thread_key_create(&ngx_core_tls_key);
747
+ if (err != 0) {
748
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
749
+ ngx_thread_key_create_n " failed");
750
+ /* fatal */
751
+ exit(2);
752
+ }
753
+
754
+ for (n = 0; n < ngx_threads_n; n++) {
755
+
756
+ ngx_threads[n].cv = ngx_cond_init(cycle->log);
757
+
758
+ if (ngx_threads[n].cv == NULL) {
759
+ /* fatal */
760
+ exit(2);
761
+ }
762
+
763
+ if (ngx_create_thread((ngx_tid_t *) &ngx_threads[n].tid,
764
+ ngx_worker_thread_cycle,
765
+ (void *) &ngx_threads[n], cycle->log)
766
+ != 0)
767
+ {
768
+ /* fatal */
769
+ exit(2);
770
+ }
771
+ }
772
+ }
773
+ }
774
+ #endif
775
+
776
+ for ( ;; ) {
777
+
778
+ if (ngx_exiting) {
779
+
780
+ c = cycle->connections;
781
+
782
+ for (i = 0; i < cycle->connection_n; i++) {
783
+
784
+ /* THREAD: lock */
785
+
786
+ if (c[i].fd != -1 && c[i].idle) {
787
+ c[i].close = 1;
788
+ c[i].read->handler(c[i].read);
789
+ }
790
+ }
791
+
792
+ if (ngx_event_timer_rbtree.root == ngx_event_timer_rbtree.sentinel)
793
+ {
794
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
795
+
796
+ ngx_worker_process_exit(cycle);
797
+ }
798
+ }
799
+
800
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
801
+
802
+ ngx_process_events_and_timers(cycle);
803
+
804
+ if (ngx_terminate) {
805
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
806
+
807
+ ngx_worker_process_exit(cycle);
808
+ }
809
+
810
+ if (ngx_quit) {
811
+ ngx_quit = 0;
812
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
813
+ "gracefully shutting down");
814
+ ngx_setproctitle("worker process is shutting down");
815
+
816
+ if (!ngx_exiting) {
817
+ ngx_close_listening_sockets(cycle);
818
+ ngx_exiting = 1;
819
+ }
820
+ }
821
+
822
+ if (ngx_reopen) {
823
+ ngx_reopen = 0;
824
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
825
+ ngx_reopen_files(cycle, -1);
826
+ }
827
+ }
828
+ }
829
+
830
+
831
+ static void
832
+ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
833
+ {
834
+ sigset_t set;
835
+ ngx_int_t n;
836
+ ngx_uint_t i;
837
+ struct rlimit rlmt;
838
+ ngx_core_conf_t *ccf;
839
+ ngx_listening_t *ls;
840
+
841
+ if (ngx_set_environment(cycle, NULL) == NULL) {
842
+ /* fatal */
843
+ exit(2);
844
+ }
845
+
846
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
847
+
848
+ if (priority && ccf->priority != 0) {
849
+ if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
850
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
851
+ "setpriority(%d) failed", ccf->priority);
852
+ }
853
+ }
854
+
855
+ if (ccf->rlimit_nofile != NGX_CONF_UNSET) {
856
+ rlmt.rlim_cur = (rlim_t) ccf->rlimit_nofile;
857
+ rlmt.rlim_max = (rlim_t) ccf->rlimit_nofile;
858
+
859
+ if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
860
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
861
+ "setrlimit(RLIMIT_NOFILE, %i) failed",
862
+ ccf->rlimit_nofile);
863
+ }
864
+ }
865
+
866
+ if (ccf->rlimit_core != NGX_CONF_UNSET) {
867
+ rlmt.rlim_cur = (rlim_t) ccf->rlimit_core;
868
+ rlmt.rlim_max = (rlim_t) ccf->rlimit_core;
869
+
870
+ if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
871
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
872
+ "setrlimit(RLIMIT_CORE, %O) failed",
873
+ ccf->rlimit_core);
874
+ }
875
+ }
876
+
877
+ #ifdef RLIMIT_SIGPENDING
878
+ if (ccf->rlimit_sigpending != NGX_CONF_UNSET) {
879
+ rlmt.rlim_cur = (rlim_t) ccf->rlimit_sigpending;
880
+ rlmt.rlim_max = (rlim_t) ccf->rlimit_sigpending;
881
+
882
+ if (setrlimit(RLIMIT_SIGPENDING, &rlmt) == -1) {
883
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
884
+ "setrlimit(RLIMIT_SIGPENDING, %i) failed",
885
+ ccf->rlimit_sigpending);
886
+ }
887
+ }
888
+ #endif
889
+
890
+ if (geteuid() == 0) {
891
+ if (setgid(ccf->group) == -1) {
892
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
893
+ "setgid(%d) failed", ccf->group);
894
+ /* fatal */
895
+ exit(2);
896
+ }
897
+
898
+ if (initgroups(ccf->username, ccf->group) == -1) {
899
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
900
+ "initgroups(%s, %d) failed",
901
+ ccf->username, ccf->group);
902
+ }
903
+
904
+ if (setuid(ccf->user) == -1) {
905
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
906
+ "setuid(%d) failed", ccf->user);
907
+ /* fatal */
908
+ exit(2);
909
+ }
910
+ }
911
+
912
+ #if (NGX_HAVE_SCHED_SETAFFINITY)
913
+
914
+ 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
+ }
925
+ }
926
+
927
+ #endif
928
+
929
+ #if (NGX_HAVE_PR_SET_DUMPABLE)
930
+
931
+ /* allow coredump after setuid() in Linux 2.4.x */
932
+
933
+ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
934
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
935
+ "prctl(PR_SET_DUMPABLE) failed");
936
+ }
937
+
938
+ #endif
939
+
940
+ if (ccf->working_directory.len) {
941
+ if (chdir((char *) ccf->working_directory.data) == -1) {
942
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
943
+ "chdir(\"%s\") failed", ccf->working_directory.data);
944
+ /* fatal */
945
+ exit(2);
946
+ }
947
+ }
948
+
949
+ sigemptyset(&set);
950
+
951
+ if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
952
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
953
+ "sigprocmask() failed");
954
+ }
955
+
956
+ /*
957
+ * disable deleting previous events for the listening sockets because
958
+ * in the worker processes there are no events at all at this point
959
+ */
960
+ ls = cycle->listening.elts;
961
+ for (i = 0; i < cycle->listening.nelts; i++) {
962
+ ls[i].previous = NULL;
963
+ }
964
+
965
+ for (i = 0; ngx_modules[i]; i++) {
966
+ if (ngx_modules[i]->init_process) {
967
+ if (ngx_modules[i]->init_process(cycle) == NGX_ERROR) {
968
+ /* fatal */
969
+ exit(2);
970
+ }
971
+ }
972
+ }
973
+
974
+ for (n = 0; n < ngx_last_process; n++) {
975
+
976
+ if (ngx_processes[n].pid == -1) {
977
+ continue;
978
+ }
979
+
980
+ if (n == ngx_process_slot) {
981
+ continue;
982
+ }
983
+
984
+ if (ngx_processes[n].channel[1] == -1) {
985
+ continue;
986
+ }
987
+
988
+ if (close(ngx_processes[n].channel[1]) == -1) {
989
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
990
+ "close() channel failed");
991
+ }
992
+ }
993
+
994
+ if (close(ngx_processes[ngx_process_slot].channel[0]) == -1) {
995
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
996
+ "close() channel failed");
997
+ }
998
+
999
+ #if 0
1000
+ ngx_last_process = 0;
1001
+ #endif
1002
+
1003
+ if (ngx_add_channel_event(cycle, ngx_channel, NGX_READ_EVENT,
1004
+ ngx_channel_handler)
1005
+ == NGX_ERROR)
1006
+ {
1007
+ /* fatal */
1008
+ exit(2);
1009
+ }
1010
+ }
1011
+
1012
+
1013
+ static void
1014
+ ngx_worker_process_exit(ngx_cycle_t *cycle)
1015
+ {
1016
+ ngx_uint_t i;
1017
+ ngx_connection_t *c;
1018
+
1019
+ #if (NGX_THREADS)
1020
+ ngx_terminate = 1;
1021
+
1022
+ ngx_wakeup_worker_threads(cycle);
1023
+ #endif
1024
+
1025
+ for (i = 0; ngx_modules[i]; i++) {
1026
+ if (ngx_modules[i]->exit_process) {
1027
+ ngx_modules[i]->exit_process(cycle);
1028
+ }
1029
+ }
1030
+
1031
+ if (ngx_exiting) {
1032
+ c = cycle->connections;
1033
+ for (i = 0; i < cycle->connection_n; i++) {
1034
+ if (c[i].fd != -1
1035
+ && c[i].read
1036
+ && !c[i].read->accept
1037
+ && !c[i].read->channel
1038
+ && !c[i].read->resolver)
1039
+ {
1040
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
1041
+ "open socket #%d left in connection %ui",
1042
+ c[i].fd, i);
1043
+ ngx_debug_quit = 1;
1044
+ }
1045
+ }
1046
+
1047
+ if (ngx_debug_quit) {
1048
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "aborting");
1049
+ ngx_debug_point();
1050
+ }
1051
+ }
1052
+
1053
+ /*
1054
+ * Copy ngx_cycle->log related data to the special static exit cycle,
1055
+ * log, and log file structures enough to allow a signal handler to log.
1056
+ * The handler may be called when standard ngx_cycle->log allocated from
1057
+ * ngx_cycle->pool is already destroyed.
1058
+ */
1059
+
1060
+ ngx_exit_log_file.fd = ngx_cycle->log->file->fd;
1061
+
1062
+ ngx_exit_log = *ngx_cycle->log;
1063
+ ngx_exit_log.file = &ngx_exit_log_file;
1064
+
1065
+ ngx_exit_cycle.log = &ngx_exit_log;
1066
+ ngx_cycle = &ngx_exit_cycle;
1067
+
1068
+ ngx_destroy_pool(cycle->pool);
1069
+
1070
+ ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, "exit");
1071
+
1072
+ exit(0);
1073
+ }
1074
+
1075
+
1076
+ static void
1077
+ ngx_channel_handler(ngx_event_t *ev)
1078
+ {
1079
+ ngx_int_t n;
1080
+ ngx_channel_t ch;
1081
+ ngx_connection_t *c;
1082
+
1083
+ if (ev->timedout) {
1084
+ ev->timedout = 0;
1085
+ return;
1086
+ }
1087
+
1088
+ c = ev->data;
1089
+
1090
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel handler");
1091
+
1092
+ for ( ;; ) {
1093
+
1094
+ n = ngx_read_channel(c->fd, &ch, sizeof(ngx_channel_t), ev->log);
1095
+
1096
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "channel: %i", n);
1097
+
1098
+ if (n == NGX_ERROR) {
1099
+
1100
+ if (ngx_event_flags & NGX_USE_EPOLL_EVENT) {
1101
+ ngx_del_conn(c, 0);
1102
+ }
1103
+
1104
+ ngx_close_connection(c);
1105
+ return;
1106
+ }
1107
+
1108
+ if (ngx_event_flags & NGX_USE_EVENTPORT_EVENT) {
1109
+ if (ngx_add_event(ev, NGX_READ_EVENT, 0) == NGX_ERROR) {
1110
+ return;
1111
+ }
1112
+ }
1113
+
1114
+ if (n == NGX_AGAIN) {
1115
+ return;
1116
+ }
1117
+
1118
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0,
1119
+ "channel command: %d", ch.command);
1120
+
1121
+ switch (ch.command) {
1122
+
1123
+ case NGX_CMD_QUIT:
1124
+ ngx_quit = 1;
1125
+ break;
1126
+
1127
+ case NGX_CMD_TERMINATE:
1128
+ ngx_terminate = 1;
1129
+ break;
1130
+
1131
+ case NGX_CMD_REOPEN:
1132
+ ngx_reopen = 1;
1133
+ break;
1134
+
1135
+ case NGX_CMD_OPEN_CHANNEL:
1136
+
1137
+ ngx_log_debug3(NGX_LOG_DEBUG_CORE, ev->log, 0,
1138
+ "get channel s:%i pid:%P fd:%d",
1139
+ ch.slot, ch.pid, ch.fd);
1140
+
1141
+ ngx_processes[ch.slot].pid = ch.pid;
1142
+ ngx_processes[ch.slot].channel[0] = ch.fd;
1143
+ break;
1144
+
1145
+ case NGX_CMD_CLOSE_CHANNEL:
1146
+
1147
+ ngx_log_debug4(NGX_LOG_DEBUG_CORE, ev->log, 0,
1148
+ "close channel s:%i pid:%P our:%P fd:%d",
1149
+ ch.slot, ch.pid, ngx_processes[ch.slot].pid,
1150
+ ngx_processes[ch.slot].channel[0]);
1151
+
1152
+ if (close(ngx_processes[ch.slot].channel[0]) == -1) {
1153
+ ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
1154
+ "close() channel failed");
1155
+ }
1156
+
1157
+ ngx_processes[ch.slot].channel[0] = -1;
1158
+ break;
1159
+ }
1160
+ }
1161
+ }
1162
+
1163
+
1164
+ #if (NGX_THREADS)
1165
+
1166
+ static void
1167
+ ngx_wakeup_worker_threads(ngx_cycle_t *cycle)
1168
+ {
1169
+ ngx_int_t i;
1170
+ ngx_uint_t live;
1171
+
1172
+ for ( ;; ) {
1173
+
1174
+ live = 0;
1175
+
1176
+ for (i = 0; i < ngx_threads_n; i++) {
1177
+ if (ngx_threads[i].state < NGX_THREAD_EXIT) {
1178
+ if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) {
1179
+ ngx_threads[i].state = NGX_THREAD_DONE;
1180
+
1181
+ } else {
1182
+ live = 1;
1183
+ }
1184
+ }
1185
+
1186
+ if (ngx_threads[i].state == NGX_THREAD_EXIT) {
1187
+ ngx_thread_join(ngx_threads[i].tid, NULL);
1188
+ ngx_threads[i].state = NGX_THREAD_DONE;
1189
+ }
1190
+ }
1191
+
1192
+ if (live == 0) {
1193
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, cycle->log, 0,
1194
+ "all worker threads are joined");
1195
+
1196
+ /* STUB */
1197
+ ngx_done_events(cycle);
1198
+ ngx_mutex_destroy(ngx_event_timer_mutex);
1199
+ ngx_mutex_destroy(ngx_posted_events_mutex);
1200
+
1201
+ return;
1202
+ }
1203
+
1204
+ ngx_sched_yield();
1205
+ }
1206
+ }
1207
+
1208
+
1209
+ static ngx_thread_value_t
1210
+ ngx_worker_thread_cycle(void *data)
1211
+ {
1212
+ ngx_thread_t *thr = data;
1213
+
1214
+ sigset_t set;
1215
+ ngx_err_t err;
1216
+ ngx_core_tls_t *tls;
1217
+ ngx_cycle_t *cycle;
1218
+
1219
+ cycle = (ngx_cycle_t *) ngx_cycle;
1220
+
1221
+ sigemptyset(&set);
1222
+ sigaddset(&set, ngx_signal_value(NGX_RECONFIGURE_SIGNAL));
1223
+ sigaddset(&set, ngx_signal_value(NGX_REOPEN_SIGNAL));
1224
+ sigaddset(&set, ngx_signal_value(NGX_CHANGEBIN_SIGNAL));
1225
+
1226
+ err = ngx_thread_sigmask(SIG_BLOCK, &set, NULL);
1227
+ if (err) {
1228
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
1229
+ ngx_thread_sigmask_n " failed");
1230
+ return (ngx_thread_value_t) 1;
1231
+ }
1232
+
1233
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
1234
+ "thread " NGX_TID_T_FMT " started", ngx_thread_self());
1235
+
1236
+ ngx_setthrtitle("worker thread");
1237
+
1238
+ tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log);
1239
+ if (tls == NULL) {
1240
+ return (ngx_thread_value_t) 1;
1241
+ }
1242
+
1243
+ err = ngx_thread_set_tls(ngx_core_tls_key, tls);
1244
+ if (err != 0) {
1245
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err,
1246
+ ngx_thread_set_tls_n " failed");
1247
+ return (ngx_thread_value_t) 1;
1248
+ }
1249
+
1250
+ ngx_mutex_lock(ngx_posted_events_mutex);
1251
+
1252
+ for ( ;; ) {
1253
+ thr->state = NGX_THREAD_FREE;
1254
+
1255
+ if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) {
1256
+ return (ngx_thread_value_t) 1;
1257
+ }
1258
+
1259
+ if (ngx_terminate) {
1260
+ thr->state = NGX_THREAD_EXIT;
1261
+
1262
+ ngx_mutex_unlock(ngx_posted_events_mutex);
1263
+
1264
+ ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0,
1265
+ "thread " NGX_TID_T_FMT " is done",
1266
+ ngx_thread_self());
1267
+
1268
+ return (ngx_thread_value_t) 0;
1269
+ }
1270
+
1271
+ thr->state = NGX_THREAD_BUSY;
1272
+
1273
+ if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
1274
+ return (ngx_thread_value_t) 1;
1275
+ }
1276
+
1277
+ if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) {
1278
+ return (ngx_thread_value_t) 1;
1279
+ }
1280
+
1281
+ if (ngx_process_changes) {
1282
+ if (ngx_process_changes(cycle, 1) == NGX_ERROR) {
1283
+ return (ngx_thread_value_t) 1;
1284
+ }
1285
+ }
1286
+ }
1287
+ }
1288
+
1289
+ #endif
1290
+
1291
+
1292
+ static void
1293
+ ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data)
1294
+ {
1295
+ ngx_cache_manager_ctx_t *ctx = data;
1296
+
1297
+ void *ident[4];
1298
+ ngx_event_t ev;
1299
+
1300
+ cycle->connection_n = 512;
1301
+
1302
+ ngx_process = NGX_PROCESS_HELPER;
1303
+
1304
+ ngx_worker_process_init(cycle, 0);
1305
+
1306
+ ngx_close_listening_sockets(cycle);
1307
+
1308
+ ngx_memzero(&ev, sizeof(ngx_event_t));
1309
+ ev.handler = ctx->handler;
1310
+ ev.data = ident;
1311
+ ev.log = cycle->log;
1312
+ ident[3] = (void *) -1;
1313
+
1314
+ ngx_use_accept_mutex = 0;
1315
+
1316
+ ngx_setproctitle(ctx->name);
1317
+
1318
+ ngx_add_timer(&ev, ctx->delay);
1319
+
1320
+ for ( ;; ) {
1321
+
1322
+ if (ngx_terminate || ngx_quit) {
1323
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting");
1324
+ exit(0);
1325
+ }
1326
+
1327
+ if (ngx_reopen) {
1328
+ ngx_reopen = 0;
1329
+ ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "reopening logs");
1330
+ ngx_reopen_files(cycle, -1);
1331
+ }
1332
+
1333
+ ngx_process_events_and_timers(cycle);
1334
+ }
1335
+ }
1336
+
1337
+
1338
+ static void
1339
+ ngx_cache_manager_process_handler(ngx_event_t *ev)
1340
+ {
1341
+ time_t next, n;
1342
+ ngx_uint_t i;
1343
+ ngx_path_t **path;
1344
+
1345
+ next = 60 * 60;
1346
+
1347
+ path = ngx_cycle->pathes.elts;
1348
+ for (i = 0; i < ngx_cycle->pathes.nelts; i++) {
1349
+
1350
+ if (path[i]->manager) {
1351
+ n = path[i]->manager(path[i]->data);
1352
+
1353
+ next = (n <= next) ? n : next;
1354
+
1355
+ ngx_time_update();
1356
+ }
1357
+ }
1358
+
1359
+ if (next == 0) {
1360
+ next = 1;
1361
+ }
1362
+
1363
+ ngx_add_timer(ev, next * 1000);
1364
+ }
1365
+
1366
+
1367
+ static void
1368
+ ngx_cache_loader_process_handler(ngx_event_t *ev)
1369
+ {
1370
+ ngx_uint_t i;
1371
+ ngx_path_t **path;
1372
+ ngx_cycle_t *cycle;
1373
+
1374
+ cycle = (ngx_cycle_t *) ngx_cycle;
1375
+
1376
+ path = cycle->pathes.elts;
1377
+ for (i = 0; i < cycle->pathes.nelts; i++) {
1378
+
1379
+ if (ngx_terminate || ngx_quit) {
1380
+ break;
1381
+ }
1382
+
1383
+ if (path[i]->loader) {
1384
+ path[i]->loader(path[i]->data);
1385
+ ngx_time_update();
1386
+ }
1387
+ }
1388
+
1389
+ exit(0);
1390
+ }