about summary refs log tree commit homepage
path: root/lib/unicorn/util.rb
DateCommit message (Collapse)
2024-03-31treewide: future-proof frozen_string_literal changes
Once again Ruby seems ready to introduce more incompatibilities and force busywork upon maintainers[1]. In order to avoid incompatibilities in the future, I used a Perl script[2] to prepend `frozen_string_literal: false' to every Ruby file. Somebody interested will have to go through every Ruby source file and enable frozen_string_literal once they've thoroughly verified it's safe to do so. [1] https://bugs.ruby-lang.org/issues/20205 [2] https://yhbt.net/add-fsl.git/74d7689/s/?b=add-fsl.perl
2018-10-18doc: update more URLs to use HTTPS and avoid redirects
Latency from redirects is painful, and HTTPS can protect privacy in some cases.
2018-05-01quiet some mismatched indentation warnings
Ruby trunk started warning about more mismatched indentations starting around r62836.
2015-07-15doc: remove references to old servers
They'll continue to be maintained, but we're no longer advertising them. Also, favor lowercase "unicorn" while we're at it since that matches the executable and gem name to avoid unnecessary escaping for RDoc.
2015-02-05favor IO#close_on_exec= over fcntl in 1.9+
IO#close_on_exec* methods are available since Ruby 1.9.1. It allows us to use less bytecode as it requires fewer operands and avoids constant lookups.
2013-10-20workaround 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
2012-10-01util: only consider regular files as logs
If a user specifies a non-regular file for stderr_path or stdout_path, we should not attempt to reopen or chown it. This should also allow users to specify FIFOs as log destinations.
2011-04-01util: allow relative paths to be rotated
Users keep both pieces if it's broken :)
2010-10-05util: uindent use less ambiguous constant scoping
This hopefully makes things easier to read and follow.
2010-10-05Unicorn::Util.tmpio => Unicorn::TmpIO.new
This is slightly shorter and hopefully easier to find.
2010-08-28make log reopens even more robust in threaded apps
A follow-up to 4b23693b9082a84433a9e6c1f358b58420176b27 If multithreaded programming can be compared to juggling chainsaws, then multithreaded programming with signal handlers in play is akin to juggling chainsaws on a tightrope over shark-infested waters.
2010-08-28make log reopens more robust in multithreaded apps
IOError may occur due to race conditions as another thread may close the file immediately after we call File#closed? to check. Errno::EBADF may occur in some applications that close a file descriptor without notifying Ruby (or if two IO objects refer to the same descriptor, possibly one of them using IO#for_fd).
2010-06-15workaround rbx not reopening logs to stderr/stdout
While log reopening worked reliably for newly-created File objects in the unit tests, the $stderr and $stdout handles that get redirected did not get reopened reliably under Rubinius. We work around this by relying on Rubinius internals and directly setting the @path instance variable. This is harmless for MRI and should be harmless for other any other Ruby implementations we'll eventually support. ref: http://github.com/evanphx/rubinius/issues/360
2010-06-11cleanup: use modules were applicable
No point in having namespaces be classes when we never create instances of them...
2010-06-08reopen_logs: no need to preserve encoding args
Since we accidentally dropped open_args a while back, nothing seems to have broken :x So apparently MRI preserves it for us, and test/unit/test_util.rb agrees.
2010-06-08reopen_logs: avoid modifying ObjectSpace while iterating
Creating File objects while iterating ObjectSpace for File objects may hit subtle bugs. It may only be safe in MRI, and even then it's not behavior that sounds sane to rely on. So stop doing it.
2010-06-08workaround IO#reopen bug in rbx when reopening logs
IO#reopen in Rubinius seems to munge the O_APPEND flag when passed a path, however passing an actual IO object. However, at the system call level, everything is the same. ref: http://github.com/evanphx/rubinius/issues/347
2010-02-22util: simplify chown_logs
no point in using "next" here
2009-11-14preserve user/group ownership when reopening logs
This is only supported when SIGUSR1 is sent only to the master process (which then resends SIGUSR1 to the workers). Since we only added support for user/group switching in the workers, we now chown any log files upon switching users so the master can pick up and chown the log files later on. Thus we can avoid having to restart workers because they fail to rotate log files on their own.
2009-11-05Util::tmpio returns a TmpIO that responds to #size
Subclass off the core File class so we don't have to worry about #size being defined. This will mainly be useful to Rainbows! but allows us to simplify our TeeInput implementation a little, too.
2009-11-03Util.reopen_logs: remove needless Range
?/ avoids allocating a String in 1.8 and in 1.9 short String objects are cheap.
2009-09-27util: remove APPEND_FLAGS constant
One less thing to RDoc
2009-09-08"encoding: binary" comments for all sources (1.9)
This ensures any string literals that pop up in *our* code will just be a bag of bytes. This shouldn't affect/fix/break existing apps in most cases, but most constants will always have the "correct" encoding (none!) to be consistent with HTTP/socket expectations. Since this comment affects things only on a per-source basis, it won't affect existing apps with the exception of strings we pass to the Rack application. This will eventually allow us to get rid of that Unicorn::Z constant, too.
2009-08-15Fix documentation for Util.reopen_logs
2009-07-19Remove core Tempfile dependency (1.9.2-preview1 compat)
With the 1.9.2preview1 release (and presumably 1.9.1 p243), the Ruby core team has decided that bending over backwards to support crippled operating/file systems was necessary and that files must be closed before unlinking. Regardless, this is more efficient than using Tempfile because: 1) no delegation is necessary, this is a real File object 2) no mkdir is necessary for locking, we can trust O_EXCL to work properly without unnecessary FS activity 3) no finalizer is needed to unlink the file, we unlink it as soon as possible after creation.
2009-05-04Preserve 1.9 IO encodings in reopen_logs
Ensure we preserve both internal and external encodings when reopening logs.
2009-03-03Add Unicorn::Util for a reopen_logs method
Since I use it myself and also in the tests, we might as well implement it correctly as a class method so people can run it in their trap('USR2') hooks.