2 * Copyright (c) 2000, 2001, 2003-2006, 2008-2011, 2015 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * April 5, 2000 Allan Nathanson <ajn@apple.com>
35 #include <sys/fileport.h>
36 #include <sys/ioctl.h>
38 #include <sys/types.h>
39 #include <sys/socket.h>
48 __SCDynamicStoreNotifyFileDescriptor(SCDynamicStoreRef store
)
50 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
51 CFStringRef sessionKey
;
54 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
55 /* sorry, you can only have one notification registered at once */
56 return kSCStatusNotifierActive
;
59 /* push out a notification if any changes are pending */
60 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
61 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
62 CFRelease(sessionKey
);
63 if (info
&& CFDictionaryContainsKey(info
, kSCDChangedKeys
)) {
64 CFNumberRef sessionNum
;
66 if (needsNotification
== NULL
)
67 needsNotification
= CFSetCreateMutable(NULL
,
69 &kCFTypeSetCallBacks
);
71 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
72 CFSetAddValue(needsNotification
, sessionNum
);
73 CFRelease(sessionNum
);
82 _notifyviafd(mach_port_t server
,
90 serverSessionRef mySession
= getSession(server
);
91 SCDynamicStorePrivateRef storePrivate
;
93 /* get notification file descriptor */
94 fd
= fileport_makefd(fileport
);
95 mach_port_deallocate(mach_task_self(), fileport
);
101 flags
= fcntl(fd
, F_GETFL
, 0);
108 if (fcntl(fd
, F_SETFL
, flags
) == -1) {
113 if (mySession
== NULL
) {
114 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
117 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
119 /* do common sanity checks */
120 *sc_status
= __SCDynamicStoreNotifyFileDescriptor(mySession
->store
);
122 /* check status of __SCDynamicStoreNotifyFileDescriptor() */
123 if (*sc_status
!= kSCStatusOK
) {
127 /* set notifier active */
128 storePrivate
->notifyStatus
= Using_NotifierInformViaFD
;
129 storePrivate
->notifyFile
= fd
;
130 storePrivate
->notifyFileIdentifier
= identifier
;
136 if (fd
>= 0) close(fd
);