]> git.saurik.com Git - apple/securityd.git/blob - src/child.h
cd9b8a57af86e2b1184a636463b9856d8d0e6bec
[apple/securityd.git] / src / child.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // child - track a single child process and its belongings
29 //
30 #ifndef _CHILD_H_
31 #define _CHILD_H_ 1
32
33 #include "securityserver.h"
34
35 class Child;
36
37 //
38 // ChildManager - Singleton Child Manager class
39 //
40 class ChildManager
41 {
42 public:
43 // The singleton childManager.
44 static ChildManager childManager;
45
46 ChildManager();
47 ~ChildManager();
48
49 // Return true in the child. Return false in the parent and set outChildPort to 0 if the child died prematuely. In this case outWaitStatus contains the result of a waitpid() on the child. if outChildPort is non 0 it's a send right to contact the child on.
50 bool forkChild(mach_port_t &outChildPort, int &outWaitStatus);
51
52 // SigChild signal handler
53 void handleSignal(int signal);
54
55 // Be notified a child just contacted us on our main server port telling us it's child port. Set childPort to 0 iff we don't wish it to be deallocated by our caller.
56 void registerChild(pid_t pid, mach_port_t &childPort);
57
58 // Assumes mLock is not locked (called by Child's eraseFromMap() function).
59 void eraseChild(pid_t pid);
60
61 // Assumes mLock is already locked (called by Child's insertInMap() function).
62 void insertChild(pid_t pid, Child *child);
63
64 private:
65 Child *findChild(pid_t pid);
66
67 void handleSigChild();
68
69 // Be notifed of a term or signal waitpid() status.
70 void waitStatusForPid(pid_t pid, int status);
71
72
73 typedef std::map<pid_t, Child *> ChildMap;
74 ChildMap mChildMap;
75 Mutex mLock;
76 };
77
78
79 #endif // _CHILD_H_