1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#import "config.h"
27#import "ChildProcessEntryPoint.h"
28
29#import <mach/mach_error.h>
30#import <servers/bootstrap.h>
31#import <stdio.h>
32#import <wtf/RetainPtr.h>
33#import <wtf/text/CString.h>
34
35#define SHOW_CRASH_REPORTER 1
36
37namespace WebKit {
38
39ChildProcessMainDelegate::~ChildProcessMainDelegate()
40{
41}
42
43void ChildProcessMainDelegate::installSignalHandlers()
44{
45#if !SHOW_CRASH_REPORTER
46    // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
47    signal(SIGILL, _exit);
48    signal(SIGFPE, _exit);
49    signal(SIGBUS, _exit);
50    signal(SIGSEGV, _exit);
51#endif
52}
53
54void ChildProcessMainDelegate::doPreInitializationWork()
55{
56}
57
58bool ChildProcessMainDelegate::getConnectionIdentifier(IPC::Connection::Identifier& identifier)
59{
60    String serviceName = m_commandLine["servicename"];
61    if (serviceName.isEmpty())
62        return false;
63
64    mach_port_t serverPort;
65    kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort);
66    if (kr) {
67        WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);
68        return false;
69    }
70
71    identifier = serverPort;
72    return true;
73}
74
75bool ChildProcessMainDelegate::getClientIdentifier(String& clientIdentifier)
76{
77    clientIdentifier = m_commandLine["client-identifier"];
78    if (clientIdentifier.isEmpty())
79        return false;
80    return true;
81}
82
83bool ChildProcessMainDelegate::getClientProcessName(String& clientProcessName)
84{
85    clientProcessName = m_commandLine["ui-process-name"];
86    if (clientProcessName.isEmpty())
87        return false;
88    return true;
89}
90
91bool ChildProcessMainDelegate::getExtraInitializationData(HashMap<String, String>&)
92{
93    return true;
94}
95
96void ChildProcessMainDelegate::startRunLoop()
97{
98    RunLoop::run();
99}
100
101void ChildProcessMainDelegate::doPostRunWork()
102{
103}
104
105} // namespace WebKit
106