2 * Copyright (c) 2000, 2001, 2003-2006, 2008-2011, 2015, 2019 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 serverSessionRef mySession
;
51 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
53 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
54 /* sorry, you can only have one notification registered at once */
55 return kSCStatusNotifierActive
;
58 /* push out a notification if any changes are pending */
59 mySession
= getSession(storePrivate
->server
);
60 if (mySession
->changedKeys
!= NULL
) {
61 CFNumberRef sessionNum
;
63 if (needsNotification
== NULL
)
64 needsNotification
= CFSetCreateMutable(NULL
,
66 &kCFTypeSetCallBacks
);
68 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
69 CFSetAddValue(needsNotification
, sessionNum
);
70 CFRelease(sessionNum
);
79 _notifyviafd(mach_port_t server
,
87 serverSessionRef mySession
= getSession(server
);
88 SCDynamicStorePrivateRef storePrivate
;
90 /* get notification file descriptor */
91 fd
= fileport_makefd(fileport
);
92 mach_port_deallocate(mach_task_self(), fileport
);
98 flags
= fcntl(fd
, F_GETFL
, 0);
105 if (fcntl(fd
, F_SETFL
, flags
) == -1) {
110 if (mySession
== NULL
) {
111 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
114 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
116 /* do common sanity checks */
117 *sc_status
= __SCDynamicStoreNotifyFileDescriptor(mySession
->store
);
119 /* check status of __SCDynamicStoreNotifyFileDescriptor() */
120 if (*sc_status
!= kSCStatusOK
) {
124 /* set notifier active */
125 storePrivate
->notifyStatus
= Using_NotifierInformViaFD
;
126 storePrivate
->notifyFile
= fd
;
127 storePrivate
->notifyFileIdentifier
= identifier
;
133 if (fd
>= 0) close(fd
);