]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDPrivate.c
8e0b6ba4141e903558389ce7ad67e6aa91b1003c
[apple/configd.git] / SystemConfiguration.fproj / SCDPrivate.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Modification History
25 *
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
28 *
29 * November 9, 2000 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33 #include <SystemConfiguration/SystemConfiguration.h>
34 #include <SystemConfiguration/SCPrivate.h>
35
36 #include <mach/mach.h>
37 #include <mach/notify.h>
38 #include <mach/mach_error.h>
39 #include <pthread.h>
40
41 void
42 __showMachPortStatus()
43 {
44 #ifdef DEBUG
45 /* print status of in-use mach ports */
46 if (_sc_debug) {
47 kern_return_t status;
48 mach_port_name_array_t ports;
49 mach_port_type_array_t types;
50 int pi, pn, tn;
51 CFMutableStringRef str;
52
53 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("----------"));
54
55 /* report on ALL mach ports associated with this task */
56 status = mach_port_names(mach_task_self(), &ports, &pn, &types, &tn);
57 if (status == MACH_MSG_SUCCESS) {
58 str = CFStringCreateMutable(NULL, 0);
59 for (pi=0; pi < pn; pi++) {
60 char rights[16], *rp = &rights[0];
61
62 if (types[pi] != MACH_PORT_TYPE_NONE) {
63 *rp++ = ' ';
64 *rp++ = '(';
65 if (types[pi] & MACH_PORT_TYPE_SEND)
66 *rp++ = 'S';
67 if (types[pi] & MACH_PORT_TYPE_RECEIVE)
68 *rp++ = 'R';
69 if (types[pi] & MACH_PORT_TYPE_SEND_ONCE)
70 *rp++ = 'O';
71 if (types[pi] & MACH_PORT_TYPE_PORT_SET)
72 *rp++ = 'P';
73 if (types[pi] & MACH_PORT_TYPE_DEAD_NAME)
74 *rp++ = 'D';
75 *rp++ = ')';
76 }
77 *rp = '\0';
78 CFStringAppendFormat(str, NULL, CFSTR(" %d%s"), ports[pi], rights);
79 }
80 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("Task ports (n=%d):%@"), pn, str);
81 CFRelease(str);
82 } else {
83 /* log (but ignore) errors */
84 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("mach_port_names(): %s"), mach_error_string(status));
85 }
86 }
87 #endif /* DEBUG */
88 return;
89 }
90
91
92 void
93 __showMachPortReferences(mach_port_t port)
94 {
95 #ifdef DEBUG
96 kern_return_t status;
97 mach_port_urefs_t refs_send = 0;
98 mach_port_urefs_t refs_recv = 0;
99 mach_port_urefs_t refs_once = 0;
100 mach_port_urefs_t refs_pset = 0;
101 mach_port_urefs_t refs_dead = 0;
102
103 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("user references for mach port %d"), port);
104
105 status = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, &refs_send);
106 if (status != KERN_SUCCESS) {
107 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_SEND): %s"), mach_error_string(status));
108 return;
109 }
110
111 status = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, &refs_recv);
112 if (status != KERN_SUCCESS) {
113 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_RECEIVE): %s"), mach_error_string(status));
114 return;
115 }
116
117 status = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND_ONCE, &refs_once);
118 if (status != KERN_SUCCESS) {
119 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_SEND_ONCE): %s"), mach_error_string(status));
120 return;
121 }
122
123 status = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_PORT_SET, &refs_pset);
124 if (status != KERN_SUCCESS) {
125 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_PORT_SET): %s"), mach_error_string(status));
126 return;
127 }
128
129 status = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_DEAD_NAME, &refs_dead);
130 if (status != KERN_SUCCESS) {
131 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_DEAD_NAME): %s"), mach_error_string(status));
132 return;
133 }
134
135 SCLog(_sc_verbose, LOG_DEBUG,
136 CFSTR(" send = %d, receive = %d, send once = %d, port set = %d, dead name = %d"),
137 refs_send,
138 refs_recv,
139 refs_once,
140 refs_pset,
141 refs_dead);
142
143 #endif /* DEBUG */
144 return;
145 }