unicorn-fotopedia 0.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. data/.CHANGELOG.old +25 -0
  2. data/.document +19 -0
  3. data/.gitignore +21 -0
  4. data/.mailmap +26 -0
  5. data/CONTRIBUTORS +32 -0
  6. data/COPYING +339 -0
  7. data/DESIGN +105 -0
  8. data/Documentation/.gitignore +5 -0
  9. data/Documentation/GNUmakefile +30 -0
  10. data/Documentation/unicorn.1.txt +171 -0
  11. data/Documentation/unicorn_rails.1.txt +172 -0
  12. data/FAQ +52 -0
  13. data/GIT-VERSION-GEN +40 -0
  14. data/GNUmakefile +292 -0
  15. data/HACKING +116 -0
  16. data/ISSUES +36 -0
  17. data/KNOWN_ISSUES +50 -0
  18. data/LICENSE +55 -0
  19. data/PHILOSOPHY +145 -0
  20. data/README +149 -0
  21. data/Rakefile +191 -0
  22. data/SIGNALS +109 -0
  23. data/Sandbox +78 -0
  24. data/TODO +5 -0
  25. data/TUNING +70 -0
  26. data/bin/unicorn +126 -0
  27. data/bin/unicorn_rails +203 -0
  28. data/examples/big_app_gc.rb +33 -0
  29. data/examples/echo.ru +27 -0
  30. data/examples/git.ru +13 -0
  31. data/examples/init.sh +58 -0
  32. data/examples/logger_mp_safe.rb +25 -0
  33. data/examples/nginx.conf +139 -0
  34. data/examples/unicorn.conf.rb +78 -0
  35. data/ext/unicorn_http/CFLAGS +13 -0
  36. data/ext/unicorn_http/c_util.h +124 -0
  37. data/ext/unicorn_http/common_field_optimization.h +111 -0
  38. data/ext/unicorn_http/ext_help.h +77 -0
  39. data/ext/unicorn_http/extconf.rb +14 -0
  40. data/ext/unicorn_http/global_variables.h +89 -0
  41. data/ext/unicorn_http/unicorn_http.rl +714 -0
  42. data/ext/unicorn_http/unicorn_http_common.rl +75 -0
  43. data/lib/unicorn.rb +847 -0
  44. data/lib/unicorn/app/exec_cgi.rb +150 -0
  45. data/lib/unicorn/app/inetd.rb +109 -0
  46. data/lib/unicorn/app/old_rails.rb +33 -0
  47. data/lib/unicorn/app/old_rails/static.rb +58 -0
  48. data/lib/unicorn/cgi_wrapper.rb +145 -0
  49. data/lib/unicorn/configurator.rb +421 -0
  50. data/lib/unicorn/const.rb +34 -0
  51. data/lib/unicorn/http_request.rb +72 -0
  52. data/lib/unicorn/http_response.rb +75 -0
  53. data/lib/unicorn/launcher.rb +65 -0
  54. data/lib/unicorn/oob_gc.rb +58 -0
  55. data/lib/unicorn/socket_helper.rb +152 -0
  56. data/lib/unicorn/tee_input.rb +217 -0
  57. data/lib/unicorn/util.rb +90 -0
  58. data/local.mk.sample +62 -0
  59. data/setup.rb +1586 -0
  60. data/t/.gitignore +2 -0
  61. data/t/GNUmakefile +67 -0
  62. data/t/README +42 -0
  63. data/t/bin/content-md5-put +36 -0
  64. data/t/bin/sha1sum.rb +23 -0
  65. data/t/bin/unused_listen +40 -0
  66. data/t/bin/utee +12 -0
  67. data/t/env.ru +3 -0
  68. data/t/my-tap-lib.sh +200 -0
  69. data/t/t0000-http-basic.sh +50 -0
  70. data/t/t0001-reload-bad-config.sh +52 -0
  71. data/t/t0002-config-conflict.sh +49 -0
  72. data/t/test-lib.sh +100 -0
  73. data/test/aggregate.rb +15 -0
  74. data/test/benchmark/README +50 -0
  75. data/test/benchmark/dd.ru +18 -0
  76. data/test/exec/README +5 -0
  77. data/test/exec/test_exec.rb +1038 -0
  78. data/test/rails/app-1.2.3/.gitignore +2 -0
  79. data/test/rails/app-1.2.3/Rakefile +7 -0
  80. data/test/rails/app-1.2.3/app/controllers/application.rb +6 -0
  81. data/test/rails/app-1.2.3/app/controllers/foo_controller.rb +36 -0
  82. data/test/rails/app-1.2.3/app/helpers/application_helper.rb +4 -0
  83. data/test/rails/app-1.2.3/config/boot.rb +11 -0
  84. data/test/rails/app-1.2.3/config/database.yml +12 -0
  85. data/test/rails/app-1.2.3/config/environment.rb +13 -0
  86. data/test/rails/app-1.2.3/config/environments/development.rb +9 -0
  87. data/test/rails/app-1.2.3/config/environments/production.rb +5 -0
  88. data/test/rails/app-1.2.3/config/routes.rb +6 -0
  89. data/test/rails/app-1.2.3/db/.gitignore +0 -0
  90. data/test/rails/app-1.2.3/public/404.html +1 -0
  91. data/test/rails/app-1.2.3/public/500.html +1 -0
  92. data/test/rails/app-2.0.2/.gitignore +2 -0
  93. data/test/rails/app-2.0.2/Rakefile +7 -0
  94. data/test/rails/app-2.0.2/app/controllers/application.rb +4 -0
  95. data/test/rails/app-2.0.2/app/controllers/foo_controller.rb +36 -0
  96. data/test/rails/app-2.0.2/app/helpers/application_helper.rb +4 -0
  97. data/test/rails/app-2.0.2/config/boot.rb +11 -0
  98. data/test/rails/app-2.0.2/config/database.yml +12 -0
  99. data/test/rails/app-2.0.2/config/environment.rb +17 -0
  100. data/test/rails/app-2.0.2/config/environments/development.rb +8 -0
  101. data/test/rails/app-2.0.2/config/environments/production.rb +5 -0
  102. data/test/rails/app-2.0.2/config/routes.rb +6 -0
  103. data/test/rails/app-2.0.2/db/.gitignore +0 -0
  104. data/test/rails/app-2.0.2/public/404.html +1 -0
  105. data/test/rails/app-2.0.2/public/500.html +1 -0
  106. data/test/rails/app-2.1.2/.gitignore +2 -0
  107. data/test/rails/app-2.1.2/Rakefile +7 -0
  108. data/test/rails/app-2.1.2/app/controllers/application.rb +4 -0
  109. data/test/rails/app-2.1.2/app/controllers/foo_controller.rb +36 -0
  110. data/test/rails/app-2.1.2/app/helpers/application_helper.rb +4 -0
  111. data/test/rails/app-2.1.2/config/boot.rb +111 -0
  112. data/test/rails/app-2.1.2/config/database.yml +12 -0
  113. data/test/rails/app-2.1.2/config/environment.rb +17 -0
  114. data/test/rails/app-2.1.2/config/environments/development.rb +7 -0
  115. data/test/rails/app-2.1.2/config/environments/production.rb +5 -0
  116. data/test/rails/app-2.1.2/config/routes.rb +6 -0
  117. data/test/rails/app-2.1.2/db/.gitignore +0 -0
  118. data/test/rails/app-2.1.2/public/404.html +1 -0
  119. data/test/rails/app-2.1.2/public/500.html +1 -0
  120. data/test/rails/app-2.2.2/.gitignore +2 -0
  121. data/test/rails/app-2.2.2/Rakefile +7 -0
  122. data/test/rails/app-2.2.2/app/controllers/application.rb +4 -0
  123. data/test/rails/app-2.2.2/app/controllers/foo_controller.rb +36 -0
  124. data/test/rails/app-2.2.2/app/helpers/application_helper.rb +4 -0
  125. data/test/rails/app-2.2.2/config/boot.rb +111 -0
  126. data/test/rails/app-2.2.2/config/database.yml +12 -0
  127. data/test/rails/app-2.2.2/config/environment.rb +17 -0
  128. data/test/rails/app-2.2.2/config/environments/development.rb +7 -0
  129. data/test/rails/app-2.2.2/config/environments/production.rb +5 -0
  130. data/test/rails/app-2.2.2/config/routes.rb +6 -0
  131. data/test/rails/app-2.2.2/db/.gitignore +0 -0
  132. data/test/rails/app-2.2.2/public/404.html +1 -0
  133. data/test/rails/app-2.2.2/public/500.html +1 -0
  134. data/test/rails/app-2.3.5/.gitignore +2 -0
  135. data/test/rails/app-2.3.5/Rakefile +7 -0
  136. data/test/rails/app-2.3.5/app/controllers/application_controller.rb +5 -0
  137. data/test/rails/app-2.3.5/app/controllers/foo_controller.rb +36 -0
  138. data/test/rails/app-2.3.5/app/helpers/application_helper.rb +4 -0
  139. data/test/rails/app-2.3.5/config/boot.rb +109 -0
  140. data/test/rails/app-2.3.5/config/database.yml +12 -0
  141. data/test/rails/app-2.3.5/config/environment.rb +17 -0
  142. data/test/rails/app-2.3.5/config/environments/development.rb +7 -0
  143. data/test/rails/app-2.3.5/config/environments/production.rb +6 -0
  144. data/test/rails/app-2.3.5/config/routes.rb +6 -0
  145. data/test/rails/app-2.3.5/db/.gitignore +0 -0
  146. data/test/rails/app-2.3.5/public/404.html +1 -0
  147. data/test/rails/app-2.3.5/public/500.html +1 -0
  148. data/test/rails/app-2.3.5/public/x.txt +1 -0
  149. data/test/rails/test_rails.rb +280 -0
  150. data/test/test_helper.rb +301 -0
  151. data/test/unit/test_configurator.rb +150 -0
  152. data/test/unit/test_http_parser.rb +555 -0
  153. data/test/unit/test_http_parser_ng.rb +443 -0
  154. data/test/unit/test_request.rb +184 -0
  155. data/test/unit/test_response.rb +110 -0
  156. data/test/unit/test_server.rb +291 -0
  157. data/test/unit/test_signals.rb +206 -0
  158. data/test/unit/test_socket_helper.rb +147 -0
  159. data/test/unit/test_tee_input.rb +257 -0
  160. data/test/unit/test_upload.rb +298 -0
  161. data/test/unit/test_util.rb +96 -0
  162. data/unicorn.gemspec +52 -0
  163. metadata +283 -0
