2 * Copyright (c) 2000-2004, 2006, 2009 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 * March 24, 2000 Allan Nathanson <ajn@apple.com>
35 #include <sys/types.h>
38 #include "configd_server.h"
43 __SCDynamicStoreNotifySignal(SCDynamicStoreRef store
, pid_t pid
, int sig
)
45 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 CFStringRef sessionKey
;
49 if ((store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
50 return kSCStatusNoStoreSession
; /* you must have an open session to play */
53 if (storePrivate
->notifyStatus
!= NotifierNotRegistered
) {
54 /* sorry, you can only have one notification registered at once */
55 return kSCStatusNotifierActive
;
58 if (pid
== getpid()) {
59 /* sorry, you can't request that configd be signalled */
60 return kSCStatusInvalidArgument
;
63 if ((sig
<= 0) || (sig
> NSIG
)) {
64 /* sorry, you must specify a valid signal */
65 return kSCStatusInvalidArgument
;
68 /* push out a notification if any changes are pending */
69 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
70 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
71 CFRelease(sessionKey
);
72 if (info
&& CFDictionaryContainsKey(info
, kSCDChangedKeys
)) {
73 CFNumberRef sessionNum
;
75 if (needsNotification
== NULL
)
76 needsNotification
= CFSetCreateMutable(NULL
,
78 &kCFTypeSetCallBacks
);
80 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
81 CFSetAddValue(needsNotification
, sessionNum
);
82 CFRelease(sessionNum
);
91 _notifyviasignal(mach_port_t server
,
96 serverSessionRef mySession
= getSession(server
);
99 SCDynamicStorePrivateRef storePrivate
;
101 if (mySession
== NULL
) {
102 /* sorry, you must have an open session to play */
103 *sc_status
= kSCStatusNoStoreSession
;
104 if (task
!= TASK_NULL
) {
105 (void) mach_port_deallocate(mach_task_self(), task
);
109 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
111 if (task
!= TASK_NULL
) {
112 status
= pid_for_task(task
, &pid
);
113 if (status
!= KERN_SUCCESS
) {
114 /* could not determine pid for task */
115 *sc_status
= kSCStatusFailed
;
116 (void) mach_port_deallocate(mach_task_self(), task
);
120 /* sorry, you must specify a valid task */
121 *sc_status
= kSCStatusInvalidArgument
;
125 *sc_status
= __SCDynamicStoreNotifySignal(mySession
->store
, pid
, sig
);
126 if (*sc_status
!= kSCStatusOK
) {
127 __MACH_PORT_DEBUG(TRUE
, "*** _notifyviasignal __SCDynamicStoreNotifySignal failed: releasing task)", task
);
128 (void) mach_port_deallocate(mach_task_self(), task
);
132 __MACH_PORT_DEBUG(TRUE
, "*** _notifyviasignal", task
);
133 storePrivate
->notifyStatus
= Using_NotifierInformViaSignal
;
134 storePrivate
->notifySignal
= sig
;
135 storePrivate
->notifySignalTask
= task
;