2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Bootstrap subset exercise.
28 * create a subset port with requestor = req_port;
29 * register "foo" on subset_port;
30 * deallocate req_port;
36 #import <servers/bootstrap.h>
38 #import <mach_error.h>
40 void log_boot_servers(port_t boot_port
);
42 int main(int argc
, char **argv
)
46 port_t requestor_port
;
49 int deallocate_subset
= 0;
51 if (argc
>= 2 && argv
[1][0] == '-' && argv
[1][1] == 'r') {
54 krtn
= bootstrap_look_up(bootstrap_port
, &argv
[1][2], &newboot
);
56 mach_error("bootstrap lookup", krtn
);
59 bootstrap_port
= newboot
;
63 if(argv
[1][0] == '-' && argv
[1][0] == 'd')
64 deallocate_subset
= 1;
68 * Allocate some resources.
70 krtn
= port_allocate(task_self(), &foo_port
);
72 mach_error("port_allocate", krtn
);
77 krtn
= port_allocate(task_self(), &requestor_port
);
79 mach_error("port_allocate", krtn
);
82 krtn
= bootstrap_subset(bootstrap_port
,
83 requestor_port
, /* requestor */
86 mach_error("bootstrap_subset", krtn
);
89 printf("Loop %d, prior to bootstrap_register:\n", loop
);
90 log_boot_servers(subset_port
);
92 krtn
= bootstrap_register(subset_port
,
96 mach_error("bootstrap_register (subset)", krtn
);
99 printf("Loop %d, after bootstrap_register:\n", loop
);
100 log_boot_servers(subset_port
);
103 * Delete requestor_port, subset should go away.
105 krtn
= port_deallocate(task_self(), requestor_port
);
107 mach_error("port_deallocate", krtn
);
111 if(deallocate_subset
) {
112 krtn
= port_deallocate(task_self(), subset_port
);
114 mach_error("port_deallocate(subset)", krtn
);
119 } while(krtn
== KERN_SUCCESS
);
125 void log_boot_servers(port_t boot_port
)
128 name_array_t service_names
;
129 unsigned int service_cnt
;
130 name_array_t server_names
;
131 unsigned int server_cnt
;
132 bool_array_t service_active
;
133 unsigned int service_active_cnt
;
136 krtn
= bootstrap_info(boot_port
,
142 &service_active_cnt
);
143 if (krtn
!= BOOTSTRAP_SUCCESS
)
144 printf("ERROR: info failed: %d", krtn
);
146 printf("log_boot_server: service_cnt = %d\n", service_cnt
);
147 for (i
= 0; i
< service_cnt
; i
++)
148 printf("Name: %-15s Server: %-15s "
151 server_names
[i
][0] == '\0' ?
152 "Unknown" : server_names
[i
],
153 service_active
[i
] ? "Yes\n" : "No\n");