2 * Port and memory management for doing lookups to the lookup server
3 * Copyright (C) 1989 by NeXT, Inc.
7 * 27-Mar-90 Gregg Kellogg (gk) at NeXT
8 * Changed to use bootstrap port instead of service port.
12 #include <mach/mach.h>
13 #include <servers/bootstrap.h>
15 mach_port_t _lu_port
= MACH_PORT_NULL
;
16 static name_t LOOKUP_NAME
= "lookup daemon v2";
18 mach_port_t
_lookupd_port(mach_port_t port
) {
19 if (port
!= MACH_PORT_NULL
) {
22 ret
= task_get_bootstrap_port(mach_task_self(), &bp
);
23 if (ret
!= KERN_SUCCESS
) {
24 mach_error("task_get_bootstrap_port() failed", ret
);
27 if (bp
== MACH_PORT_NULL
) {
28 mach_error("task_get_bootstrap_port() returned MACH_PORT_NULL!", 0);
29 return MACH_PORT_NULL
;
31 ret
= bootstrap_register(bp
, LOOKUP_NAME
, port
);
32 if (ret
!= BOOTSTRAP_SUCCESS
) {
33 mach_error("bootstrap_register() failed", ret
);
41 /* called as child starts up. mach ports aren't inherited: trash cache */
49 _lu_port
= MACH_PORT_NULL
;
51 ret
= task_get_bootstrap_port(mach_task_self(), &bp
);
52 if (ret
!= KERN_SUCCESS
) {
53 mach_error("task_get_bootstrap_port() failed", ret
);
56 if (bp
== MACH_PORT_NULL
) {
57 fprintf(stderr
, "task_get_bootstrap_port() returned MACH_PORT_NULL!\n");
60 ret
= bootstrap_look_up(bp
, LOOKUP_NAME
, &_lu_port
);
61 if (ret
!= BOOTSTRAP_SUCCESS
&& ret
!= BOOTSTRAP_UNKNOWN_SERVICE
) {
62 mach_error("bootstrap_look_up() failed", ret
);
63 _lu_port
= MACH_PORT_NULL
;
69 _lu_setport(mach_port_t desired
)
71 if (_lu_port
!= MACH_PORT_NULL
) {
72 mach_port_deallocate(mach_task_self(), _lu_port
);
78 port_valid(mach_port_t port
)
80 mach_port_type_t ptype
;
83 ret
= mach_port_type(mach_task_self(), port
, &ptype
);
84 if (ret
!= KERN_SUCCESS
) {
85 mach_error("mach_port_type() failed", ret
);
94 if (_lu_port
== MACH_PORT_NULL
) {
97 if (_lu_port
!= MACH_PORT_NULL
) {
98 if (port_valid(_lu_port
)) {
102 if (port_valid(_lu_port
)) {