racer 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (336) hide show
  1. data/LICENSE +22 -0
  2. data/bin/racer +33 -0
  3. data/ext/libuv/AUTHORS +45 -0
  4. data/ext/libuv/LICENSE +42 -0
  5. data/ext/libuv/Makefile +119 -0
  6. data/ext/libuv/README.md +88 -0
  7. data/ext/libuv/build/gcc_version.py +20 -0
  8. data/ext/libuv/common.gypi +176 -0
  9. data/ext/libuv/config-mingw.mk +61 -0
  10. data/ext/libuv/config-unix.mk +171 -0
  11. data/ext/libuv/gyp_uv +64 -0
  12. data/ext/libuv/include/ares.h +591 -0
  13. data/ext/libuv/include/ares_version.h +24 -0
  14. data/ext/libuv/include/uv-private/eio.h +403 -0
  15. data/ext/libuv/include/uv-private/ev.h +838 -0
  16. data/ext/libuv/include/uv-private/ngx-queue.h +108 -0
  17. data/ext/libuv/include/uv-private/tree.h +768 -0
  18. data/ext/libuv/include/uv-private/uv-unix.h +310 -0
  19. data/ext/libuv/include/uv-private/uv-win.h +510 -0
  20. data/ext/libuv/include/uv.h +1796 -0
  21. data/ext/libuv/src/ares/AUTHORS +37 -0
  22. data/ext/libuv/src/ares/CHANGES +1218 -0
  23. data/ext/libuv/src/ares/CMakeLists.txt +22 -0
  24. data/ext/libuv/src/ares/NEWS +21 -0
  25. data/ext/libuv/src/ares/README +60 -0
  26. data/ext/libuv/src/ares/README.cares +13 -0
  27. data/ext/libuv/src/ares/README.msvc +142 -0
  28. data/ext/libuv/src/ares/README.node +21 -0
  29. data/ext/libuv/src/ares/RELEASE-NOTES +26 -0
  30. data/ext/libuv/src/ares/TODO +23 -0
  31. data/ext/libuv/src/ares/ares__close_sockets.c +66 -0
  32. data/ext/libuv/src/ares/ares__get_hostent.c +263 -0
  33. data/ext/libuv/src/ares/ares__read_line.c +71 -0
  34. data/ext/libuv/src/ares/ares__timeval.c +111 -0
  35. data/ext/libuv/src/ares/ares_cancel.c +63 -0
  36. data/ext/libuv/src/ares/ares_data.c +190 -0
  37. data/ext/libuv/src/ares/ares_data.h +65 -0
  38. data/ext/libuv/src/ares/ares_destroy.c +105 -0
  39. data/ext/libuv/src/ares/ares_dns.h +90 -0
  40. data/ext/libuv/src/ares/ares_expand_name.c +200 -0
  41. data/ext/libuv/src/ares/ares_expand_string.c +75 -0
  42. data/ext/libuv/src/ares/ares_fds.c +63 -0
  43. data/ext/libuv/src/ares/ares_free_hostent.c +42 -0
  44. data/ext/libuv/src/ares/ares_free_string.c +25 -0
  45. data/ext/libuv/src/ares/ares_getenv.c +30 -0
  46. data/ext/libuv/src/ares/ares_getenv.h +26 -0
  47. data/ext/libuv/src/ares/ares_gethostbyaddr.c +301 -0
  48. data/ext/libuv/src/ares/ares_gethostbyname.c +523 -0
  49. data/ext/libuv/src/ares/ares_getnameinfo.c +427 -0
  50. data/ext/libuv/src/ares/ares_getopt.c +122 -0
  51. data/ext/libuv/src/ares/ares_getopt.h +53 -0
  52. data/ext/libuv/src/ares/ares_getsock.c +72 -0
  53. data/ext/libuv/src/ares/ares_init.c +1809 -0
  54. data/ext/libuv/src/ares/ares_iphlpapi.h +221 -0
  55. data/ext/libuv/src/ares/ares_ipv6.h +78 -0
  56. data/ext/libuv/src/ares/ares_library_init.c +142 -0
  57. data/ext/libuv/src/ares/ares_library_init.h +42 -0
  58. data/ext/libuv/src/ares/ares_llist.c +86 -0
  59. data/ext/libuv/src/ares/ares_llist.h +42 -0
  60. data/ext/libuv/src/ares/ares_mkquery.c +195 -0
  61. data/ext/libuv/src/ares/ares_nowarn.c +181 -0
  62. data/ext/libuv/src/ares/ares_nowarn.h +55 -0
  63. data/ext/libuv/src/ares/ares_options.c +248 -0
  64. data/ext/libuv/src/ares/ares_parse_a_reply.c +263 -0
  65. data/ext/libuv/src/ares/ares_parse_aaaa_reply.c +259 -0
  66. data/ext/libuv/src/ares/ares_parse_mx_reply.c +170 -0
  67. data/ext/libuv/src/ares/ares_parse_ns_reply.c +182 -0
  68. data/ext/libuv/src/ares/ares_parse_ptr_reply.c +217 -0
  69. data/ext/libuv/src/ares/ares_parse_srv_reply.c +179 -0
  70. data/ext/libuv/src/ares/ares_parse_txt_reply.c +201 -0
  71. data/ext/libuv/src/ares/ares_platform.c +11035 -0
  72. data/ext/libuv/src/ares/ares_platform.h +43 -0
  73. data/ext/libuv/src/ares/ares_private.h +355 -0
  74. data/ext/libuv/src/ares/ares_process.c +1295 -0
  75. data/ext/libuv/src/ares/ares_query.c +183 -0
  76. data/ext/libuv/src/ares/ares_rules.h +144 -0
  77. data/ext/libuv/src/ares/ares_search.c +321 -0
  78. data/ext/libuv/src/ares/ares_send.c +134 -0
  79. data/ext/libuv/src/ares/ares_setup.h +199 -0
  80. data/ext/libuv/src/ares/ares_strcasecmp.c +66 -0
  81. data/ext/libuv/src/ares/ares_strcasecmp.h +30 -0
  82. data/ext/libuv/src/ares/ares_strdup.c +42 -0
  83. data/ext/libuv/src/ares/ares_strdup.h +26 -0
  84. data/ext/libuv/src/ares/ares_strerror.c +56 -0
  85. data/ext/libuv/src/ares/ares_timeout.c +80 -0
  86. data/ext/libuv/src/ares/ares_version.c +11 -0
  87. data/ext/libuv/src/ares/ares_writev.c +79 -0
  88. data/ext/libuv/src/ares/ares_writev.h +36 -0
  89. data/ext/libuv/src/ares/bitncmp.c +59 -0
  90. data/ext/libuv/src/ares/bitncmp.h +26 -0
  91. data/ext/libuv/src/ares/config_cygwin/ares_config.h +512 -0
  92. data/ext/libuv/src/ares/config_darwin/ares_config.h +512 -0
  93. data/ext/libuv/src/ares/config_freebsd/ares_config.h +512 -0
  94. data/ext/libuv/src/ares/config_linux/ares_config.h +512 -0
  95. data/ext/libuv/src/ares/config_netbsd/ares_config.h +512 -0
  96. data/ext/libuv/src/ares/config_openbsd/ares_config.h +512 -0
  97. data/ext/libuv/src/ares/config_sunos/ares_config.h +512 -0
  98. data/ext/libuv/src/ares/config_win32/ares_config.h +369 -0
  99. data/ext/libuv/src/ares/get_ver.awk +35 -0
  100. data/ext/libuv/src/ares/inet_net_pton.c +451 -0
  101. data/ext/libuv/src/ares/inet_net_pton.h +31 -0
  102. data/ext/libuv/src/ares/inet_ntop.c +208 -0
  103. data/ext/libuv/src/ares/inet_ntop.h +26 -0
  104. data/ext/libuv/src/ares/nameser.h +203 -0
  105. data/ext/libuv/src/ares/setup_once.h +504 -0
  106. data/ext/libuv/src/ares/windows_port.c +22 -0
  107. data/ext/libuv/src/cares.c +225 -0
  108. data/ext/libuv/src/fs-poll.c +237 -0
  109. data/ext/libuv/src/unix/async.c +119 -0
  110. data/ext/libuv/src/unix/core.c +647 -0
  111. data/ext/libuv/src/unix/cygwin.c +84 -0
  112. data/ext/libuv/src/unix/darwin.c +341 -0
  113. data/ext/libuv/src/unix/dl.c +83 -0
  114. data/ext/libuv/src/unix/eio/Changes +63 -0
  115. data/ext/libuv/src/unix/eio/LICENSE +36 -0
  116. data/ext/libuv/src/unix/eio/Makefile.am +15 -0
  117. data/ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
  118. data/ext/libuv/src/unix/eio/autogen.sh +3 -0
  119. data/ext/libuv/src/unix/eio/config.h.in +86 -0
  120. data/ext/libuv/src/unix/eio/config_cygwin.h +80 -0
  121. data/ext/libuv/src/unix/eio/config_darwin.h +141 -0
  122. data/ext/libuv/src/unix/eio/config_freebsd.h +81 -0
  123. data/ext/libuv/src/unix/eio/config_linux.h +94 -0
  124. data/ext/libuv/src/unix/eio/config_netbsd.h +81 -0
  125. data/ext/libuv/src/unix/eio/config_openbsd.h +137 -0
  126. data/ext/libuv/src/unix/eio/config_sunos.h +84 -0
  127. data/ext/libuv/src/unix/eio/configure.ac +22 -0
  128. data/ext/libuv/src/unix/eio/demo.c +194 -0
  129. data/ext/libuv/src/unix/eio/ecb.h +370 -0
  130. data/ext/libuv/src/unix/eio/eio.3 +3428 -0
  131. data/ext/libuv/src/unix/eio/eio.c +2593 -0
  132. data/ext/libuv/src/unix/eio/eio.pod +969 -0
  133. data/ext/libuv/src/unix/eio/libeio.m4 +195 -0
  134. data/ext/libuv/src/unix/eio/xthread.h +164 -0
  135. data/ext/libuv/src/unix/error.c +104 -0
  136. data/ext/libuv/src/unix/ev/Changes +388 -0
  137. data/ext/libuv/src/unix/ev/LICENSE +36 -0
  138. data/ext/libuv/src/unix/ev/Makefile.am +18 -0
  139. data/ext/libuv/src/unix/ev/Makefile.in +771 -0
  140. data/ext/libuv/src/unix/ev/README +58 -0
  141. data/ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
  142. data/ext/libuv/src/unix/ev/autogen.sh +6 -0
  143. data/ext/libuv/src/unix/ev/config.guess +1526 -0
  144. data/ext/libuv/src/unix/ev/config.h.in +125 -0
  145. data/ext/libuv/src/unix/ev/config.sub +1658 -0
  146. data/ext/libuv/src/unix/ev/config_cygwin.h +123 -0
  147. data/ext/libuv/src/unix/ev/config_darwin.h +122 -0
  148. data/ext/libuv/src/unix/ev/config_freebsd.h +120 -0
  149. data/ext/libuv/src/unix/ev/config_linux.h +141 -0
  150. data/ext/libuv/src/unix/ev/config_netbsd.h +120 -0
  151. data/ext/libuv/src/unix/ev/config_openbsd.h +126 -0
  152. data/ext/libuv/src/unix/ev/config_sunos.h +122 -0
  153. data/ext/libuv/src/unix/ev/configure +13037 -0
  154. data/ext/libuv/src/unix/ev/configure.ac +18 -0
  155. data/ext/libuv/src/unix/ev/depcomp +630 -0
  156. data/ext/libuv/src/unix/ev/ev++.h +816 -0
  157. data/ext/libuv/src/unix/ev/ev.3 +5311 -0
  158. data/ext/libuv/src/unix/ev/ev.c +3925 -0
  159. data/ext/libuv/src/unix/ev/ev.pod +5243 -0
  160. data/ext/libuv/src/unix/ev/ev_epoll.c +266 -0
  161. data/ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
  162. data/ext/libuv/src/unix/ev/ev_poll.c +148 -0
  163. data/ext/libuv/src/unix/ev/ev_port.c +179 -0
  164. data/ext/libuv/src/unix/ev/ev_select.c +310 -0
  165. data/ext/libuv/src/unix/ev/ev_vars.h +203 -0
  166. data/ext/libuv/src/unix/ev/ev_win32.c +153 -0
  167. data/ext/libuv/src/unix/ev/ev_wrap.h +196 -0
  168. data/ext/libuv/src/unix/ev/event.c +402 -0
  169. data/ext/libuv/src/unix/ev/event.h +170 -0
  170. data/ext/libuv/src/unix/ev/install-sh +294 -0
  171. data/ext/libuv/src/unix/ev/libev.m4 +39 -0
  172. data/ext/libuv/src/unix/ev/ltmain.sh +8413 -0
  173. data/ext/libuv/src/unix/ev/missing +336 -0
  174. data/ext/libuv/src/unix/ev/mkinstalldirs +111 -0
  175. data/ext/libuv/src/unix/freebsd.c +312 -0
  176. data/ext/libuv/src/unix/fs.c +699 -0
  177. data/ext/libuv/src/unix/internal.h +180 -0
  178. data/ext/libuv/src/unix/kqueue.c +122 -0
  179. data/ext/libuv/src/unix/linux/core.c +474 -0
  180. data/ext/libuv/src/unix/linux/inotify.c +209 -0
  181. data/ext/libuv/src/unix/linux/syscalls.c +268 -0
  182. data/ext/libuv/src/unix/linux/syscalls.h +93 -0
  183. data/ext/libuv/src/unix/loop-watcher.c +63 -0
  184. data/ext/libuv/src/unix/loop.c +81 -0
  185. data/ext/libuv/src/unix/netbsd.c +108 -0
  186. data/ext/libuv/src/unix/openbsd.c +295 -0
  187. data/ext/libuv/src/unix/pipe.c +261 -0
  188. data/ext/libuv/src/unix/poll.c +116 -0
  189. data/ext/libuv/src/unix/process.c +447 -0
  190. data/ext/libuv/src/unix/stream.c +1026 -0
  191. data/ext/libuv/src/unix/sunos.c +483 -0
  192. data/ext/libuv/src/unix/tcp.c +328 -0
  193. data/ext/libuv/src/unix/thread.c +211 -0
  194. data/ext/libuv/src/unix/timer.c +138 -0
  195. data/ext/libuv/src/unix/tty.c +146 -0
  196. data/ext/libuv/src/unix/udp.c +661 -0
  197. data/ext/libuv/src/unix/uv-eio.c +107 -0
  198. data/ext/libuv/src/unix/uv-eio.h +13 -0
  199. data/ext/libuv/src/uv-common.c +384 -0
  200. data/ext/libuv/src/uv-common.h +171 -0
  201. data/ext/libuv/src/win/async.c +130 -0
  202. data/ext/libuv/src/win/core.c +283 -0
  203. data/ext/libuv/src/win/dl.c +86 -0
  204. data/ext/libuv/src/win/error.c +150 -0
  205. data/ext/libuv/src/win/fs-event.c +512 -0
  206. data/ext/libuv/src/win/fs.c +1856 -0
  207. data/ext/libuv/src/win/getaddrinfo.c +365 -0
  208. data/ext/libuv/src/win/handle-inl.h +145 -0
  209. data/ext/libuv/src/win/handle.c +150 -0
  210. data/ext/libuv/src/win/internal.h +337 -0
  211. data/ext/libuv/src/win/loop-watcher.c +123 -0
  212. data/ext/libuv/src/win/pipe.c +1675 -0
  213. data/ext/libuv/src/win/poll.c +618 -0
  214. data/ext/libuv/src/win/process-stdio.c +479 -0
  215. data/ext/libuv/src/win/process.c +1013 -0
  216. data/ext/libuv/src/win/req-inl.h +225 -0
  217. data/ext/libuv/src/win/req.c +25 -0
  218. data/ext/libuv/src/win/stream-inl.h +69 -0
  219. data/ext/libuv/src/win/stream.c +167 -0
  220. data/ext/libuv/src/win/tcp.c +1400 -0
  221. data/ext/libuv/src/win/thread.c +372 -0
  222. data/ext/libuv/src/win/threadpool.c +74 -0
  223. data/ext/libuv/src/win/timer.c +226 -0
  224. data/ext/libuv/src/win/tty.c +1801 -0
  225. data/ext/libuv/src/win/udp.c +718 -0
  226. data/ext/libuv/src/win/util.c +864 -0
  227. data/ext/libuv/src/win/winapi.c +132 -0
  228. data/ext/libuv/src/win/winapi.h +4443 -0
  229. data/ext/libuv/src/win/winsock.c +557 -0
  230. data/ext/libuv/src/win/winsock.h +171 -0
  231. data/ext/libuv/test/benchmark-ares.c +117 -0
  232. data/ext/libuv/test/benchmark-fs-stat.c +164 -0
  233. data/ext/libuv/test/benchmark-getaddrinfo.c +94 -0
  234. data/ext/libuv/test/benchmark-list.h +114 -0
  235. data/ext/libuv/test/benchmark-loop-count.c +88 -0
  236. data/ext/libuv/test/benchmark-million-timers.c +65 -0
  237. data/ext/libuv/test/benchmark-ping-pongs.c +213 -0
  238. data/ext/libuv/test/benchmark-pound.c +324 -0
  239. data/ext/libuv/test/benchmark-pump.c +462 -0
  240. data/ext/libuv/test/benchmark-sizes.c +42 -0
  241. data/ext/libuv/test/benchmark-spawn.c +162 -0
  242. data/ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
  243. data/ext/libuv/test/benchmark-thread.c +64 -0
  244. data/ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
  245. data/ext/libuv/test/blackhole-server.c +118 -0
  246. data/ext/libuv/test/dns-server.c +321 -0
  247. data/ext/libuv/test/echo-server.c +378 -0
  248. data/ext/libuv/test/fixtures/empty_file +0 -0
  249. data/ext/libuv/test/fixtures/load_error.node +1 -0
  250. data/ext/libuv/test/run-benchmarks.c +64 -0
  251. data/ext/libuv/test/run-tests.c +138 -0
  252. data/ext/libuv/test/runner-unix.c +290 -0
  253. data/ext/libuv/test/runner-unix.h +36 -0
  254. data/ext/libuv/test/runner-win.c +285 -0
  255. data/ext/libuv/test/runner-win.h +42 -0
  256. data/ext/libuv/test/runner.c +326 -0
  257. data/ext/libuv/test/runner.h +159 -0
  258. data/ext/libuv/test/task.h +109 -0
  259. data/ext/libuv/test/test-async.c +118 -0
  260. data/ext/libuv/test/test-callback-order.c +76 -0
  261. data/ext/libuv/test/test-callback-stack.c +203 -0
  262. data/ext/libuv/test/test-connection-fail.c +148 -0
  263. data/ext/libuv/test/test-counters-init.c +215 -0
  264. data/ext/libuv/test/test-cwd-and-chdir.c +64 -0
  265. data/ext/libuv/test/test-delayed-accept.c +197 -0
  266. data/ext/libuv/test/test-dlerror.c +58 -0
  267. data/ext/libuv/test/test-error.c +59 -0
  268. data/ext/libuv/test/test-fail-always.c +29 -0
  269. data/ext/libuv/test/test-fs-event.c +442 -0
  270. data/ext/libuv/test/test-fs-poll.c +146 -0
  271. data/ext/libuv/test/test-fs.c +1843 -0
  272. data/ext/libuv/test/test-get-currentexe.c +63 -0
  273. data/ext/libuv/test/test-get-loadavg.c +36 -0
  274. data/ext/libuv/test/test-get-memory.c +38 -0
  275. data/ext/libuv/test/test-getaddrinfo.c +122 -0
  276. data/ext/libuv/test/test-gethostbyname.c +189 -0
  277. data/ext/libuv/test/test-getsockname.c +342 -0
  278. data/ext/libuv/test/test-hrtime.c +54 -0
  279. data/ext/libuv/test/test-idle.c +81 -0
  280. data/ext/libuv/test/test-ipc-send-recv.c +209 -0
  281. data/ext/libuv/test/test-ipc.c +620 -0
  282. data/ext/libuv/test/test-list.h +421 -0
  283. data/ext/libuv/test/test-loop-handles.c +336 -0
  284. data/ext/libuv/test/test-multiple-listen.c +102 -0
  285. data/ext/libuv/test/test-mutexes.c +63 -0
  286. data/ext/libuv/test/test-pass-always.c +28 -0
  287. data/ext/libuv/test/test-ping-pong.c +253 -0
  288. data/ext/libuv/test/test-pipe-bind-error.c +140 -0
  289. data/ext/libuv/test/test-pipe-connect-error.c +96 -0
  290. data/ext/libuv/test/test-platform-output.c +87 -0
  291. data/ext/libuv/test/test-poll-close.c +77 -0
  292. data/ext/libuv/test/test-poll.c +573 -0
  293. data/ext/libuv/test/test-process-title.c +42 -0
  294. data/ext/libuv/test/test-ref.c +338 -0
  295. data/ext/libuv/test/test-run-once.c +48 -0
  296. data/ext/libuv/test/test-semaphore.c +111 -0
  297. data/ext/libuv/test/test-shutdown-close.c +103 -0
  298. data/ext/libuv/test/test-shutdown-eof.c +183 -0
  299. data/ext/libuv/test/test-spawn.c +847 -0
  300. data/ext/libuv/test/test-stdio-over-pipes.c +246 -0
  301. data/ext/libuv/test/test-tcp-bind-error.c +191 -0
  302. data/ext/libuv/test/test-tcp-bind6-error.c +154 -0
  303. data/ext/libuv/test/test-tcp-close-while-connecting.c +80 -0
  304. data/ext/libuv/test/test-tcp-close.c +129 -0
  305. data/ext/libuv/test/test-tcp-connect-error-after-write.c +95 -0
  306. data/ext/libuv/test/test-tcp-connect-error.c +70 -0
  307. data/ext/libuv/test/test-tcp-connect-timeout.c +85 -0
  308. data/ext/libuv/test/test-tcp-connect6-error.c +68 -0
  309. data/ext/libuv/test/test-tcp-flags.c +51 -0
  310. data/ext/libuv/test/test-tcp-shutdown-after-write.c +131 -0
  311. data/ext/libuv/test/test-tcp-write-error.c +168 -0
  312. data/ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
  313. data/ext/libuv/test/test-tcp-writealot.c +170 -0
  314. data/ext/libuv/test/test-thread.c +183 -0
  315. data/ext/libuv/test/test-threadpool.c +57 -0
  316. data/ext/libuv/test/test-timer-again.c +141 -0
  317. data/ext/libuv/test/test-timer.c +152 -0
  318. data/ext/libuv/test/test-tty.c +110 -0
  319. data/ext/libuv/test/test-udp-dgram-too-big.c +86 -0
  320. data/ext/libuv/test/test-udp-ipv6.c +156 -0
  321. data/ext/libuv/test/test-udp-multicast-join.c +139 -0
  322. data/ext/libuv/test/test-udp-multicast-ttl.c +86 -0
  323. data/ext/libuv/test/test-udp-options.c +86 -0
  324. data/ext/libuv/test/test-udp-send-and-recv.c +208 -0
  325. data/ext/libuv/test/test-util.c +97 -0
  326. data/ext/libuv/test/test-walk-handles.c +77 -0
  327. data/ext/libuv/uv.gyp +452 -0
  328. data/ext/libuv/vcbuild.bat +105 -0
  329. data/ext/racer/extconf.rb +20 -0
  330. data/ext/racer/http_parser.c +2059 -0
  331. data/ext/racer/http_parser.h +318 -0
  332. data/ext/racer/mkmf.log +22 -0
  333. data/ext/racer/racer.c +551 -0
  334. data/lib/racer.rb +2 -0
  335. data/lib/racer/version.rb +3 -0
  336. metadata +382 -0
