Module PhusionPassenger::Utils
In: lib/phusion_passenger/utils/file_system_watcher.rb
lib/phusion_passenger/utils/hosts_file_parser.rb
lib/phusion_passenger/utils/rewindable_input.rb
lib/phusion_passenger/utils/tmpdir.rb
lib/phusion_passenger/utils/unseekable_socket.rb
lib/phusion_passenger/utils.rb

Utility functions.

Methods

Classes and Modules

Class PhusionPassenger::Utils::FileSystemWatcher
Class PhusionPassenger::Utils::HostsFileParser
Class PhusionPassenger::Utils::PseudoIO
Class PhusionPassenger::Utils::RewindableInput
Class PhusionPassenger::Utils::UnseekableSocket

Constants

FileSystemWatcher = NativeSupport::FileSystemWatcher
NULL = "\0".freeze

Public Class methods

Protected Class methods

No-op, hook for unit tests.

Returns the directory in which to store Phusion Passenger-specific temporary files. If create is true, then this method creates the directory if it doesn‘t exist.

Protected Instance methods

To be called after the request handler main loop is exited. This function will fire off necessary events perform necessary cleanup tasks.

This method is to be called after loading the application code but before forking a worker process.

Assert that path is a directory. Raises InvalidPath if it isn‘t.

Assert that path is a file. Raises InvalidPath if it isn‘t.

Assert that groupname is a valid group name. Raises ArgumentError if that is not the case.

Assert that username is a valid username. Raises ArgumentError if that is not the case.

To be called before the request handler main loop is entered, but after the app startup file has been loaded. This function will fire off necessary events and perform necessary preparation tasks.

forked indicates whether the current worker process is forked off from an ApplicationSpawner that has preloaded the app code. options are the spawn options that were passed.

Return the canonicalized version of path. This path is guaranteed to to be "normal", i.e. it doesn‘t contain stuff like ".." or "/", and it fully resolves symbolic links.

Raises SystemCallError if something went wrong. Raises ArgumentError if path is nil. Raises InvalidPath if path does not appear to be a valid path.

Checks the permissions of all parent directories of dir as well as dir itself.

dir must be a canonical path.

If one of the parent directories has wrong permissions, causing dir to be inaccessible by the current process, then this function returns [path, true] where path is the path of the top-most directory with wrong permissions.

If dir itself is not executable by the current process then this function returns [dir, false].

Otherwise, nil is returned.

Generate a long, cryptographically secure random ID string, which is also a valid filename.

Returns a string which reports the backtraces for all threads, or if that‘s not supported the backtrace for the current thread.

Lowers the current process‘s privilege based on the documented rules for the "user", "group", "default_user" and "default_group" options.

Prepare an application process using rules for the given spawn options. This method is to be called before loading the application code.

startup_file is the application type‘s startup file, e.g. "config/environment.rb" for Rails apps and "config.ru" for Rack apps. See SpawnManager#spawn_application for options.

This function may modify options. The modified options are to be passed to the request handler.

Print the given exception, including the stack trace, to STDERR.

current_location is a string which describes where the code is currently at. Usually the current class name will be enough.

Checks whether the given process exists.

Run the given block. A message will be sent through channel (a MessageChannel object), telling the remote side whether the block raised an exception, called exit(), or succeeded.

If sink is non-nil, then every operation on $stderr/STDERR inside the block will be performed on sink as well. If sink is nil then all operations on $stderr/STDERR inside the block will be silently discarded, i.e. if one writes to $stderr/STDERR then nothing will be actually written to the console.

Returns whether the block succeeded, i.e. whether it didn‘t raise an exception.

Exceptions are not propagated, except SystemExit and a few non-StandardExeption classes such as SignalException. Of the exceptions that are propagated, only SystemExit will be reported.

Fork a new process and run the given block inside the child process, just like fork(). Unlike fork(), this method is safe, i.e. there‘s no way for the child process to escape the block. Any uncaught exceptions in the child process will be printed to standard output, citing current_location as the source. Futhermore, the child process will exit by calling Kernel#exit!, thereby bypassing any at_exit or ensure blocks.

If double_fork is true, then the child process will fork and immediately exit. This technique can be used to avoid zombie processes, at the expense of not being able to waitpid() the second child.

Split the given string into an hash. Keys and values are obtained by splitting the string using the null character as the delimitor.

Receive status information that was sent to channel by report_app_init_status. If an error occured according to the received information, then an appropriate exception will be raised.

If print_exception evaluates to true, then the exception message and the backtrace will also be printed. Where it is printed to depends on the type of print_exception:

  • If it responds to puts, then the exception information will be printed using this method.
  • If it responds to to_str, then the exception information will be appended to the file whose filename equals the return value of the to_str call.
  • Otherwise, it will be printed to STDERR.

Raises:

  • AppInitError: this class wraps the exception information received through the channel.
  • IOError, SystemCallError, SocketError: these errors are raised if an error occurred while receiving the information through the channel.

[Validate]