예제 #1
0
void HelperLaunchd::start()
{
    unloadHelper();

    if (!checkHelperPath())
        writePlist();

    loadHelper();
}
예제 #2
0
static int run(CFArrayRef argv) {
	ssize_t res = 0;
	CFIndex count = CFArrayGetCount(argv);
	if (count > 2)  return -1;
	int xml = 0, i;
	CFMutableDictionaryRef dict, preplist;
	CFDictionaryRef project = NULL;
	CFStringRef projname;
	CFArrayRef builds;
	const void *ssites, *bsites;
	CFStringRef build = DBGetCurrentBuild();

	if (count == 2) {
		CFStringRef arg = CFArrayGetValueAtIndex(argv, 0);
		xml = CFEqual(arg, CFSTR("-xml"));
		// -xml is the only supported option
		if (!xml) return -1;
		projname = CFArrayGetValueAtIndex(argv, 1);
	} else if (count == 1 ) {
		projname = CFArrayGetValueAtIndex(argv, 0);
	} else
		return -1;

	builds = DBCopyBuildInheritance(build);
	dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);

	preplist = (CFMutableDictionaryRef)DBCopyProjectPlist(build, NULL);
	ssites = CFDictionaryGetValue(preplist, CFSTR("source_sites"));
	bsites = CFDictionaryGetValue(preplist, CFSTR("binary_sites"));

	preplist = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
	for( i = 0; i < CFArrayGetCount(builds); i++ ) {
		build = CFArrayGetValueAtIndex(builds, i);
		project = DBCopyProjectPlist(build, projname);
		if( CFDictionaryGetCount(project) > 0 )
			break;
	}
	if( CFDictionaryGetCount(project) < 1 )
		return -1;
	CFDictionaryAddValue(dict, projname, project);
	CFRelease(project);
	CFDictionarySetValue(preplist, CFSTR("build"), build);
	CFDictionarySetValue(preplist, CFSTR("projects"), dict);
	if(ssites) CFDictionarySetValue(preplist, CFSTR("source_sites"), ssites);
	if(bsites) CFDictionarySetValue(preplist, CFSTR("binary_sites"), bsites);

	CFPropertyListRef plist = preplist;
	if (xml) {
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
	    CFDataRef data = CFPropertyListCreateData(kCFAllocatorDefault, 
			  				  plist, 
							  kCFPropertyListXMLFormat_v1_0,
							  0,
							  NULL);
#else
		CFDataRef data = CFPropertyListCreateXMLData(NULL, plist);
#endif
		res = write(STDOUT_FILENO, CFDataGetBytePtr(data), (ssize_t)CFDataGetLength(data));
	} else {
		res = writePlist(stdout, plist, 0);
	}
	return (int)res;
}