@@ -0,0 +1,33 @@
1
+ # Run GC after every request, before attempting to accept more connections.
2
+ #
3
+ # You could customize this patch to read REQ["PATH_INFO"] and only
4
+ # call GC.start after expensive requests.
5
+ #
6
+ # We could have this wrap the response body.close as middleware, but the
7
+ # scannable stack is would still be bigger than it would be here.
8
+ #
9
+ # This shouldn't hurt overall performance as long as the server cluster
10
+ # is at <=50% CPU capacity, and improves the performance of most memory
11
+ # intensive requests. This serves to improve _client-visible_
12
+ # performance (possibly at the cost of overall performance).
13
+ #
14
+ # We'll call GC after each request is been written out to the socket, so
15
+ # the client never sees the extra GC hit it. It's ideal to call the GC
16
+ # inside the HTTP server (vs middleware or hooks) since the stack is
17
+ # smaller at this point, so the GC will both be faster and more
18
+ # effective at releasing unused memory.
19
+ #
20
+ # This monkey patch is _only_ effective for applications that use a lot
21
+ # of memory, and will hurt simpler apps/endpoints that can process
22
+ # multiple requests before incurring GC.
23
+
24
+ class Unicorn::HttpServer
25
+ REQ = Unicorn::HttpRequest::REQ
26
+ alias _process_client process_client
27
+ undef_method :process_client
28
+ def process_client(client)
29
+ _process_client(client)
30
+ REQ.clear
31
+ GC.start
32
+ end
33
+ end if defined?(Unicorn)
@@ -0,0 +1,27 @@
1
+ #\-E none
2
+ #
3
+ # Example application that echoes read data back to the HTTP client.
4
+ # This emulates the old echo protocol people used to run.
5
+ #
6
+ # An example of using this in a client would be to run:
7
+ # curl --no-buffer -T- http://host:port/
8
+ #
9
+ # Then type random stuff in your terminal to watch it get echoed back!
10
+
11
+ class EchoBody < Struct.new(:input)
12
+
13
+ def each(&block)
14
+ while buf = input.read(4096)
15
+ yield buf
16
+ end
17
+ self
18
+ end
19
+
20
+ end
21
+
22
+ use Rack::Chunked
23
+ run lambda { |env|
24
+ /\A100-continue\z/i =~ env['HTTP_EXPECT'] and return [100, {}, []]
25
+ [ 200, { 'Content-Type' => 'application/octet-stream' },
26
+ EchoBody.new(env['rack.input']) ]
27
+ }
@@ -0,0 +1,13 @@
1
+ #\-E none
2
+
3
+ # See http://thread.gmane.org/gmane.comp.web.curl.general/10473/raw on
4
+ # how to setup git for this. A better version of the above patch was
5
+ # accepted and committed on June 15, 2009, so you can pull the latest
6
+ # curl CVS snapshot to try this out.
7
+ require 'unicorn/app/inetd'
8
+
9
+ use Rack::Lint
10
+ use Rack::Chunked # important!
11
+ run Unicorn::App::Inetd.new(
12
+ *%w(git daemon --verbose --inetd --export-all --base-path=/home/ew/unicorn)
13
+ )
@@ -0,0 +1,58 @@
1
+ #!/bin/sh
2
+ set -e
3
+ # Example init script, this can be used with nginx, too,
4
+ # since nginx and unicorn accept the same signals
5
+
6
+ # Feel free to change any of the following variables for your app:
7
+ APP_ROOT=/home/x/my_app/current
8
+ PID=$APP_ROOT/tmp/pids/unicorn.pid
9
+ CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
10
+ INIT_CONF=$APP_ROOT/config/init.conf
11
+ action="$1"
12
+ set -u
13
+
14
+ test -f "$INIT_CONF" && . $INIT_CONF
15
+
16
+ old_pid="$PID.oldbin"
17
+
18
+ cd $APP_ROOT || exit 1
19
+
20
+ sig () {
21
+ test -s "$PID" && kill -$1 `cat $PID`
22
+ }
23
+
24
+ oldsig () {
25
+ test -s $old_pid && kill -$1 `cat $old_pid`
26
+ }
27
+
28
+ case $action in
29
+ start)
30
+ sig 0 && echo >&2 "Already running" && exit 0
31
+ $CMD
32
+ ;;
33
+ stop)
34
+ sig QUIT && exit 0
35
+ echo >&2 "Not running"
36
+ ;;
37
+ force-stop)
38
+ sig TERM && exit 0
39
+ echo >&2 "Not running"
40
+ ;;
41
+ restart|reload)
42
+ sig HUP && echo reloaded OK && exit 0
43
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
44
+ $CMD
45
+ ;;
46
+ upgrade)
47
+ sig USR2 && sleep 2 && sig 0 && oldsig QUIT && exit 0
48
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
49
+ $CMD
50
+ ;;
51
+ reopen-logs)
52
+ sig USR1
53
+ ;;
54
+ *)
55
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
56
+ exit 1
57
+ ;;
58
+ esac
@@ -0,0 +1,25 @@
1
+ # Multi-Processing-safe monkey patch for Logger
2
+ #
3
+ # This monkey patch fixes the case where "preload_app true" is used and
4
+ # the application spawns a background thread upon being loaded.
5
+ #
6
+ # This removes all lock from the Logger code and solely relies on the
7
+ # underlying filesystem to handle write(2) system calls atomically when
8
+ # O_APPEND is used. This is safe in the presence of both multiple
9
+ # threads (native or green) and multiple processes when writing to
10
+ # a filesystem with POSIX O_APPEND semantics.
11
+ #
12
+ # It should be noted that the original locking on Logger could _never_ be
13
+ # considered reliable on non-POSIX filesystems with multiple processes,
14
+ # either, so nothing is lost in that case.
15
+
16
+ require 'logger'
17
+ class Logger::LogDevice
18
+ def write(message)
19
+ @dev.syswrite(message)
20
+ end
21
+
22
+ def close
23
+ @dev.close
24
+ end
25
+ end
@@ -0,0 +1,139 @@
1
+ # This is example contains the bare mininum to get nginx going with
2
+ # Unicorn or Rainbows! servers. Generally these configuration settings
3
+ # are applicable to other HTTP application servers (and not just Ruby
4
+ # ones), so if you have one working well for proxying another app
5
+ # server, feel free to continue using it.
6
+ #
7
+ # The only setting we feel strongly about is the fail_timeout=0
8
+ # directive in the "upstream" block. max_fails=0 also has the same
9
+ # effect as fail_timeout=0 for current versions of nginx and may be
10
+ # used in its place.
11
+ #
12
+ # Users are strongly encouraged to refer to nginx documentation for more
13
+ # details and search for other example configs.
14
+
15
+ # you generally only need one nginx worker unless you're serving
16
+ # large amounts of static files which require blocking disk reads
17
+ worker_processes 1;
18
+
19
+ # # drop privileges, root is needed on most systems for binding to port 80
20
+ # # (or anything < 1024). Capability-based security may be available for
21
+ # # your system and worth checking out so you won't need to be root to
22
+ # # start nginx to bind on 80
23
+ user nobody nogroup; # for systems with a "nogroup"
24
+ # user nobody nobody; # for systems with "nobody" as a group instead
25
+
26
+ # Feel free to change all paths to suite your needs here, of course
27
+ pid /tmp/nginx.pid;
28
+ error_log /tmp/nginx.error.log;
29
+
30
+ events {
31
+ worker_connections 1024; # increase if you have lots of clients
32
+ accept_mutex off; # "on" if nginx worker_processes > 1
33
+ # use epoll; # enable for Linux 2.6+
34
+ # use kqueue; # enable for FreeBSD, OSX
35
+ }
36
+
37
+ http {
38
+ # nginx will find this file in the config directory set at nginx build time
39
+ include mime.types;
40
+
41
+ # fallback in case we can't determine a type
42
+ default_type application/octet-stream;
43
+
44
+ # click tracking!
45
+ access_log /tmp/nginx.access.log combined;
46
+
47
+ # you generally want to serve static files with nginx since neither
48
+ # Unicorn nor Rainbows! is optimized for it at the moment
49
+ sendfile on;
50
+
51
+ tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
52
+ tcp_nodelay off; # on may be better for some Comet/long-poll stuff
53
+
54
+ # we haven't checked to see if Rack::Deflate on the app server is
55
+ # faster or not than doing compression via nginx. It's easier
56
+ # to configure it all in one place here for static files and also
57
+ # to disable gzip for clients who don't get gzip/deflate right.
58
+ # There are other other gzip settings that may be needed used to deal with
59
+ # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule
60
+ gzip on;
61
+ gzip_http_version 1.0;
62
+ gzip_proxied any;
63
+ gzip_min_length 500;
64
+ gzip_disable "MSIE [1-6]\.";
65
+ gzip_types text/plain text/html text/xml text/css
66
+ text/comma-separated-values
67
+ text/javascript application/x-javascript
68
+ application/atom+xml;
69
+
70
+ # this can be any application server, not just Unicorn/Rainbows!
71
+ upstream app_server {
72
+ # fail_timeout=0 means we always retry an upstream even if it failed
73
+ # to return a good HTTP response (in case the Unicorn master nukes a
74
+ # single worker for timing out).
75
+
76
+ # for UNIX domain socket setups:
77
+ server unix:/tmp/.sock fail_timeout=0;
78
+
79
+ # for TCP setups, point these to your backend servers
80
+ # server 192.168.0.7:8080 fail_timeout=0;
81
+ # server 192.168.0.8:8080 fail_timeout=0;
82
+ # server 192.168.0.9:8080 fail_timeout=0;
83
+ }
84
+
85
+ server {
86
+ # listen 80 default deferred; # for Linux
87
+ # listen 80 default accept_filter=httpready; # for FreeBSD
88
+ listen 80 default;
89
+
90
+ client_max_body_size 4G;
91
+ server_name _;
92
+
93
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
94
+ # retrieve needed images/icons/frames, connections are cheap in
95
+ # nginx so increasing this is generally safe...
96
+ keepalive_timeout 5;
97
+
98
+ # path for static files
99
+ root /path/to/app/current/public;
100
+
101
+ location / {
102
+ # an HTTP header important enough to have its own Wikipedia entry:
103
+ # http://en.wikipedia.org/wiki/X-Forwarded-For
104
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
105
+
106
+ # enable this if and only if you use HTTPS, this helps Rack
107
+ # set the proper protocol for doing redirects:
108
+ # proxy_set_header X-Forwarded-Proto https;
109
+
110
+ # pass the Host: header from the client right along so redirects
111
+ # can be set properly within the Rack application
112
+ proxy_set_header Host $http_host;
113
+
114
+ # we don't want nginx trying to do something clever with
115
+ # redirects, we set the Host: header above already.
116
+ proxy_redirect off;
117
+
118
+ # set "proxy_buffering off" *only* for Rainbows! when doing
119
+ # Comet/long-poll stuff. It's also safe to set if you're
120
+ # using only serving fast clients with Unicorn + nginx.
121
+ # Otherwise you _want_ nginx to buffer responses to slow
122
+ # clients, really.
123
+ # proxy_buffering off;
124
+
125
+ # Try to serve static files from nginx, no point in making an
126
+ # *application* server like Unicorn/Rainbows! serve static files.
127
+ if (!-f $request_filename) {
128
+ proxy_pass http://app_server;
129
+ break;
130
+ }
131
+ }
132
+
133
+ # Rails error pages
134
+ error_page 500 502 503 504 /500.html;
135
+ location = /500.html {
136
+ root /path/to/app/current/public;
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,78 @@
1
+ # Sample configuration file for Unicorn (not Rack)
2
+ #
3
+ # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
4
+ # documentation.
5
+
6
+ # Use at least one worker per core if you're on a dedicated server,
7
+ # more will usually help for _short_ waits on databases/caches.
8
+ worker_processes 4
9
+
10
+ # Help ensure your application will always spawn in the symlinked
11
+ # "current" directory that Capistrano sets up.
12
+ working_directory "/path/to/app/current" # available in 0.94.0+
13
+
14
+ # listen on both a Unix domain socket and a TCP port,
15
+ # we use a shorter backlog for quicker failover when busy
16
+ listen "/tmp/.sock", :backlog => 64
17
+ listen 8080, :tcp_nopush => true
18
+
19
+ # nuke workers after 30 seconds instead of 60 seconds (the default)
20
+ timeout 30
21
+
22
+ # feel free to point this anywhere accessible on the filesystem
23
+ pid "/path/to/app/shared/pids/unicorn.pid"
24
+
25
+ # some applications/frameworks log to stderr or stdout, so prevent
26
+ # them from going to /dev/null when daemonized here:
27
+ stderr_path "/path/to/app/shared/log/unicorn.stderr.log"
28
+ stdout_path "/path/to/app/shared/log/unicorn.stdout.log"
29
+
30
+ # combine REE with "preload_app true" for memory savings
31
+ # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
32
+ preload_app true
33
+ GC.respond_to?(:copy_on_write_friendly=) and
34
+ GC.copy_on_write_friendly = true
35
+
36
+ before_fork do |server, worker|
37
+ # the following is highly recomended for Rails + "preload_app true"
38
+ # as there's no need for the master process to hold a connection
39
+ defined?(ActiveRecord::Base) and
40
+ ActiveRecord::Base.connection.disconnect!
41
+
42
+ # The following is only recommended for memory/DB-constrained
43
+ # installations. It is not needed if your system can house
44
+ # twice as many worker_processes as you have configured.
45
+ #
46
+ # # This allows a new master process to incrementally
47
+ # # phase out the old master process with SIGTTOU to avoid a
48
+ # # thundering herd (especially in the "preload_app false" case)
49
+ # # when doing a transparent upgrade. The last worker spawned
50
+ # # will then kill off the old master process with a SIGQUIT.
51
+ # old_pid = "#{server.config[:pid]}.oldbin"
52
+ # if old_pid != server.pid
53
+ # begin
54
+ # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
55
+ # Process.kill(sig, File.read(old_pid).to_i)
56
+ # rescue Errno::ENOENT, Errno::ESRCH
57
+ # end
58
+ # end
59
+ #
60
+ # # *optionally* throttle the master from forking too quickly by sleeping
61
+ # sleep 1
62
+ end
63
+
64
+ after_fork do |server, worker|
65
+ # per-process listener ports for debugging/admin/migrations
66
+ # addr = "127.0.0.1:#{9293 + worker.nr}"
67
+ # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
68
+
69
+ # the following is *required* for Rails + "preload_app true",
70
+ defined?(ActiveRecord::Base) and
71
+ ActiveRecord::Base.establish_connection
72
+
73
+ # if preload_app is true, then you may also want to check and
74
+ # restart any other shared sockets/descriptors such as Memcached,
75
+ # and Redis. TokyoCabinet file handles are safe to reuse
76
+ # between any number of forked children (assuming your kernel
77
+ # correctly implements pread()/pwrite() system calls)
78
+ end
@@ -0,0 +1,13 @@
1
+ # CFLAGS used for development (gcc-dependent)
2
+ # source this file if you want/need them
3
+ CFLAGS=
4
+ CFLAGS="$CFLAGS -Wall"
5
+ CFLAGS="$CFLAGS -Wwrite-strings"
6
+ CFLAGS="$CFLAGS -Wdeclaration-after-statement"
7
+ CFLAGS="$CFLAGS -Wcast-qual"
8
+ CFLAGS="$CFLAGS -Wstrict-prototypes"
9
+ CFLAGS="$CFLAGS -Wshadow"
10
+ CFLAGS="$CFLAGS -Wextra"
11
+ CFLAGS="$CFLAGS -Wno-deprecated-declarations"
12
+ CFLAGS="$CFLAGS -Waggregate-return"
13
+ CFLAGS="$CFLAGS -Wchar-subscripts"
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Generic C functions and macros go here, there are no dependencies
3
+ * on Unicorn internal structures or the Ruby C API in here.
4
+ */
5
+
6
+ #ifndef UH_util_h
7
+ #define UH_util_h
8
+
9
+ #include <unistd.h>
10
+ #include <assert.h>
11
+
12
+ #define MIN(a,b) (a < b ? a : b)
13
+ #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
14
+
15
+ #ifndef SIZEOF_OFF_T
16
+ # define SIZEOF_OFF_T 4
17
+ # warning SIZEOF_OFF_T not defined, guessing 4. Did you run extconf.rb?
18
+ #endif
19
+
20
+ #if SIZEOF_OFF_T == 4
21
+ # define UH_OFF_T_MAX 0x7fffffff
22
+ #elif SIZEOF_OFF_T == 8
23
+ # if SIZEOF_LONG == 4
24
+ # define UH_OFF_T_MAX 0x7fffffffffffffffLL
25
+ # else
26
+ # define UH_OFF_T_MAX 0x7fffffffffffffff
27
+ # endif
28
+ #else
29
+ # error off_t size unknown for this platform!
30
+ #endif /* SIZEOF_OFF_T check */
31
+
32
+ /*
33
+ * ragel enforces fpc as a const, and merely casting can make picky
34
+ * compilers unhappy, so we have this little helper do our dirty work
35
+ */
36
+ static inline void *deconst(const void *in)
37
+ {
38
+ union { const void *in; void *out; } tmp;
39
+
40
+ tmp.in = in;
41
+
42
+ return tmp.out;
43
+ }
44
+
45
+ /*
46
+ * capitalizes all lower-case ASCII characters and converts dashes
47
+ * to underscores for HTTP headers. Locale-agnostic.
48
+ */
49
+ static void snake_upcase_char(char *c)
50
+ {
51
+ if (*c >= 'a' && *c <= 'z')
52
+ *c &= ~0x20;
53
+ else if (*c == '-')
54
+ *c = '_';
55
+ }
56
+
57
+ /* Downcases a single ASCII character. Locale-agnostic. */
58
+ static void downcase_char(char *c)
59
+ {
60
+ if (*c >= 'A' && *c <= 'Z')
61
+ *c |= 0x20;
62
+ }
63
+
64
+ static int hexchar2int(int xdigit)
65
+ {
66
+ if (xdigit >= 'A' && xdigit <= 'F')
67
+ return xdigit - 'A' + 10;
68
+ if (xdigit >= 'a' && xdigit <= 'f')
69
+ return xdigit - 'a' + 10;
70
+
71
+ /* Ragel already does runtime range checking for us in Unicorn: */
72
+ assert(xdigit >= '0' && xdigit <= '9' && "invalid digit character");
73
+
74
+ return xdigit - '0';
75
+ }
76
+
77
+ /*
78
+ * multiplies +i+ by +base+ and increments the result by the parsed
79
+ * integer value of +xdigit+. +xdigit+ is a character byte
80
+ * representing a number the range of 0..(base-1)
81
+ * returns the new value of +i+ on success
82
+ * returns -1 on errors (including overflow)
83
+ */
84
+ static off_t step_incr(off_t i, int xdigit, const int base)
85
+ {
86
+ static const off_t max = UH_OFF_T_MAX;
87
+ const off_t next_max = (max - (max % base)) / base;
88
+ off_t offset = hexchar2int(xdigit);
89
+
90
+ if (offset > (base - 1))
91
+ return -1;
92
+ if (i > next_max)
93
+ return -1;
94
+ i *= base;
95
+
96
+ if ((offset > (base - 1)) || ((max - i) < offset))
97
+ return -1;
98
+
99
+ return i + offset;
100
+ }
101
+
102
+ /*
103
+ * parses a non-negative length according to base-10 and
104
+ * returns it as an off_t value. Returns -1 on errors
105
+ * (including overflow).
106
+ */
107
+ static off_t parse_length(const char *value, size_t length)
108
+ {
109
+ off_t rv;
110
+
111
+ for (rv = 0; length-- && rv >= 0; ++value) {
112
+ if (*value >= '0' && *value <= '9')
113
+ rv = step_incr(rv, *value, 10);
114
+ else
115
+ return -1;
116
+ }
117
+
118
+ return rv;
119
+ }
120
+
121
+ #define CONST_MEM_EQ(const_p, buf, len) \
122
+ ((sizeof(const_p) - 1) == len && !memcmp(const_p, buf, sizeof(const_p) - 1))
123
+
124
+ #endif /* UH_util_h */