# File lib/phusion_passenger/preloader_shared_helpers.rb, line 47
        def accept_and_process_next_client(server_socket)
                original_pid = Process.pid
                client = server_socket.accept
                client.binmode
                begin
                        command = client.readline
                rescue EOFError
                        return nil
                end
                if command !~ /\n\Z/
                        STDERR.puts "Command must end with a newline"
                elsif command == "spawn\n"
                        while client.readline != "\n"
                                # Do nothing.
                        end
                        
                        # Improve copy-on-write friendliness.
                        GC.start
                        
                        pid = fork
                        if pid.nil?
                                $0 = "#{$0} (forking...)"
                                client.puts "OK"
                                client.puts Process.pid
                                client.flush
                                client.sync = true
                                return [:forked, client]
                        else
                                NativeSupport.detach_process(pid)
                        end
                else
                        STDERR.puts "Unknown command '#{command.inspect}'"
                end
                return nil
        ensure
                if client && Process.pid == original_pid
                        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