2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Port and memory management for doing lookups to the lookup server
27 * Copyright (C) 1989 by NeXT, Inc.
31 * 27-Mar-90 Gregg Kellogg (gk) at NeXT
32 * Changed to use bootstrap port instead of service port.
37 #include <sys/types.h>
39 #include <mach/mach.h>
40 #include <mach/error.h>
41 #include <servers/bootstrap.h>
43 mach_port_t _lu_port
= MACH_PORT_NULL
;
44 static name_t LOOKUP_NAME
= "lookup daemon v2";
46 mach_port_t
_lookupd_port(mach_port_t port
) {
47 if (port
!= MACH_PORT_NULL
) {
50 ret
= task_get_bootstrap_port(mach_task_self(), &bp
);
51 if (ret
!= KERN_SUCCESS
) {
52 mach_error("task_get_bootstrap_port() failed", ret
);
55 if (bp
== MACH_PORT_NULL
) {
56 mach_error("task_get_bootstrap_port() returned MACH_PORT_NULL!", 0);
57 return MACH_PORT_NULL
;
59 ret
= bootstrap_register(bp
, LOOKUP_NAME
, port
);
60 if (ret
!= BOOTSTRAP_SUCCESS
) {
61 mach_error("bootstrap_register() failed", ret
);
69 /* called as child starts up. mach ports aren't inherited: trash cache */
77 _lu_port
= MACH_PORT_NULL
;
79 ret
= task_get_bootstrap_port(mach_task_self(), &bp
);
80 if (ret
!= KERN_SUCCESS
) {
81 mach_error("task_get_bootstrap_port() failed", ret
);
84 if (bp
== MACH_PORT_NULL
) {
85 fprintf(stderr
, "task_get_bootstrap_port() returned MACH_PORT_NULL!\n");
88 ret
= bootstrap_look_up(bp
, LOOKUP_NAME
, &_lu_port
);
89 if (ret
!= BOOTSTRAP_SUCCESS
&& ret
!= BOOTSTRAP_UNKNOWN_SERVICE
) {
90 mach_error("bootstrap_look_up() failed", ret
);
91 _lu_port
= MACH_PORT_NULL
;
97 _lu_setport(mach_port_t desired
)
99 if (_lu_port
!= MACH_PORT_NULL
) {
100 mach_port_deallocate(mach_task_self(), _lu_port
);
106 port_valid(mach_port_t port
)
108 mach_port_type_t ptype
;
111 ret
= mach_port_type(mach_task_self(), port
, &ptype
);
112 if (ret
!= KERN_SUCCESS
) {
113 mach_error("mach_port_type() failed", ret
);
122 if (_lu_port
== MACH_PORT_NULL
) {
125 if (_lu_port
!= MACH_PORT_NULL
) {
126 if (port_valid(_lu_port
)) {
130 if (port_valid(_lu_port
)) {