2 * Copyright (c) 2000, 2001, 2003-2005, 2008-2011, 2013, 2015-2017 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>
34 #include "SCDynamicStoreInternal.h"
35 #include "config.h" /* MiG generated file */
39 #include <sys/types.h>
40 #include <sys/socket.h>
44 SCDynamicStoreNotifyFileDescriptor(SCDynamicStoreRef store
,
48 #ifdef VERBOSE_ACTIVITY_LOGGING
49 struct os_activity_scope_state_s activity_state
;
50 #endif // VERBOSE_ACTIVITY_LOGGING
51 int fildes
[2] = { -1, -1 };
52 fileport_t fileport
= MACH_PORT_NULL
;
55 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
59 /* sorry, you must provide a session */
60 _SCErrorSet(kSCStatusNoStoreSession
);
64 if (storePrivate
->server
== MACH_PORT_NULL
) {
65 /* sorry, you must have an open session to play */
66 _SCErrorSet(kSCStatusNoStoreServer
);
70 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
71 /* sorry, you can only have one notification registered at once */
72 _SCErrorSet(kSCStatusNotifierActive
);
79 SC_log(LOG_ERR
, "pipe() failed: %s", strerror(errno
));
84 * send fildes[1], the sender's fd, to configd using a fileport and
85 * return fildes[0] to the caller.
88 fileport
= MACH_PORT_NULL
;
89 ret
= fileport_makeport(fildes
[1], &fileport
);
92 SC_log(LOG_ERR
, "fileport_makeport() failed: %s", strerror(errno
));
96 #ifdef VERBOSE_ACTIVITY_LOGGING
97 os_activity_scope_enter(storePrivate
->activity
, &activity_state
);
98 #endif // VERBOSE_ACTIVITY_LOGGING
102 status
= notifyviafd(storePrivate
->server
,
107 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
110 "SCDynamicStoreNotifyFileDescriptor notifyviafd()")) {
114 #ifdef VERBOSE_ACTIVITY_LOGGING
115 os_activity_scope_leave(&activity_state
);
116 #endif // VERBOSE_ACTIVITY_LOGGING
118 if (status
!= KERN_SUCCESS
) {
123 if (sc_status
!= kSCStatusOK
) {
124 _SCErrorSet(sc_status
);
128 /* the SCDynamicStore server now has a copy of the write side, close our reference */
129 (void) close(fildes
[1]);
131 /* and keep the read side */
134 /* set notifier active */
135 storePrivate
->notifyStatus
= Using_NotifierInformViaFD
;
141 if (fildes
[0] != -1) close(fildes
[0]);
142 if (fildes
[1] != -1) close(fildes
[1]);