@@ -0,0 +1,103 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ /*
23
+ * These tests verify that the uv_shutdown callback is always made, even when
24
+ * it is immediately followed by an uv_close call.
25
+ */
26
+
27
+ #include "uv.h"
28
+ #include "task.h"
29
+
30
+
31
+ static uv_shutdown_t shutdown_req;
32
+ static uv_connect_t connect_req;
33
+
34
+ static int connect_cb_called = 0;
35
+ static int shutdown_cb_called = 0;
36
+ static int close_cb_called = 0;
37
+
38
+
39
+ static void shutdown_cb(uv_shutdown_t* req, int status) {
40
+ ASSERT(req == &shutdown_req);
41
+ ASSERT(status == 0 ||
42
+ (status == -1 && uv_last_error(uv_default_loop()).code == UV_EINTR));
43
+ shutdown_cb_called++;
44
+ }
45
+
46
+
47
+ static void close_cb(uv_handle_t* handle) {
48
+ close_cb_called++;
49
+ }
50
+
51
+
52
+ static void connect_cb(uv_connect_t* req, int status) {
53
+ int r;
54
+
55
+ ASSERT(req == &connect_req);
56
+ ASSERT(status == 0);
57
+
58
+ r = uv_shutdown(&shutdown_req, req->handle, shutdown_cb);
59
+ ASSERT(r == 0);
60
+ ASSERT(!uv_is_closing((uv_handle_t*) req->handle));
61
+ uv_close((uv_handle_t*) req->handle, close_cb);
62
+ ASSERT(uv_is_closing((uv_handle_t*) req->handle));
63
+
64
+ connect_cb_called++;
65
+ }
66
+
67
+
68
+ TEST_IMPL(shutdown_close_tcp) {
69
+ struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
70
+ uv_tcp_t h;
71
+ int r;
72
+
73
+ r = uv_tcp_init(uv_default_loop(), &h);
74
+ ASSERT(r == 0);
75
+ r = uv_tcp_connect(&connect_req, &h, addr, connect_cb);
76
+ ASSERT(r == 0);
77
+ r = uv_run(uv_default_loop());
78
+ ASSERT(r == 0);
79
+
80
+ ASSERT(connect_cb_called == 1);
81
+ ASSERT(shutdown_cb_called == 1);
82
+ ASSERT(close_cb_called == 1);
83
+
84
+ return 0;
85
+ }
86
+
87
+
88
+ TEST_IMPL(shutdown_close_pipe) {
89
+ uv_pipe_t h;
90
+ int r;
91
+
92
+ r = uv_pipe_init(uv_default_loop(), &h, 0);
93
+ ASSERT(r == 0);
94
+ uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, connect_cb);
95
+ r = uv_run(uv_default_loop());
96
+ ASSERT(r == 0);
97
+
98
+ ASSERT(connect_cb_called == 1);
99
+ ASSERT(shutdown_cb_called == 1);
100
+ ASSERT(close_cb_called == 1);
101
+
102
+ return 0;
103
+ }
@@ -0,0 +1,183 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ #include "uv.h"
23
+ #include "task.h"
24
+ #include <stdio.h>
25
+ #include <stdlib.h>
26
+
27
+ static uv_timer_t timer;
28
+ static uv_tcp_t tcp;
29
+ static uv_connect_t connect_req;
30
+ static uv_write_t write_req;
31
+ static uv_shutdown_t shutdown_req;
32
+ static uv_buf_t qbuf;
33
+ static int got_q;
34
+ static int got_eof;
35
+ static int called_connect_cb;
36
+ static int called_shutdown_cb;
37
+ static int called_tcp_close_cb;
38
+ static int called_timer_close_cb;
39
+ static int called_timer_cb;
40
+
41
+
42
+ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
43
+ uv_buf_t buf;
44
+ buf.base = (char*)malloc(size);
45
+ buf.len = size;
46
+ return buf;
47
+ }
48
+
49
+
50
+ static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) {
51
+ uv_err_t err = uv_last_error(uv_default_loop());
52
+
53
+ ASSERT((uv_tcp_t*)t == &tcp);
54
+
55
+ if (nread == 0) {
56
+ ASSERT(err.code == UV_EAGAIN);
57
+ free(buf.base);
58
+ return;
59
+ }
60
+
61
+ if (!got_q) {
62
+ ASSERT(nread == 1);
63
+ ASSERT(!got_eof);
64
+ ASSERT(buf.base[0] == 'Q');
65
+ free(buf.base);
66
+ got_q = 1;
67
+ puts("got Q");
68
+ } else {
69
+ ASSERT(err.code == UV_EOF);
70
+ if (buf.base) {
71
+ free(buf.base);
72
+ }
73
+ got_eof = 1;
74
+ puts("got EOF");
75
+ }
76
+ }
77
+
78
+
79
+ static void shutdown_cb(uv_shutdown_t *req, int status) {
80
+ ASSERT(req == &shutdown_req);
81
+
82
+ ASSERT(called_connect_cb == 1);
83
+ ASSERT(!got_eof);
84
+ ASSERT(called_tcp_close_cb == 0);
85
+ ASSERT(called_timer_close_cb == 0);
86
+ ASSERT(called_timer_cb == 0);
87
+
88
+ called_shutdown_cb++;
89
+ }
90
+
91
+
92
+ static void connect_cb(uv_connect_t *req, int status) {
93
+ ASSERT(status == 0);
94
+ ASSERT(req == &connect_req);
95
+
96
+ /* Start reading from our connection so we can receive the EOF. */
97
+ uv_read_start((uv_stream_t*)&tcp, alloc_cb, read_cb);
98
+
99
+ /*
100
+ * Write the letter 'Q' to gracefully kill the echo-server. This will not
101
+ * effect our connection.
102
+ */
103
+ uv_write(&write_req, (uv_stream_t*) &tcp, &qbuf, 1, NULL);
104
+
105
+ /* Shutdown our end of the connection. */
106
+ uv_shutdown(&shutdown_req, (uv_stream_t*) &tcp, shutdown_cb);
107
+
108
+ called_connect_cb++;
109
+ ASSERT(called_shutdown_cb == 0);
110
+ }
111
+
112
+
113
+ void tcp_close_cb(uv_handle_t* handle) {
114
+ ASSERT(handle == (uv_handle_t*) &tcp);
115
+
116
+ ASSERT(called_connect_cb == 1);
117
+ ASSERT(got_q);
118
+ ASSERT(got_eof);
119
+ ASSERT(called_timer_cb == 1);
120
+
121
+ called_tcp_close_cb++;
122
+ }
123
+
124
+
125
+ void timer_close_cb(uv_handle_t* handle) {
126
+ ASSERT(handle == (uv_handle_t*) &timer);
127
+ called_timer_close_cb++;
128
+ }
129
+
130
+
131
+ void timer_cb(uv_timer_t* handle, int status) {
132
+ ASSERT(handle == &timer);
133
+ uv_close((uv_handle_t*) handle, timer_close_cb);
134
+
135
+ /*
136
+ * The most important assert of the test: we have not received
137
+ * tcp_close_cb yet.
138
+ */
139
+ ASSERT(called_tcp_close_cb == 0);
140
+ uv_close((uv_handle_t*) &tcp, tcp_close_cb);
141
+
142
+ called_timer_cb++;
143
+ }
144
+
145
+
146
+ /*
147
+ * This test has a client which connects to the echo_server and immediately
148
+ * issues a shutdown. The echo-server, in response, will also shutdown their
149
+ * connection. We check, with a timer, that libuv is not automatically
150
+ * calling uv_close when the client receives the EOF from echo-server.
151
+ */
152
+ TEST_IMPL(shutdown_eof) {
153
+ struct sockaddr_in server_addr;
154
+ int r;
155
+
156
+ qbuf.base = "Q";
157
+ qbuf.len = 1;
158
+
159
+ r = uv_timer_init(uv_default_loop(), &timer);
160
+ ASSERT(r == 0);
161
+
162
+ uv_timer_start(&timer, timer_cb, 100, 0);
163
+
164
+ server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
165
+ r = uv_tcp_init(uv_default_loop(), &tcp);
166
+ ASSERT(!r);
167
+
168
+ r = uv_tcp_connect(&connect_req, &tcp, server_addr, connect_cb);
169
+ ASSERT(!r);
170
+
171
+ uv_run(uv_default_loop());
172
+
173
+ ASSERT(called_connect_cb == 1);
174
+ ASSERT(called_shutdown_cb == 1);
175
+ ASSERT(got_eof);
176
+ ASSERT(got_q);
177
+ ASSERT(called_tcp_close_cb == 1);
178
+ ASSERT(called_timer_close_cb == 1);
179
+ ASSERT(called_timer_cb == 1);
180
+
181
+ return 0;
182
+ }
183
+
@@ -0,0 +1,847 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ #include "uv.h"
23
+ #include "task.h"
24
+ #include <fcntl.h>
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+
29
+ #ifndef _WIN32
30
+ #include <unistd.h>
31
+ #endif
32
+
33
+
34
+ static int close_cb_called;
35
+ static int exit_cb_called;
36
+ static uv_process_t process;
37
+ static uv_timer_t timer;
38
+ static uv_process_options_t options;
39
+ static char exepath[1024];
40
+ static size_t exepath_size = 1024;
41
+ static char* args[3];
42
+ static int no_term_signal;
43
+
44
+ #define OUTPUT_SIZE 1024
45
+ static char output[OUTPUT_SIZE];
46
+ static int output_used;
47
+
48
+
49
+ static void close_cb(uv_handle_t* handle) {
50
+ printf("close_cb\n");
51
+ close_cb_called++;
52
+ }
53
+
54
+
55
+ static void exit_cb(uv_process_t* process, int exit_status, int term_signal) {
56
+ printf("exit_cb\n");
57
+ exit_cb_called++;
58
+ ASSERT(exit_status == 1);
59
+ ASSERT(term_signal == 0);
60
+ uv_close((uv_handle_t*)process, close_cb);
61
+ }
62
+
63
+
64
+ static void exit_cb_failure_expected(uv_process_t* process, int exit_status,
65
+ int term_signal) {
66
+ printf("exit_cb\n");
67
+ exit_cb_called++;
68
+ ASSERT(exit_status == 127);
69
+ ASSERT(term_signal == 0);
70
+ uv_close((uv_handle_t*)process, close_cb);
71
+ }
72
+
73
+
74
+ static void exit_cb_unexpected(uv_process_t* process, int exit_status,
75
+ int term_signal) {
76
+ ASSERT(0 && "should not have been called");
77
+ }
78
+
79
+
80
+ static void kill_cb(uv_process_t* process, int exit_status, int term_signal) {
81
+ uv_err_t err;
82
+
83
+ printf("exit_cb\n");
84
+ exit_cb_called++;
85
+ #ifdef _WIN32
86
+ ASSERT(exit_status == 1);
87
+ #else
88
+ ASSERT(exit_status == 0);
89
+ #endif
90
+ ASSERT(no_term_signal || term_signal == 15);
91
+ uv_close((uv_handle_t*)process, close_cb);
92
+
93
+ /*
94
+ * Sending signum == 0 should check if the
95
+ * child process is still alive, not kill it.
96
+ * This process should be dead.
97
+ */
98
+ err = uv_kill(process->pid, 0);
99
+ ASSERT(err.code == UV_ESRCH);
100
+ }
101
+
102
+ static void detach_failure_cb(uv_process_t* process, int exit_status, int term_signal) {
103
+ printf("detach_cb\n");
104
+ exit_cb_called++;
105
+ }
106
+
107
+ static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
108
+ uv_buf_t buf;
109
+ buf.base = output + output_used;
110
+ buf.len = OUTPUT_SIZE - output_used;
111
+ return buf;
112
+ }
113
+
114
+
115
+ void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) {
116
+ uv_err_t err = uv_last_error(uv_default_loop());
117
+
118
+ if (nread > 0) {
119
+ output_used += nread;
120
+ } else if (nread < 0) {
121
+ ASSERT(err.code == UV_EOF);
122
+ uv_close((uv_handle_t*)tcp, close_cb);
123
+ }
124
+ }
125
+
126
+
127
+ void write_cb(uv_write_t* req, int status) {
128
+ ASSERT(status == 0);
129
+ uv_close((uv_handle_t*)req->handle, close_cb);
130
+ }
131
+
132
+
133
+ static void init_process_options(char* test, uv_exit_cb exit_cb) {
134
+ /* Note spawn_helper1 defined in test/run-tests.c */
135
+ int r = uv_exepath(exepath, &exepath_size);
136
+ ASSERT(r == 0);
137
+ exepath[exepath_size] = '\0';
138
+ args[0] = exepath;
139
+ args[1] = test;
140
+ args[2] = NULL;
141
+ options.file = exepath;
142
+ options.args = args;
143
+ options.exit_cb = exit_cb;
144
+ options.flags = 0;
145
+ }
146
+
147
+
148
+ static void timer_cb(uv_timer_t* handle, int status) {
149
+ uv_process_kill(&process, /* SIGTERM */ 15);
150
+ uv_close((uv_handle_t*)handle, close_cb);
151
+ }
152
+
153
+
154
+ TEST_IMPL(spawn_exit_code) {
155
+ int r;
156
+
157
+ init_process_options("spawn_helper1", exit_cb);
158
+
159
+ r = uv_spawn(uv_default_loop(), &process, options);
160
+ ASSERT(r == 0);
161
+
162
+ r = uv_run(uv_default_loop());
163
+ ASSERT(r == 0);
164
+
165
+ ASSERT(exit_cb_called == 1);
166
+ ASSERT(close_cb_called == 1);
167
+
168
+ return 0;
169
+ }
170
+
171
+
172
+ TEST_IMPL(spawn_stdout) {
173
+ int r;
174
+ uv_pipe_t out;
175
+ uv_stdio_container_t stdio[2];
176
+
177
+ init_process_options("spawn_helper2", exit_cb);
178
+
179
+ uv_pipe_init(uv_default_loop(), &out, 0);
180
+ options.stdio = stdio;
181
+ options.stdio[0].flags = UV_IGNORE;
182
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
183
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
184
+ options.stdio_count = 2;
185
+
186
+ r = uv_spawn(uv_default_loop(), &process, options);
187
+ ASSERT(r == 0);
188
+
189
+ r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
190
+ ASSERT(r == 0);
191
+
192
+ r = uv_run(uv_default_loop());
193
+ ASSERT(r == 0);
194
+
195
+ ASSERT(exit_cb_called == 1);
196
+ ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
197
+ printf("output is: %s", output);
198
+ ASSERT(strcmp("hello world\n", output) == 0);
199
+
200
+ return 0;
201
+ }
202
+
203
+
204
+ TEST_IMPL(spawn_stdout_to_file) {
205
+ int r;
206
+ uv_file file;
207
+ uv_fs_t fs_req;
208
+ uv_stdio_container_t stdio[2];
209
+
210
+ /* Setup. */
211
+ unlink("stdout_file");
212
+
213
+ init_process_options("spawn_helper2", exit_cb);
214
+
215
+ r = uv_fs_open(uv_default_loop(), &fs_req, "stdout_file", O_CREAT | O_RDWR,
216
+ S_IREAD | S_IWRITE, NULL);
217
+ ASSERT(r != -1);
218
+ uv_fs_req_cleanup(&fs_req);
219
+
220
+ file = r;
221
+
222
+ options.stdio = stdio;
223
+ options.stdio[0].flags = UV_IGNORE;
224
+ options.stdio[1].flags = UV_INHERIT_FD;
225
+ options.stdio[1].data.fd = file;
226
+ options.stdio_count = 2;
227
+
228
+ r = uv_spawn(uv_default_loop(), &process, options);
229
+ ASSERT(r == 0);
230
+
231
+ r = uv_run(uv_default_loop());
232
+ ASSERT(r == 0);
233
+
234
+ ASSERT(exit_cb_called == 1);
235
+ ASSERT(close_cb_called == 1);
236
+
237
+ r = uv_fs_read(uv_default_loop(), &fs_req, file, output, sizeof(output),
238
+ 0, NULL);
239
+ ASSERT(r == 12);
240
+ uv_fs_req_cleanup(&fs_req);
241
+
242
+ r = uv_fs_close(uv_default_loop(), &fs_req, file, NULL);
243
+ ASSERT(r == 0);
244
+ uv_fs_req_cleanup(&fs_req);
245
+
246
+ printf("output is: %s", output);
247
+ ASSERT(strcmp("hello world\n", output) == 0);
248
+
249
+ /* Cleanup. */
250
+ unlink("stdout_file");
251
+
252
+ return 0;
253
+ }
254
+
255
+
256
+ TEST_IMPL(spawn_stdin) {
257
+ int r;
258
+ uv_pipe_t out;
259
+ uv_pipe_t in;
260
+ uv_write_t write_req;
261
+ uv_buf_t buf;
262
+ uv_stdio_container_t stdio[2];
263
+ char buffer[] = "hello-from-spawn_stdin";
264
+
265
+ init_process_options("spawn_helper3", exit_cb);
266
+
267
+ uv_pipe_init(uv_default_loop(), &out, 0);
268
+ uv_pipe_init(uv_default_loop(), &in, 0);
269
+ options.stdio = stdio;
270
+ options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
271
+ options.stdio[0].data.stream = (uv_stream_t*)&in;
272
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
273
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
274
+ options.stdio_count = 2;
275
+
276
+ r = uv_spawn(uv_default_loop(), &process, options);
277
+ ASSERT(r == 0);
278
+
279
+ buf.base = buffer;
280
+ buf.len = sizeof(buffer);
281
+ r = uv_write(&write_req, (uv_stream_t*)&in, &buf, 1, write_cb);
282
+ ASSERT(r == 0);
283
+
284
+ r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
285
+ ASSERT(r == 0);
286
+
287
+ r = uv_run(uv_default_loop());
288
+ ASSERT(r == 0);
289
+
290
+ ASSERT(exit_cb_called == 1);
291
+ ASSERT(close_cb_called == 3); /* Once for process twice for the pipe. */
292
+ ASSERT(strcmp(buffer, output) == 0);
293
+
294
+ return 0;
295
+ }
296
+
297
+
298
+ TEST_IMPL(spawn_stdio_greater_than_3) {
299
+ int r;
300
+ uv_pipe_t pipe;
301
+ uv_stdio_container_t stdio[4];
302
+
303
+ init_process_options("spawn_helper5", exit_cb);
304
+
305
+ uv_pipe_init(uv_default_loop(), &pipe, 0);
306
+ options.stdio = stdio;
307
+ options.stdio[0].flags = UV_IGNORE;
308
+ options.stdio[1].flags = UV_IGNORE;
309
+ options.stdio[2].flags = UV_IGNORE;
310
+ options.stdio[3].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
311
+ options.stdio[3].data.stream = (uv_stream_t*)&pipe;
312
+ options.stdio_count = 4;
313
+
314
+ r = uv_spawn(uv_default_loop(), &process, options);
315
+ ASSERT(r == 0);
316
+
317
+ r = uv_read_start((uv_stream_t*) &pipe, on_alloc, on_read);
318
+ ASSERT(r == 0);
319
+
320
+ r = uv_run(uv_default_loop());
321
+ ASSERT(r == 0);
322
+
323
+ ASSERT(exit_cb_called == 1);
324
+ ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
325
+ printf("output from stdio[3] is: %s", output);
326
+ ASSERT(strcmp("fourth stdio!\n", output) == 0);
327
+
328
+ return 0;
329
+ }
330
+
331
+
332
+ TEST_IMPL(spawn_ignored_stdio) {
333
+ int r;
334
+
335
+ init_process_options("spawn_helper6", exit_cb);
336
+
337
+ options.stdio = NULL;
338
+ options.stdio_count = 0;
339
+
340
+ r = uv_spawn(uv_default_loop(), &process, options);
341
+ ASSERT(r == 0);
342
+
343
+ r = uv_run(uv_default_loop());
344
+ ASSERT(r == 0);
345
+
346
+ ASSERT(exit_cb_called == 1);
347
+ ASSERT(close_cb_called == 1);
348
+
349
+ return 0;
350
+ }
351
+
352
+
353
+ TEST_IMPL(spawn_and_kill) {
354
+ int r;
355
+
356
+ init_process_options("spawn_helper4", kill_cb);
357
+
358
+ r = uv_spawn(uv_default_loop(), &process, options);
359
+ ASSERT(r == 0);
360
+
361
+ r = uv_timer_init(uv_default_loop(), &timer);
362
+ ASSERT(r == 0);
363
+
364
+ r = uv_timer_start(&timer, timer_cb, 500, 0);
365
+ ASSERT(r == 0);
366
+
367
+ r = uv_run(uv_default_loop());
368
+ ASSERT(r == 0);
369
+
370
+ ASSERT(exit_cb_called == 1);
371
+ ASSERT(close_cb_called == 2); /* Once for process and once for timer. */
372
+
373
+ return 0;
374
+ }
375
+
376
+ TEST_IMPL(spawn_detached) {
377
+ int r;
378
+ uv_err_t err;
379
+
380
+ init_process_options("spawn_helper4", detach_failure_cb);
381
+
382
+ options.flags |= UV_PROCESS_DETACHED;
383
+
384
+ r = uv_spawn(uv_default_loop(), &process, options);
385
+ ASSERT(r == 0);
386
+
387
+ uv_unref((uv_handle_t*)&process);
388
+
389
+ r = uv_run(uv_default_loop());
390
+ ASSERT(r == 0);
391
+
392
+ ASSERT(exit_cb_called == 0);
393
+
394
+ err = uv_kill(process.pid, 0);
395
+ ASSERT(err.code == 0);
396
+
397
+ err = uv_kill(process.pid, 15);
398
+ ASSERT(err.code == 0);
399
+
400
+ return 0;
401
+ }
402
+
403
+ TEST_IMPL(spawn_and_kill_with_std) {
404
+ int r;
405
+ uv_pipe_t in, out, err;
406
+ uv_write_t write;
407
+ char message[] = "Nancy's joining me because the message this evening is "
408
+ "not my message but ours.";
409
+ uv_buf_t buf;
410
+ uv_stdio_container_t stdio[3];
411
+
412
+ init_process_options("spawn_helper4", kill_cb);
413
+
414
+ r = uv_pipe_init(uv_default_loop(), &in, 0);
415
+ ASSERT(r == 0);
416
+
417
+ r = uv_pipe_init(uv_default_loop(), &out, 0);
418
+ ASSERT(r == 0);
419
+
420
+ r = uv_pipe_init(uv_default_loop(), &err, 0);
421
+ ASSERT(r == 0);
422
+
423
+ options.stdio = stdio;
424
+ options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
425
+ options.stdio[0].data.stream = (uv_stream_t*)&in;
426
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
427
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
428
+ options.stdio[2].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
429
+ options.stdio[2].data.stream = (uv_stream_t*)&err;
430
+ options.stdio_count = 3;
431
+
432
+ r = uv_spawn(uv_default_loop(), &process, options);
433
+ ASSERT(r == 0);
434
+
435
+ buf = uv_buf_init(message, sizeof message);
436
+ r = uv_write(&write, (uv_stream_t*) &in, &buf, 1, write_cb);
437
+ ASSERT(r == 0);
438
+
439
+ r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
440
+ ASSERT(r == 0);
441
+
442
+ r = uv_read_start((uv_stream_t*) &err, on_alloc, on_read);
443
+ ASSERT(r == 0);
444
+
445
+ r = uv_timer_init(uv_default_loop(), &timer);
446
+ ASSERT(r == 0);
447
+
448
+ r = uv_timer_start(&timer, timer_cb, 500, 0);
449
+ ASSERT(r == 0);
450
+
451
+ r = uv_run(uv_default_loop());
452
+ ASSERT(r == 0);
453
+
454
+ ASSERT(exit_cb_called == 1);
455
+ ASSERT(close_cb_called == 5); /* process x 1, timer x 1, stdio x 3. */
456
+
457
+ return 0;
458
+ }
459
+
460
+
461
+ TEST_IMPL(spawn_and_ping) {
462
+ uv_write_t write_req;
463
+ uv_pipe_t in, out;
464
+ uv_buf_t buf;
465
+ uv_stdio_container_t stdio[2];
466
+ int r;
467
+
468
+ init_process_options("spawn_helper3", exit_cb);
469
+ buf = uv_buf_init("TEST", 4);
470
+
471
+ uv_pipe_init(uv_default_loop(), &out, 0);
472
+ uv_pipe_init(uv_default_loop(), &in, 0);
473
+ options.stdio = stdio;
474
+ options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
475
+ options.stdio[0].data.stream = (uv_stream_t*)&in;
476
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
477
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
478
+ options.stdio_count = 2;
479
+
480
+ r = uv_spawn(uv_default_loop(), &process, options);
481
+ ASSERT(r == 0);
482
+
483
+ /* Sending signum == 0 should check if the
484
+ * child process is still alive, not kill it.
485
+ */
486
+ r = uv_process_kill(&process, 0);
487
+ ASSERT(r == 0);
488
+
489
+ r = uv_write(&write_req, (uv_stream_t*)&in, &buf, 1, write_cb);
490
+ ASSERT(r == 0);
491
+
492
+ r = uv_read_start((uv_stream_t*)&out, on_alloc, on_read);
493
+ ASSERT(r == 0);
494
+
495
+ ASSERT(exit_cb_called == 0);
496
+
497
+ r = uv_run(uv_default_loop());
498
+ ASSERT(r == 0);
499
+
500
+ ASSERT(exit_cb_called == 1);
501
+ ASSERT(strcmp(output, "TEST") == 0);
502
+
503
+ return 0;
504
+ }
505
+
506
+
507
+ TEST_IMPL(kill) {
508
+ int r;
509
+ uv_err_t err;
510
+
511
+ #ifdef _WIN32
512
+ no_term_signal = 1;
513
+ #endif
514
+
515
+ init_process_options("spawn_helper4", kill_cb);
516
+
517
+ r = uv_spawn(uv_default_loop(), &process, options);
518
+ ASSERT(r == 0);
519
+
520
+ /* Sending signum == 0 should check if the
521
+ * child process is still alive, not kill it.
522
+ */
523
+ err = uv_kill(process.pid, 0);
524
+ ASSERT(err.code == UV_OK);
525
+
526
+ /* Kill the process. */
527
+ err = uv_kill(process.pid, /* SIGTERM */ 15);
528
+ ASSERT(err.code == UV_OK);
529
+
530
+ r = uv_run(uv_default_loop());
531
+ ASSERT(r == 0);
532
+
533
+ ASSERT(exit_cb_called == 1);
534
+ ASSERT(close_cb_called == 1);
535
+
536
+ return 0;
537
+ }
538
+
539
+
540
+ #ifdef _WIN32
541
+ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) {
542
+ int r;
543
+ uv_pipe_t out;
544
+ char name[64];
545
+ HANDLE pipe_handle;
546
+ uv_stdio_container_t stdio[2];
547
+
548
+ init_process_options("spawn_helper2", exit_cb);
549
+
550
+ uv_pipe_init(uv_default_loop(), &out, 0);
551
+ options.stdio = stdio;
552
+ options.stdio[0].flags = UV_IGNORE;
553
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
554
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
555
+ options.stdio_count = 2;
556
+
557
+ /* Create a pipe that'll cause a collision. */
558
+ _snprintf(name, sizeof(name), "\\\\.\\pipe\\uv\\%p-%d", &out, GetCurrentProcessId());
559
+ pipe_handle = CreateNamedPipeA(name,
560
+ PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
561
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
562
+ 10,
563
+ 65536,
564
+ 65536,
565
+ 0,
566
+ NULL);
567
+ ASSERT(pipe_handle != INVALID_HANDLE_VALUE);
568
+
569
+ r = uv_spawn(uv_default_loop(), &process, options);
570
+ ASSERT(r == 0);
571
+
572
+ r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
573
+ ASSERT(r == 0);
574
+
575
+ r = uv_run(uv_default_loop());
576
+ ASSERT(r == 0);
577
+
578
+ ASSERT(exit_cb_called == 1);
579
+ ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */
580
+ printf("output is: %s", output);
581
+ ASSERT(strcmp("hello world\n", output) == 0);
582
+
583
+ return 0;
584
+ }
585
+
586
+
587
+ wchar_t* make_program_args(char** args, int verbatim_arguments);
588
+ wchar_t* quote_cmd_arg(const wchar_t *source, wchar_t *target);
589
+
590
+ TEST_IMPL(argument_escaping) {
591
+ const wchar_t* test_str[] = {
592
+ L"HelloWorld",
593
+ L"Hello World",
594
+ L"Hello\"World",
595
+ L"Hello World\\",
596
+ L"Hello\\\"World",
597
+ L"Hello\\World",
598
+ L"Hello\\\\World",
599
+ L"Hello World\\",
600
+ L"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\""
601
+ };
602
+ const int count = sizeof(test_str) / sizeof(*test_str);
603
+ wchar_t** test_output;
604
+ wchar_t* command_line;
605
+ wchar_t** cracked;
606
+ size_t total_size = 0;
607
+ int i;
608
+ int num_args;
609
+
610
+ char* verbatim[] = {
611
+ "cmd.exe",
612
+ "/c",
613
+ "c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"",
614
+ NULL
615
+ };
616
+ wchar_t* verbatim_output;
617
+ wchar_t* non_verbatim_output;
618
+
619
+ test_output = calloc(count, sizeof(wchar_t*));
620
+ for (i = 0; i < count; ++i) {
621
+ test_output[i] = calloc(2 * (wcslen(test_str[i]) + 2), sizeof(wchar_t));
622
+ quote_cmd_arg(test_str[i], test_output[i]);
623
+ wprintf(L"input : %s\n", test_str[i]);
624
+ wprintf(L"output: %s\n", test_output[i]);
625
+ total_size += wcslen(test_output[i]) + 1;
626
+ }
627
+ command_line = calloc(total_size + 1, sizeof(wchar_t));
628
+ for (i = 0; i < count; ++i) {
629
+ wcscat(command_line, test_output[i]);
630
+ wcscat(command_line, L" ");
631
+ }
632
+ command_line[total_size - 1] = L'\0';
633
+
634
+ wprintf(L"command_line: %s\n", command_line);
635
+
636
+ cracked = CommandLineToArgvW(command_line, &num_args);
637
+ for (i = 0; i < num_args; ++i) {
638
+ wprintf(L"%d: %s\t%s\n", i, test_str[i], cracked[i]);
639
+ ASSERT(wcscmp(test_str[i], cracked[i]) == 0);
640
+ }
641
+
642
+ LocalFree(cracked);
643
+ for (i = 0; i < count; ++i) {
644
+ free(test_output[i]);
645
+ }
646
+
647
+ verbatim_output = make_program_args(verbatim, 1);
648
+ non_verbatim_output = make_program_args(verbatim, 0);
649
+
650
+ wprintf(L" verbatim_output: %s\n", verbatim_output);
651
+ wprintf(L"non_verbatim_output: %s\n", non_verbatim_output);
652
+
653
+ ASSERT(wcscmp(verbatim_output, L"cmd.exe /c c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"") == 0);
654
+ ASSERT(wcscmp(non_verbatim_output, L"cmd.exe /c \"c:\\path\\to\\node.exe --eval \\\"require('c:\\\\path\\\\to\\\\test.js')\\\"\"") == 0);
655
+
656
+ free(verbatim_output);
657
+ free(non_verbatim_output);
658
+
659
+ return 0;
660
+ }
661
+
662
+ wchar_t* make_program_env(char** env_block);
663
+
664
+ TEST_IMPL(environment_creation) {
665
+ int i;
666
+ char* environment[] = {
667
+ "FOO=BAR",
668
+ "SYSTEM=ROOT", /* substring of a supplied var name */
669
+ "SYSTEMROOTED=OMG", /* supplied var name is a substring */
670
+ "TEMP=C:\\Temp",
671
+ "BAZ=QUX",
672
+ NULL
673
+ };
674
+
675
+ wchar_t expected[512];
676
+ wchar_t* ptr = expected;
677
+ wchar_t* result;
678
+ wchar_t* str;
679
+
680
+ for (i = 0; i < sizeof(environment) / sizeof(environment[0]) - 1; i++) {
681
+ ptr += uv_utf8_to_utf16(environment[i], ptr, expected + sizeof(expected) - ptr);
682
+ }
683
+
684
+ memcpy(ptr, L"SYSTEMROOT=", sizeof(L"SYSTEMROOT="));
685
+ ptr += sizeof(L"SYSTEMROOT=")/sizeof(wchar_t) - 1;
686
+ ptr += GetEnvironmentVariableW(L"SYSTEMROOT", ptr, expected + sizeof(expected) - ptr);
687
+ ++ptr;
688
+
689
+ memcpy(ptr, L"SYSTEMDRIVE=", sizeof(L"SYSTEMDRIVE="));
690
+ ptr += sizeof(L"SYSTEMDRIVE=")/sizeof(wchar_t) - 1;
691
+ ptr += GetEnvironmentVariableW(L"SYSTEMDRIVE", ptr, expected + sizeof(expected) - ptr);
692
+ ++ptr;
693
+ *ptr = '\0';
694
+
695
+ result = make_program_env(environment);
696
+
697
+ for (str = result; *str; str += wcslen(str) + 1) {
698
+ wprintf(L"%s\n", str);
699
+ }
700
+
701
+ ASSERT(wcscmp(expected, result) == 0);
702
+
703
+ return 0;
704
+ }
705
+ #endif
706
+
707
+ #ifndef _WIN32
708
+ TEST_IMPL(spawn_setuid_setgid) {
709
+ int r;
710
+
711
+ /* if not root, then this will fail. */
712
+ uv_uid_t uid = getuid();
713
+ if (uid != 0) {
714
+ fprintf(stderr, "spawn_setuid_setgid skipped: not root\n");
715
+ return 0;
716
+ }
717
+
718
+ init_process_options("spawn_helper1", exit_cb);
719
+
720
+ /* become the "nobody" user. */
721
+ struct passwd* pw;
722
+ pw = getpwnam("nobody");
723
+ ASSERT(pw != NULL);
724
+ options.uid = pw->pw_uid;
725
+ options.gid = pw->pw_gid;
726
+ options.flags = UV_PROCESS_SETUID | UV_PROCESS_SETGID;
727
+
728
+ r = uv_spawn(uv_default_loop(), &process, options);
729
+ ASSERT(r == 0);
730
+
731
+ r = uv_run(uv_default_loop());
732
+ ASSERT(r == 0);
733
+
734
+ ASSERT(exit_cb_called == 1);
735
+ ASSERT(close_cb_called == 1);
736
+
737
+ return 0;
738
+ }
739
+ #endif
740
+
741
+
742
+ #ifndef _WIN32
743
+ TEST_IMPL(spawn_setuid_fails) {
744
+ int r;
745
+
746
+ /* if root, become nobody. */
747
+ uv_uid_t uid = getuid();
748
+ if (uid == 0) {
749
+ struct passwd* pw;
750
+ pw = getpwnam("nobody");
751
+ ASSERT(pw != NULL);
752
+ r = setuid(pw->pw_uid);
753
+ ASSERT(r == 0);
754
+ }
755
+
756
+ init_process_options("spawn_helper1", exit_cb_failure_expected);
757
+
758
+ options.flags |= UV_PROCESS_SETUID;
759
+ options.uid = (uv_uid_t) -42424242;
760
+
761
+ r = uv_spawn(uv_default_loop(), &process, options);
762
+ ASSERT(r == 0);
763
+
764
+ r = uv_run(uv_default_loop());
765
+ ASSERT(r == 0);
766
+
767
+ ASSERT(exit_cb_called == 1);
768
+ ASSERT(close_cb_called == 1);
769
+
770
+ return 0;
771
+ }
772
+
773
+
774
+ TEST_IMPL(spawn_setgid_fails) {
775
+ int r;
776
+
777
+ /* if root, become nobody. */
778
+ uv_uid_t uid = getuid();
779
+ if (uid == 0) {
780
+ struct passwd* pw;
781
+ pw = getpwnam("nobody");
782
+ ASSERT(pw != NULL);
783
+ r = setuid(pw->pw_uid);
784
+ ASSERT(r == 0);
785
+ }
786
+
787
+ init_process_options("spawn_helper1", exit_cb_failure_expected);
788
+
789
+ options.flags |= UV_PROCESS_SETGID;
790
+ options.gid = (uv_gid_t) -42424242;
791
+
792
+ r = uv_spawn(uv_default_loop(), &process, options);
793
+ ASSERT(r == 0);
794
+
795
+ r = uv_run(uv_default_loop());
796
+ ASSERT(r == 0);
797
+
798
+ ASSERT(exit_cb_called == 1);
799
+ ASSERT(close_cb_called == 1);
800
+
801
+ return 0;
802
+ }
803
+ #endif
804
+
805
+
806
+ #ifdef _WIN32
807
+ TEST_IMPL(spawn_setuid_fails) {
808
+ int r;
809
+
810
+ init_process_options("spawn_helper1", exit_cb_unexpected);
811
+
812
+ options.flags |= UV_PROCESS_SETUID;
813
+ options.uid = (uv_uid_t) -42424242;
814
+
815
+ r = uv_spawn(uv_default_loop(), &process, options);
816
+ ASSERT(r == -1);
817
+ ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSUP);
818
+
819
+ r = uv_run(uv_default_loop());
820
+ ASSERT(r == 0);
821
+
822
+ ASSERT(close_cb_called == 0);
823
+
824
+ return 0;
825
+ }
826
+
827
+
828
+ TEST_IMPL(spawn_setgid_fails) {
829
+ int r;
830
+
831
+ init_process_options("spawn_helper1", exit_cb_unexpected);
832
+
833
+ options.flags |= UV_PROCESS_SETGID;
834
+ options.gid = (uv_gid_t) -42424242;
835
+
836
+ r = uv_spawn(uv_default_loop(), &process, options);
837
+ ASSERT(r == -1);
838
+ ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSUP);
839
+
840
+ r = uv_run(uv_default_loop());
841
+ ASSERT(r == 0);
842
+
843
+ ASSERT(close_cb_called == 0);
844
+
845
+ return 0;
846
+ }
847
+ #endif