}
/**
- * startupItemListGetMatches returns an array of items which contain the string aService in the key aKey
+ * startupItemListCopyMatches returns an array of items which contain the string aService in the key aKey
**/
-static CFMutableArrayRef startupItemListGetMatches(CFArrayRef anItemList, CFStringRef aKey, CFStringRef aService)
+static CFMutableArrayRef startupItemListCopyMatches(CFArrayRef anItemList, CFStringRef aKey, CFStringRef aService)
{
CFMutableArrayRef aResult = NULL;
break;
}
if (*c == NULL) {
- CFRetain(ci);
CFArrayAppendValue(aNewList, ci);
CF_syslog(LOG_DEBUG, CFSTR("%@: Keeping %@"), type, ci);
}
}
CFDictionaryReplaceValue(aConfig, type, aNewList);
+ CFRelease(aNewList);
}
if (type == kUsesKey)
return;
return aResult;
}
-static bool StartupItemSecurityCheck(const char *aPath)
+bool StartupItemSecurityCheck(const char *aPath)
{
static struct timeval boot_time;
struct stat aStatBuf;
while ((aState = NSGetNextSearchPathEnumeration(aState, aPath))) {
DIR *aDirectory;
- strcpy(aPath + strlen(aPath), kStartupItemsPath);
+ strlcat(aPath, kStartupItemsPath, sizeof(aPath));
++aDomainIndex;
/* 5485016
*
* Just in case...
*/
- mkdir(aPath, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
+ mkdir(aPath, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
if (!StartupItemSecurityCheck(aPath))
continue;
CFMutableDictionaryRef StartupItemListGetProvider(CFArrayRef anItemList, CFStringRef aService)
{
CFMutableDictionaryRef aResult = NULL;
- CFMutableArrayRef aList = startupItemListGetMatches(anItemList, kProvidesKey, aService);
+ CFMutableArrayRef aList = startupItemListCopyMatches(anItemList, kProvidesKey, aService);
if (aList && CFArrayGetCount(aList) > 0)
aResult = (CFMutableDictionaryRef) CFArrayGetValueAtIndex(aList, 0);
+ if (aList) CFRelease(aList);
+
return aResult;
}
-CFArrayRef StartupItemListGetRunning(CFArrayRef anItemList)
+CFArrayRef StartupItemListCreateFromRunning(CFArrayRef anItemList)
{
CFMutableArrayRef aResult = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
if (aResult) {
for (anItemIndex = 0; anItemIndex < anItemCount; anItemIndex++) {
CFStringRef anItem = CFArrayGetValueAtIndex(anItemList, anItemIndex);
- CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, aKey, anItem);
+ CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, aKey, anItem);
if (aMatchesList) {
aCount = aCount + CFArrayGetCount(aMatchesList);
for (anAntecedentIndex = 0; anAntecedentIndex < anAntecedentCount; ++anAntecedentIndex) {
CFStringRef anAntecedent = CFArrayGetValueAtIndex(anAntecedentList, anAntecedentIndex);
CFStringRef aKey = (anAction == kActionStart) ? kProvidesKey : kUsesKey;
- CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, aKey, anAntecedent);
+ CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, aKey, anAntecedent);
if (aMatchesList) {
CFIndex aMatchesListCount = CFArrayGetCount(aMatchesList);
* might provide that service.
*/
else {
- CFArrayRef aMatchesList = startupItemListGetMatches(aWaitingList, kProvidesKey, aProvides);
+ CFArrayRef aMatchesList = startupItemListCopyMatches(aWaitingList, kProvidesKey, aProvides);
if (aMatchesList) {
CFIndex aMatchesListCount = CFArrayGetCount(aMatchesList);
CFIndex aMatchesListIndex;
return aNextItem;
}
-CFStringRef StartupItemGetDescription(CFMutableDictionaryRef anItem)
+CFStringRef StartupItemCreateDescription(CFMutableDictionaryRef anItem)
{
CFStringRef aString = NULL;
anError = 0;
} else {
CFStringRef aBundlePathString = CFDictionaryGetValue(anItem, kBundlePathKey);
- size_t aBundlePathCLength =
- CFStringGetMaximumSizeForEncoding(CFStringGetLength(aBundlePathString), kCFStringEncodingUTF8) + 1;
- char *aBundlePath = (char *)malloc(aBundlePathCLength);
- char anExecutable[PATH_MAX] = "";
+ char aBundlePath[PATH_MAX];
+ char anExecutable[PATH_MAX];
+ char *tmp;
- if (!aBundlePath) {
- syslog(LOG_EMERG, "malloc() failed; out of memory while running item %s", aBundlePathString);
- return (anError);
- }
- if (!CFStringGetCString(aBundlePathString, aBundlePath, aBundlePathCLength, kCFStringEncodingUTF8)) {
+ if (!CFStringGetCString(aBundlePathString, aBundlePath, sizeof(aBundlePath), kCFStringEncodingUTF8)) {
CF_syslog(LOG_EMERG, CFSTR("Internal error while running item %@"), aBundlePathString);
return (anError);
}
/* Compute path to excecutable */
- {
- char *tmp;
- strncpy(anExecutable, aBundlePath, sizeof(anExecutable)); /* .../foo */
- tmp = rindex(anExecutable, '/'); /* /foo */
- strncat(anExecutable, tmp, strlen(tmp)); /* .../foo/foo */
- }
-
- free(aBundlePath);
+ tmp = rindex(aBundlePath, '/');
+ snprintf(anExecutable, sizeof(anExecutable), "%s%s", aBundlePath, tmp);
/**
* Run the bundle