]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifycancel.c
configd-84.tar.gz
[apple/configd.git] / configd.tproj / _notifycancel.c
1 /*
2 * Copyright (c) 2000-2003 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 * Modification History
28 *
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
31 *
32 * March 31, 2000 Allan Nathanson <ajn@apple.com>
33 * - initial revision
34 */
35
36 #include <unistd.h>
37
38 #include "configd.h"
39 #include "session.h"
40
41
42 __private_extern__
43 int
44 __SCDynamicStoreNotifyCancel(SCDynamicStoreRef store)
45 {
46 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
47
48 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreNotifyCancel:"));
49
50 if (!store) {
51 return kSCStatusNoStoreSession; /* you must have an open session to play */
52 }
53
54 /*
55 * cleanup any mach port based notifications.
56 */
57 if (storePrivate->notifyPort != MACH_PORT_NULL) {
58 (void) mach_port_destroy(mach_task_self(), storePrivate->notifyPort);
59 storePrivate->notifyPort = MACH_PORT_NULL;
60 }
61
62 /*
63 * cleanup any file based notifications.
64 */
65 if (storePrivate->notifyFile >= 0) {
66 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" closing (notification) fd %d"), storePrivate->notifyFile);
67 (void) close(storePrivate->notifyFile);
68 storePrivate->notifyFile = -1;
69 }
70
71 /*
72 * cleanup any signal notifications.
73 */
74 if (storePrivate->notifySignal > 0) {
75 (void) mach_port_destroy(mach_task_self(), storePrivate->notifySignalTask);
76 storePrivate->notifySignal = 0;
77 storePrivate->notifySignalTask = TASK_NULL;
78 }
79
80 /* remove this session from the to-be-notified list */
81 if (needsNotification) {
82 CFNumberRef num;
83
84 num = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server);
85 CFSetRemoveValue(needsNotification, num);
86 CFRelease(num);
87
88 if (CFSetGetCount(needsNotification) == 0) {
89 CFRelease(needsNotification);
90 needsNotification = NULL;
91 }
92 }
93
94 /* set notifier inactive */
95 storePrivate->notifyStatus = NotifierNotRegistered;
96
97 return kSCStatusOK;
98 }
99
100
101 __private_extern__
102 kern_return_t
103 _notifycancel(mach_port_t server,
104 int *sc_status)
105 {
106 serverSessionRef mySession = getSession(server);
107
108 if (_configd_verbose) {
109 SCLog(TRUE, LOG_DEBUG, CFSTR("Cancel requested notifications."));
110 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
111 }
112
113 if (!mySession) {
114 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
115 return KERN_SUCCESS;
116 }
117
118 *sc_status = __SCDynamicStoreNotifyCancel(mySession->store);
119 if (*sc_status != kSCStatusOK) {
120 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreNotifyCancel(): %s"), SCErrorString(*sc_status));
121 }
122
123 return KERN_SUCCESS;
124 }