DMA32
     	ˆÁÀÅ604¿ÃÂ \    	‹      Õ–ßoÚ0ÇßûWx~ØÚ®4xêH¥¡QŠZ¦iš¦ÊÄ†XMìÈ60ú×ÏÁi›NEcZAíçK¾¹»�9ÿßE—½ñ÷Ñ9ú<¾ Ñ×Oƒ~áÀ·V GþE»Þ Î‡áÄÚ¼°\.ëËV]éŒ¯ ±YÚcµˆm�Y†ÉAX<#(L8eÎ¢Ð
›rÒ—ŒÿBjŠ@Í­Œ»ïV_ˆ˜›blyÏ”^•¦}R1Þ(ÝÖ‡'nÐh†àc»lP¦'Š­Š*‚et�×Pt²N\5	m‚43ÙÅVå˜„"›!£ã.+i`’Ry[Ÿ‰)F4µ]ü£ß»üét`“âkR”h>íâ�½îðô²a2¤�>¯¹pš3LÔX”)&¦‚³�âk/¾w›F^qk‘[¡ä£b5V©É©c=t‰®ª¼„ým6hüd2FgWçÃqÔ¿òSÂŠ�Õýÿÿ‡Éˆj.-Š„æ±u¯J8Ÿé½œ˜üôÞEeéZÌ‹	B5ô¬òx§*e\W‰7±Þ×ëmµÊ?Êj6šGµ ¨'(8î4ŽÚaýsy+ÕRV\;< d*$ÇÄÛ- š
Ú�öÉF ·	}Ù#@ž¬Ì�o2L*Îö(Ç¯
EÛ`I²orØÚ)Èö‹"WK®Ý¢ðö%êßó¢Ðn;Z'&Ã­1Üï+é'c©ukóöºÈÌ'å™áÆop‹�ó…;Ë0ñö% öÜGE vs§$7˜TœÝ÷Ô–—(¯w!¬¯“!øKíoü¹ý7    E   ˆl–Ãa¾”ªeJe@ãB¸©‹Fÿ�þBóR,Ü¬²Ð„G¥)üÿÇƒpBÆ_�uÐb&=LyZËcõÅÄ M    # encoding: binary
#  Phusion Passenger - https://www.phusionpassenger.com/
#  Copyright (c) 2011-2017 Phusion Holding B.V.
#
#  "Passenger", "Phusion Passenger" and "Union Station" are registered
#  trademarks of Phusion Holding B.V.
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.

require 'tmpdir'
PhusionPassenger.require_passenger_lib 'constants'
PhusionPassenger.require_passenger_lib 'utils'
PhusionPassenger.require_passenger_lib 'native_support'

module PhusionPassenger

  # Provides shared functions for preloader apps.
  module PreloaderSharedHelpers
    extend self

    def init(main_app)
      options = LoaderSharedHelpers.init(main_app)

      $0 = "#{SHORT_PROGRAM_NAME} AppPreloader: #{options['app_root']}"

      if !Kernel.respond_to?(:fork)
        message = "Smart spawning is not available on this Ruby " +
          "implementation because it does not support `Kernel.fork`. "
        case options['integration_mode']
        when 'nginx'
          message << "Please set `passenger_spawn_method` to `direct`."
        when 'apache'
          message << "Please set `PassengerSpawnMethod` to `direct`."
        else
          message << "Please set `spawn_method` to `direct`."
        end
        raise(message)
      end

      options
    end

    def accept_and_process_next_client(server_socket)
      client = server_socket.accept
      client.binmode
      begin
        line = client.readline
      rescue EOFError
        return nil
      end

      begin
        doc = Utils::JSON.parse(line)
      rescue RuntimeError => e
        client.write(Utils::JSON.generate(
          :result => 'error',
          :message => "JSON parse error: #{e}"
        ))
      end

      if doc['command'] == 'spawn'
        handle_spawn_command(client, doc)
      else
        client.write(Utils::JSON.generate(
          :result => 'error',
          :message => "Unknown command #{doc['command'].inspect}"
        ))
        nil
      end
    ensure
      if client
        begin
          client.close
        rescue Errno::EINVAL
          # Work around OS X bug.
          # https://code.google.com/p/phusion-passenger/issues/detail?id=854
        end
      end
    end

    def handle_spawn_command(client, doc)
      work_dir = doc['work_dir']
      LoaderSharedHelpers.record_journey_step_end('PRELOADER_PREPARATION