Make -N/--no-default-middleware option work

This fixes the -N (a.k.a. --no-defaut-middleware) option, which
was not working.  The problem was that Unicorn::Configurator::RACKUP
is cleared before the lambda returned by Unicorn.builder is run,
which means that checking whether the :no_default_middleware option
was set from the lambda could not detect anything.  This patch copies
it to a local variable that won't get clobbered, restoring the feature.

[ew: squashed test commit into the fix, whitespace fixes]

Signed-off-by: Eric Wong <normalperson@yhbt.net>
unicorn 4.6.3 - fix --no-default-middleware option

Thanks to Micah Chalmer for this fix.  There are also minor
documentation updates and internal cleanups.
http_server: improve handling of client-triggerable socket errors

We do not attempt to write HTTP responses for socket errors if
clients disconnect from us unexpectedly.

Additionally, we do not hide backtraces EINVAL/EBADF errors, since
they are indicative of real bugs which must be fixed.

We do continue to hide hide EOF, ECONNRESET, ENOTCONN, and EPIPE
because clients (even "friendly") ones will break connections due to
client crashes or network failure (which is common for me :P), and
the backtraces from those will cause excessive logging and even
become a DoS vector.
test_util: fix encoding test for Ruby trunk (2.1.0dev)

As of r40610 in ruby trunk, internal encoding is ignored if
external coding is ASCII-8BIT (binary)

ref: r40610 http://svn.ruby-lang.org/repos/ruby/trunk
Sandbox: document SIGUSR2 + bundler issue with 2.0.0

Thanks to Eric Chapweske for the heads up.

ref: http://mid.gmane.org/loom.20130904T205308-432@post.gmane.org
tests: upgrade several gems (rack, kgio, raindrops)

All tests seem to pass.
Rakefile: kill raa_update task

RAA is dead.
workaround reopen atomicity issues for stdio vs non-stdio

In multithreaded apps, we must use dup2/dup3 with a temporary
descriptor to reopen log files atomically.  This is the only way
to protect all concurrent userspace access to a file when reopening.

ref: http://bugs.ruby-lang.org/issues/9036
ref: yahns commit bcb10abe53cfb1d6a8ef7daef59eb10ced397c8a
attempt to rename PID file when possible

This will preserve mtime on successful renames for comparisions.
While we're at it, avoid writing the new PID until the listeners are
inherited successfully.  This can be useful to avoid accidentally
clobbering a good PID if binding the listener or building the app
(preload_app==true) fails
tests: limit oobgc check to accepted sockets

Otherwise these tests fail if we start using IO#autoclose=true
on Ruby 1.9 (and also if we use IPv6 sockets for tests).
support SO_REUSEPORT on new listeners (:reuseport)

This allows users to start an independent instance of unicorn on
a the same port as a running unicorn (as long as both instances
use :reuseport).

ref: https://lwn.net/Articles/542629/
avoid IO_PURGATORY on Ruby 1.9+

Ruby 1.9 and later includes IO#autoclose=, so we can use it
and prevent some dead IO objects from hanging around.
http_server: fixup comments for PID file renaming

Thanks to Hongli Lai for noticing my typo.  While we're at it, finish up
a halfway-written comment for the EXDEV case
license: allow all future versions of the GNU GPL

There is currently no GPLv4, so this change has no effect at the
moment.

In case the GPLv4 arrives and I am not alive to approve/review it,
the lesser of evils is have give blanket approval of all future GPL
versions (as published by the FSF).  The worse evil is to be stuck
with a license which cannot guarantee the Free-ness of this project
in the future.

This unfortunately means the FSF can theoretically come out with
license terms I do not agree with, but the GPLv2 and GPLv3 will
always be an option to all users.
configurator: validate :reuseport for boolean-ess

In case we (and Linux) supports other values in the future,
we can update it then.  Until now, ensure users only set
true or false for this option.
construct listener_fds Hash in 1.8.6 compatible way

This renables the ability for Ruby 1.8.6 environments to perform reexecs

[ew: clarified this is for 1.8.6,
 favor literal {} over Hash.new,
 tweaked LISTENERS.map => LISTENERS.each, thanks to Hleb Valoshka
]

Signed-off-by: Eric Wong <normalperson@yhbt.net>
bin/*: enforce -p/--port argument to be a valid integer

Users may confuse '-p' with the (to-be-deprecated) '-P/--pid'
option, leading to surprising behavior if a pathname is passed as a
port, because String#to_i would convert it to zero, causing:

    TCPServer.new(host, port = 0)

to bind to a random, unused port.
unicorn 4.7.0 - minor updates, license tweak

* support SO_REUSEPORT on new listeners (:reuseport)

  This allows users to start an independent instance of unicorn on
  a the same port as a running unicorn (as long as both instances
  use :reuseport).

  ref: https://lwn.net/Articles/542629/

* unicorn is now GPLv2-or-later and Ruby 1.8-licensed
  (instead of GPLv2-only, GPLv3-only, and Ruby 1.8-licensed)

  This changes nothing at the moment.  Once the FSF publishes the next
  version of the GPL, users may choose the newer GPL version without the
  unicorn BDFL approving it.  Two years ago when I got permission to add
  GPLv3 to the license options, I also got permission from all past
  contributors to approve future versions of the GPL.  So now I'm
  approving all future versions of the GPL for use with unicorn.

  Reasoning below:

  In case the GPLv4 arrives and I am not alive to approve/review it,
  the lesser of evils is have give blanket approval of all future GPL
  versions (as published by the FSF).  The worse evil is to be stuck
  with a license which cannot guarantee the Free-ness of this project
  in the future.

  This unfortunately means the FSF can theoretically come out with
  license terms I do not agree with, but the GPLv2 and GPLv3 will
  always be an option to all users.

  Note: we currently prefer GPLv3

Two improvements thanks to Ernest W. Durbin III:

* USR2 redirects fixed for Ruby 1.8.6 (broken since 4.1.0)
* unicorn(1) and unicorn_rails(1) enforces valid integer for -p/--port

A few more odd, minor tweaks and fixes:

* attempt to rename PID file when possible (on USR2)
* workaround reopen atomicity issues for stdio vs non-stdio
* improve handling of client-triggerable socket errors
tests: fix SO_REUSEPORT tests for old Linux and non-Linux

On BSD-derived platforms the getsockopt true value may be any
(>= 0) value, not just one as it is on Linux.

Additionally, SO_REUSEPORT is only supported since Linux 3.9, so
folks on older kernels may not have it available.  We still define it
for Linux since kernel upgrades are usually more common than glibc
upgrades.

Note: we will still raise an exception at runtime if a user
explicitly requests :reuseport in their config and runs an
older Linux kernel.

Reported-by: Andrew Hobson <ahobson@gmail.com>
stream_input: avoid IO#close on client disconnect

This can avoid IOError from being seen by the application, and also
reduces points where IO#close may be called.  This is a good thing
if we eventually port this code into a low-level server like
cmogstored where per-client memory space is defined by FD number of
a client.

Reported-by: Andrew Hobson <ahobson@gmail.com>