6 #include <CoreFoundation/CoreFoundation.h>
9 CF2launch_data(CFTypeRef cfr
);
12 myCFDictionaryApplyFunction(const void *key
, const void *value
, void *context
)
14 launch_data_t ik
, iw
, where
= context
;
16 ik
= CF2launch_data(key
);
17 iw
= CF2launch_data(value
);
19 launch_data_dict_insert(where
, iw
, launch_data_get_string(ik
));
24 CF2launch_data(CFTypeRef cfr
)
27 CFTypeID cft
= CFGetTypeID(cfr
);
29 if (cft
== CFStringGetTypeID()) {
31 CFStringGetCString(cfr
, buf
, sizeof(buf
), kCFStringEncodingUTF8
);
32 r
= launch_data_alloc(LAUNCH_DATA_STRING
);
33 launch_data_set_string(r
, buf
);
34 } else if (cft
== CFBooleanGetTypeID()) {
35 r
= launch_data_alloc(LAUNCH_DATA_BOOL
);
36 launch_data_set_bool(r
, CFBooleanGetValue(cfr
));
37 } else if (cft
== CFArrayGetTypeID()) {
38 CFIndex i
, ac
= CFArrayGetCount(cfr
);
39 r
= launch_data_alloc(LAUNCH_DATA_ARRAY
);
40 for (i
= 0; i
< ac
; i
++) {
41 CFTypeRef v
= CFArrayGetValueAtIndex(cfr
, i
);
43 launch_data_t iv
= CF2launch_data(v
);
44 launch_data_array_set_index(r
, iv
, i
);
47 } else if (cft
== CFDictionaryGetTypeID()) {
48 r
= launch_data_alloc(LAUNCH_DATA_DICTIONARY
);
49 CFDictionaryApplyFunction(cfr
, myCFDictionaryApplyFunction
, r
);
50 } else if (cft
== CFDataGetTypeID()) {
51 r
= launch_data_alloc(LAUNCH_DATA_ARRAY
);
52 launch_data_set_opaque(r
, CFDataGetBytePtr(cfr
), CFDataGetLength(cfr
));
53 } else if (cft
== CFNumberGetTypeID()) {
56 CFNumberType cfnt
= CFNumberGetType(cfr
);
58 case kCFNumberSInt8Type
:
59 case kCFNumberSInt16Type
:
60 case kCFNumberSInt32Type
:
61 case kCFNumberSInt64Type
:
62 case kCFNumberCharType
:
63 case kCFNumberShortType
:
64 case kCFNumberIntType
:
65 case kCFNumberLongType
:
66 case kCFNumberLongLongType
:
67 CFNumberGetValue(cfr
, kCFNumberLongLongType
, &n
);
68 r
= launch_data_alloc(LAUNCH_DATA_INTEGER
);
69 launch_data_set_integer(r
, n
);
71 case kCFNumberFloat32Type
:
72 case kCFNumberFloat64Type
:
73 case kCFNumberFloatType
:
74 case kCFNumberDoubleType
:
75 CFNumberGetValue(cfr
, kCFNumberDoubleType
, &d
);
76 r
= launch_data_alloc(LAUNCH_DATA_REAL
);
77 launch_data_set_real(r
, d
);
90 CreateMyPropertyListFromFile(const char *posixfile
)
92 CFPropertyListRef propertyList
;
93 CFStringRef errorString
;
94 CFDataRef resourceData
;
98 fileURL
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (const UInt8
*)posixfile
, strlen(posixfile
), false);
100 fprintf(stderr
, "%s: CFURLCreateFromFileSystemRepresentation(%s) failed\n", getprogname(), posixfile
);
102 if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault
, fileURL
, &resourceData
, NULL
, NULL
, &errorCode
)) {
103 fprintf(stderr
, "%s: CFURLCreateDataAndPropertiesFromResource(%s) failed: %d\n", getprogname(), posixfile
, (int)errorCode
);
105 propertyList
= CFPropertyListCreateFromXMLData(kCFAllocatorDefault
, resourceData
, kCFPropertyListMutableContainers
, &errorString
);
107 fprintf(stderr
, "%s: propertyList is NULL\n", getprogname());
113 int main(int argc
, const char *argv
[]) {
115 fprintf(stderr
, "usage: sbreload\n");
119 notify_post("com.apple.mobile.springboard_teardown");
121 launch_data_t request
= launch_data_alloc(LAUNCH_DATA_DICTIONARY
);
123 CFDictionaryRef plist
= CreateMyPropertyListFromFile("/System/Library/LaunchDaemons/com.apple.SpringBoard.plist");
125 fprintf(stderr
, "CreateMyPropertyListFromFile() == NULL\n");
129 launch_data_t job
= CF2launch_data(plist
);
131 fprintf(stderr
, "CF2launch_data() == NULL\n");
135 const char *label
= launch_data_get_string(launch_data_dict_lookup(job
, LAUNCH_JOBKEY_LABEL
));
136 launch_data_dict_insert(request
, job
, LAUNCH_KEY_SUBMITJOB
);
138 launch_data_t response
;
140 response
= launch_msg(request
);
142 if (response
== NULL
) {
143 fprintf(stderr
, "launch_msg() == NULL\n");
147 if (launch_data_get_type(response
) != LAUNCH_DATA_ERRNO
) {
148 fprintf(stderr
, "launch_data_get_type() != ERRNO\n");
152 int error
= launch_data_get_errno(response
);
153 launch_data_free(response
);
155 const char *string
= strerror(error
);
157 if (error
== EEXIST
) {
158 fprintf(stderr
, "%s: %s, retrying...\n", label
, string
);
161 } else if (error
!= 0) {
162 fprintf(stderr
, "%s: %s\n", label
, string
);
166 launch_data_free(request
);