]> git.saurik.com Git - apple/configd.git/blobdiff - scutil.tproj/session.c
configd-395.11.tar.gz
[apple/configd.git] / scutil.tproj / session.c
index 9c5d2cbd5fd14945612e07e2b4e7a453c8192de0..6f00f3857468348afd93f162580d5ffed57a5952 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004, 2010 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
 
 #include "scutil.h"
 #include "session.h"
-#include "notify.h"
+#include "notifications.h"
 
+
+static void
+reconnected(SCDynamicStoreRef store, void *info)
+{
+       SCPrint(TRUE, stdout, CFSTR("SCDynamicStore server restarted, session reconnected\n"));
+       return;
+}
+
+
+__private_extern__
 void
 do_open(int argc, char **argv)
 {
@@ -44,12 +54,30 @@ do_open(int argc, char **argv)
                CFRelease(watchedPatterns);
        }
 
-       store = SCDynamicStoreCreate(NULL, CFSTR("scutil"), storeCallback, NULL);
-       if (!store) {
+       if (argc < 1) {
+               store = SCDynamicStoreCreate(NULL, CFSTR("scutil"), storeCallback, NULL);
+       } else {
+               CFMutableDictionaryRef  options;
+
+               options = CFDictionaryCreateMutable(NULL,
+                                                   0,
+                                                   &kCFTypeDictionaryKeyCallBacks,
+                                                   &kCFTypeDictionaryValueCallBacks);
+               CFDictionarySetValue(options, kSCDynamicStoreUseSessionKeys, kCFBooleanTrue);
+               store = SCDynamicStoreCreateWithOptions(NULL,
+                                                       CFSTR("scutil"),
+                                                       options,
+                                                       storeCallback,
+                                                       NULL);
+               CFRelease(options);
+       }
+       if (store == NULL) {
                SCPrint(TRUE, stdout, CFSTR("  %s\n"), SCErrorString(SCError()));
                return;
        }
 
+       (void) SCDynamicStoreSetDisconnectCallBack(store, reconnected);
+
        watchedKeys     = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
        watchedPatterns = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
 
@@ -57,21 +85,26 @@ do_open(int argc, char **argv)
 }
 
 
+__private_extern__
 void
 do_close(int argc, char **argv)
 {
-       if (notifyRls) {
-               CFRunLoopRemoveSource(CFRunLoopGetCurrent(), notifyRls, kCFRunLoopDefaultMode);
-               CFRelease(notifyRls);
+       if (notifyRls != NULL) {
+               if (doDispatch) {
+                       (void) SCDynamicStoreSetDispatchQueue(store, NULL);
+               } else {
+                       CFRunLoopSourceInvalidate(notifyRls);
+                       CFRelease(notifyRls);
+               }
                notifyRls = NULL;
        }
 
-       if (notifyRl) {
+       if (notifyRl != NULL) {
                CFRunLoopStop(notifyRl);
                notifyRl  = NULL;
        }
 
-       if (store) {
+       if (store != NULL) {
                CFRelease(store);
                store = NULL;
                CFRelease(watchedKeys);
@@ -83,6 +116,7 @@ do_close(int argc, char **argv)
 }
 
 
+__private_extern__
 void
 do_lock(int argc, char **argv)
 {
@@ -93,6 +127,7 @@ do_lock(int argc, char **argv)
 }
 
 
+__private_extern__
 void
 do_unlock(int argc, char **argv)
 {