]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/safe_vproc.c
mDNSResponder-214.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / safe_vproc.c
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: safe_vproc.c,v $
20 Revision 1.3 2009/02/14 00:09:53 cheshire
21 Only log "Compiled without vproc_transaction support" when running on a system
22 where we expect that to be available -- if running on a system that doesn't even
23 have vproc_transaction, then it doesn't matter that the code was compiled without it.
24
25 Revision 1.2 2009/02/09 21:16:17 mcguire
26 <rdar://problem/5858533> Adopt vproc_transaction API in mDNSResponder
27 additional cleanup: don't alloc memory since we currently only expect to have one transaction
28
29 Revision 1.1 2009/02/06 03:06:49 mcguire
30 <rdar://problem/5858533> Adopt vproc_transaction API in mDNSResponder
31
32 */
33
34 #include <stdlib.h>
35 #include <assert.h>
36 #include <vproc.h>
37 #include "safe_vproc.h"
38 #include "mDNSDebug.h"
39
40 #ifdef VPROC_HAS_TRANSACTIONS
41
42 static vproc_transaction_t transaction = NULL;
43
44 void safe_vproc_transaction_begin(void)
45 {
46 if (vproc_transaction_begin)
47 {
48 if (transaction) { LogMsg("safe_vproc_transaction_begin: Already have a transaction"); }
49 else transaction = vproc_transaction_begin(NULL);
50 }
51 }
52
53 void safe_vproc_transaction_end(void)
54 {
55 if (vproc_transaction_end)
56 {
57 if (transaction) { vproc_transaction_end(NULL, transaction); transaction = NULL; }
58 else LogMsg("safe_vproc_transaction_end: No current transaction");
59 }
60 }
61
62 #else
63
64 #include <stdio.h>
65 #include <CoreFoundation/CFString.h>
66
67 CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
68 CF_EXPORT const CFStringRef _kCFSystemVersionBuildVersionKey;
69 #define OSXVers_10_6_SnowLeopard 10
70
71 void safe_vproc_transaction_begin(void)
72 {
73 static int majorversion = 0;
74 if (!majorversion)
75 {
76 CFDictionaryRef vers = _CFCopySystemVersionDictionary();
77 if (vers)
78 {
79 char buildver[256];
80 CFStringRef cfbuildver = CFDictionaryGetValue(vers, _kCFSystemVersionBuildVersionKey);
81 if (cfbuildver && CFStringGetCString(cfbuildver, buildver, sizeof(buildver), kCFStringEncodingUTF8))
82 sscanf(buildver, "%d", &majorversion);
83 CFRelease(vers);
84 }
85 if (!majorversion || majorversion >= OSXVers_10_6_SnowLeopard)
86 LogMsg("Compiled without vproc_transaction support");
87 }
88 }
89
90 void safe_vproc_transaction_end(void) { }
91
92 #endif