]> git.saurik.com Git - apple/configd.git/blame - configd.tproj/_notifycancel.c
configd-24.1.tar.gz
[apple/configd.git] / configd.tproj / _notifycancel.c
CommitLineData
5958d7c0
A
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#include <unistd.h>
24
25#include "configd.h"
26#include "session.h"
27
28
29SCDStatus
30_SCDNotifierCancel(SCDSessionRef session)
31{
32 SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
33
34 SCDLog(LOG_DEBUG, CFSTR("_SCDNotifierCancel:"));
35
36 if (session == NULL) {
37 return SCD_NOSESSION; /* you must have an open session to play */
38 }
39
40 /*
41 * cleanup any mach port based notifications.
42 */
43 if (sessionPrivate->notifyPort != MACH_PORT_NULL) {
44 (void) mach_port_destroy(mach_task_self(), sessionPrivate->notifyPort);
45 sessionPrivate->notifyPort = MACH_PORT_NULL;
46 }
47
48 /*
49 * cleanup any file based notifications.
50 */
51 if (sessionPrivate->notifyFile >= 0) {
52 SCDLog(LOG_DEBUG, CFSTR(" closing (notification) fd %d"), sessionPrivate->notifyFile);
53 (void) close(sessionPrivate->notifyFile);
54 sessionPrivate->notifyFile = -1;
55 }
56
57 /*
58 * cleanup any signal notifications.
59 */
60 if (sessionPrivate->notifySignal > 0) {
61 (void) mach_port_destroy(mach_task_self(), sessionPrivate->notifySignalTask);
62 sessionPrivate->notifySignal = 0;
63 sessionPrivate->notifySignalTask = TASK_NULL;
64 }
65
66 /* remove this session from the to-be-notified list */
67 if (needsNotification) {
68 CFNumberRef num;
69
70 num = CFNumberCreate(NULL, kCFNumberIntType, &sessionPrivate->server);
71 CFSetRemoveValue(needsNotification, num);
72 CFRelease(num);
73
74 if (CFSetGetCount(needsNotification) == 0) {
75 CFRelease(needsNotification);
76 needsNotification = NULL;
77 }
78 }
79
80 /* set notifier inactive */
81 sessionPrivate->notifyStatus = NotifierNotRegistered;
82
83 return SCD_OK;
84}
85
86
87kern_return_t
88_notifycancel(mach_port_t server,
89 int *scd_status)
90{
91 serverSessionRef mySession = getSession(server);
92
93 SCDLog(LOG_DEBUG, CFSTR("Cancel requested notifications."));
94 SCDLog(LOG_DEBUG, CFSTR(" server = %d"), server);
95
96 *scd_status = _SCDNotifierCancel(mySession->session);
97 if (*scd_status != SCD_OK) {
98 SCDLog(LOG_DEBUG, CFSTR(" SCDNotifierCancel(): %s"), SCDError(*scd_status));
99 }
100
101 return KERN_SUCCESS;
102}