]> git.saurik.com Git - apple/configd.git/blobdiff - configd.tproj/_notifyviasignal.c
configd-136.1.tar.gz
[apple/configd.git] / configd.tproj / _notifyviasignal.c
index bbe43ee44fd93ed21aada7fd440e02cd3efb9961..28aea5a3966a627701334e413bd27ee75bb53c78 100644 (file)
@@ -1,22 +1,23 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
  * @APPLE_LICENSE_HEADER_END@
  */
 
  * - initial revision
  */
 
+#include <unistd.h>
+#include <sys/types.h>
+
 #include "configd.h"
 #include "configd_server.h"
 #include "session.h"
 
+__private_extern__
 int
 __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig)
 {
@@ -41,8 +46,6 @@ __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig)
        CFStringRef                     sessionKey;
        CFDictionaryRef                 info;
 
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreNotifySignal:"));
-
        if (!store || (storePrivate->server == MACH_PORT_NULL)) {
                return kSCStatusNoStoreSession; /* you must have an open session to play */
        }
@@ -54,7 +57,7 @@ __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig)
 
        if (pid == getpid()) {
                /* sorry, you can't request that configd be signalled */
-               return kSCStatusFailed;
+               return kSCStatusInvalidArgument;
        }
 
        if ((sig <= 0) || (sig > NSIG)) {
@@ -83,6 +86,7 @@ __SCDynamicStoreNotifySignal(SCDynamicStoreRef store, pid_t pid, int sig)
 }
 
 
+__private_extern__
 kern_return_t
 _notifyviasignal(mach_port_t   server,
                 task_t         task,
@@ -97,15 +101,14 @@ _notifyviasignal(mach_port_t       server,
        mach_port_t                     oldNotify;
 #endif /* NOTYET */
 
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Send signal when a notification key changes."));
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  server = %d"), server);
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  task   = %d"), task);
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("  signal = %d"), sig);
-
        status = pid_for_task(task, &pid);
        if (status != KERN_SUCCESS) {
-               /* could not determine pid for task */
-               *sc_status = kSCStatusFailed;
+               *sc_status = kSCStatusFailed;           /* could not determine pid for task */
+               return KERN_SUCCESS;
+       }
+
+       if (!mySession) {
+               *sc_status = kSCStatusNoStoreSession;   /* you must have an open session to play */
                return KERN_SUCCESS;
        }
 
@@ -151,19 +154,21 @@ _notifyviasignal(mach_port_t      server,
                                                MACH_MSG_TYPE_MAKE_SEND_ONCE,
                                                &oldNotify);
        if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("mach_port_request_notification(): %s"), mach_error_string(status));
+               SCLog(TRUE, LOG_DEBUG, CFSTR("_notifyviasignal mach_port_request_notification() failed: %s"), mach_error_string(status));
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
        }
 
+#ifdef NOTYET_DEBUG
        if (oldNotify != MACH_PORT_NULL) {
-               SCLog(_configd_verbose, LOG_ERR, CFSTR("_notifyviasignal(): why is oldNotify != MACH_PORT_NULL?"));
+               SCLog(TRUE, LOG_ERR, CFSTR("_notifyviasignal(): why is oldNotify != MACH_PORT_NULL?"));
        }
+#endif /* NOTYET_DEBUG */
 
-       SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Adding task notification port %d to the server's port set"), task);
+       // add task notification port to the server's port set
        status = mach_port_move_member(mach_task_self(), task, server_ports);
        if (status != KERN_SUCCESS) {
-               SCLog(_configd_verbose, LOG_DEBUG, CFSTR("mach_port_move_member(): %s"), mach_error_string(status));
+               SCLog(TRUE, LOG_DEBUG, CFSTR("_notifyviasignal mach_port_move_member() failed: %s"), mach_error_string(status));
                *sc_status = kSCStatusFailed;
                return KERN_SUCCESS;
        }