]>
Commit | Line | Data |
---|---|---|
5958d7c0 A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
23 | #include <fcntl.h> | |
24 | #include <paths.h> | |
25 | #include <unistd.h> | |
26 | ||
27 | #include "configd.h" | |
28 | #include "configd_server.h" | |
29 | #include "session.h" | |
30 | ||
31 | ||
32 | #define SNAPSHOT_PATH_CACHE _PATH_VARTMP "configd-cache.xml" | |
33 | #define SNAPSHOT_PATH_SESSION _PATH_VARTMP "configd-session.xml" | |
34 | ||
35 | ||
36 | SCDStatus | |
37 | _SCDSnapshot(SCDSessionRef session) | |
38 | { | |
39 | int fd; | |
40 | CFDataRef xmlData; | |
41 | ||
42 | SCDLog(LOG_DEBUG, CFSTR("_SCDSnapshot:")); | |
43 | ||
44 | /* Save a snapshot of the "cache" data */ | |
45 | ||
46 | (void) unlink(SNAPSHOT_PATH_CACHE); | |
47 | fd = open(SNAPSHOT_PATH_CACHE, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
48 | if (fd < 0) { | |
49 | return SCD_FAILED; | |
50 | } | |
51 | ||
52 | xmlData = CFPropertyListCreateXMLData(NULL, cacheData); | |
53 | (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData)); | |
54 | (void) close(fd); | |
55 | CFRelease(xmlData); | |
56 | ||
57 | /* Save a snapshot of the "session" data */ | |
58 | ||
59 | (void) unlink(SNAPSHOT_PATH_SESSION); | |
60 | fd = open(SNAPSHOT_PATH_SESSION, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
61 | if (fd < 0) { | |
62 | return SCD_FAILED; | |
63 | } | |
64 | ||
65 | /* Save a snapshot of the "session" data */ | |
66 | ||
67 | xmlData = CFPropertyListCreateXMLData(NULL, sessionData); | |
68 | (void) write(fd, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData)); | |
69 | (void) close(fd); | |
70 | CFRelease(xmlData); | |
71 | ||
72 | return SCD_OK; | |
73 | } | |
74 | ||
75 | ||
76 | kern_return_t | |
77 | _snapshot(mach_port_t server, int *scd_status) | |
78 | { | |
79 | serverSessionRef mySession = getSession(server); | |
80 | ||
81 | SCDLog(LOG_DEBUG, CFSTR("Snapshot configuration database.")); | |
82 | ||
83 | *scd_status = _SCDSnapshot(mySession->session); | |
84 | if (*scd_status != SCD_OK) { | |
85 | SCDLog(LOG_DEBUG, CFSTR(" SCDUnlock(): %s"), SCDError(*scd_status)); | |
86 | } | |
87 | ||
88 | return KERN_SUCCESS; | |
89 | } |