this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

LaunchServices launch appliations

Uses the proper launchd way, spawn_via_launchd

launchd fails due to unimplemented syscall.

Unimplemented syscall (428)

+78 -30
+3
src/frameworks/CoreServices/include/LaunchServices/LaunchServices.h
··· 101 101 102 102 // TODO: many other functions 103 103 104 + // Undocumented, not sure on correct parameters 105 + OSStatus _LSLaunchApplication(CFURLRef appPath); 106 + 104 107 #ifdef __cplusplus 105 108 } 106 109 #endif
+75 -30
src/frameworks/CoreServices/src/LaunchServices/LaunchServices.c
··· 20 20 #include <LaunchServices/LaunchServices.h> 21 21 #include <stdio.h> 22 22 #include <stdlib.h> 23 + #include <launch_priv.h> 23 24 24 - static CFStringRef get_main_executable(CFURLRef appURL); 25 + static void get_main_executable_info(CFURLRef appURL, CFStringRef *exec, CFStringRef *bundleName); 25 26 26 27 OSStatus LSRegisterURL(CFURLRef inURL, Boolean inUpdate) 27 28 { ··· 41 42 42 43 OSStatus LSOpenFromURLSpec(const LSLaunchURLSpec *inLaunchSpec, CFURLRef *outLaunchedURL) 43 44 { 44 - CFStringRef scheme, extension, executable; 45 + CFStringRef scheme, extension; 45 46 CFIndex count, i; 46 - CFURLRef url, url_plus_exec, pre; 47 + CFURLRef url; 47 48 CFRange range; 48 - OSStatus ret = 0; 49 + OSStatus ret = 0, temp; 49 50 50 51 /* Inspect scheme of URL */ 51 52 count = CFArrayGetCount(inLaunchSpec->itemURLs); ··· 61 62 62 63 /* Check for .app suffix */ 63 64 extension = CFURLCopyPathExtension(url); 64 - range = CFRangeMake(0, CFStringGetLength(extension)); 65 - if (CFStringCompareWithOptions(extension, CFSTR("app"), range, kCFCompareCaseInsensitive) == kCFCompareEqualTo) 65 + if (extension != NULL) 66 + range = CFRangeMake(0, CFStringGetLength(extension)); 67 + if (extension != NULL && (CFStringCompareWithOptions(extension, CFSTR("app"), range, kCFCompareCaseInsensitive) == kCFCompareEqualTo)) 66 68 { 67 - /* Read info.plist, find path to main executable */ 68 - if ((executable = get_main_executable(url)) == NULL) 69 - { 70 - ret = 1; 71 - } 72 - else 73 - { 74 - url_plus_exec = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, url, CFSTR("Contents"), TRUE); 75 - pre = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, url_plus_exec, CFSTR("MacOS"), TRUE); 76 - CFRelease(url_plus_exec); 77 - url_plus_exec = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, pre, executable, FALSE); 78 - CFRelease(pre); 79 - 80 - /* Launch the executable */ 81 - executable = CFURLGetString(url_plus_exec); 82 - CFShow(executable); 83 - 84 - CFRelease(url_plus_exec); 85 - CFRelease(executable); 86 - } 69 + temp = _LSLaunchApplication(url); 70 + if (temp) 71 + ret = temp; 87 72 } 88 73 else 89 74 { ··· 91 76 ret = 1; 92 77 } 93 78 94 - CFRelease(extension); 79 + if (extension != NULL) 80 + CFRelease(extension); 95 81 } 96 82 else 97 83 { 98 84 printf("We can't handle this scheme yet\n"); 99 - CFShow(scheme); 100 85 ret = kLSApplicationNotFoundErr; 101 86 } 102 87 CFRelease(scheme); ··· 104 89 return ret; 105 90 } 106 91 107 - static CFStringRef get_main_executable(CFURLRef appURL) 92 + OSStatus _LSLaunchApplication(CFURLRef appPath) 93 + { 94 + CFStringRef executable, bundleName; 95 + CFIndex nameSize, execSize; 96 + CFURLRef pre, url_plus_exec; 97 + pid_t pid; 98 + char *name, *exec, *argv[2]; 99 + 100 + /* Read info.plist, find path to main executable */ 101 + get_main_executable_info(appPath, &executable, &bundleName); 102 + if (executable == NULL) 103 + { 104 + return 1; 105 + } 106 + else 107 + { 108 + url_plus_exec = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, appPath, CFSTR("Contents"), TRUE); 109 + pre = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, url_plus_exec, CFSTR("MacOS"), TRUE); 110 + CFRelease(url_plus_exec); 111 + url_plus_exec = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, pre, executable, FALSE); 112 + CFRelease(pre); 113 + /* Launch the executable */ 114 + executable = CFURLGetString(url_plus_exec); 115 + CFShow(executable); 116 + /* Try to use CFBundleName first */ 117 + if (bundleName == NULL) 118 + bundleName = CFStringCreateCopy(kCFAllocatorDefault, executable); 119 + nameSize = CFStringGetLength(bundleName)+1; 120 + name = malloc(nameSize); 121 + CFStringGetCString(bundleName, name, nameSize, kCFStringEncodingUTF8); 122 + execSize = CFStringGetLength(executable)+1; 123 + exec = malloc(execSize); 124 + CFStringGetCString(executable, exec, execSize, kCFStringEncodingUTF8); 125 + argv[0] = exec; 126 + argv[1] = NULL; 127 + pid = spawn_via_launchd(name, (const char *const *)argv, NULL); 128 + if (pid < 0) 129 + { 130 + printf("%s: Failed to spawn via launchd\n", exec); 131 + return 1; 132 + } 133 + free(name); 134 + free(exec); 135 + CFRelease(url_plus_exec); 136 + CFRelease(executable); 137 + 138 + } 139 + if (bundleName != NULL) 140 + CFRelease(bundleName); 141 + return 0; 142 + } 143 + 144 + static void get_main_executable_info(CFURLRef appURL, CFStringRef *exec, CFStringRef *bundleName) 108 145 { 109 146 CFURLRef pre = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, appURL, CFSTR("Contents"), TRUE); 110 147 CFURLRef info_plist_url = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, pre, CFSTR("Info.plist"), FALSE); 111 148 CFReadStreamRef rs = CFReadStreamCreateWithFile(kCFAllocatorDefault, info_plist_url); 112 149 CFDictionaryRef info_plist; 113 150 CFStringRef ret = NULL; 151 + 152 + *exec = NULL; 153 + *bundleName = NULL; 114 154 115 155 CFRelease(pre); 116 156 ··· 132 172 if (ret != NULL) 133 173 ret = CFStringCreateCopy(kCFAllocatorDefault, ret); 134 174 175 + *exec = ret; 176 + 177 + ret = CFDictionaryGetValue(info_plist, CFSTR("CFBundleName")); 178 + if (ret != NULL) 179 + *bundleName = CFStringCreateCopy(kCFAllocatorDefault, ret); 180 + 135 181 err: 136 182 CFRelease(info_plist); 137 183 err_pre_info: 138 184 CFRelease(rs); 139 185 CFRelease(info_plist_url); 140 - return ret; 141 186 }