From ec189725d81a238ccf990bbf2bc015013abac913 Mon Sep 17 00:00:00 2001 From: thomasvl Date: Tue, 27 Jan 2015 18:57:31 +0000 Subject: Make GTMSMJobRemove() have the same behavior on OSX 10.10+ as it has on previous OSX versions. In OSX 10.10+, launch_msg(LAUNCH_KEY_REMOVEJOB, ...) returns the error EINPROGRESS if the job was running at the time it was removed. In OSX 10.9 and earlier, the same function call returns success. This CL makes GTMSMJobRemove() treat the error EINPROGRESS as success on OSX 10.10+. --- Foundation/GTMServiceManagement.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Foundation') diff --git a/Foundation/GTMServiceManagement.c b/Foundation/GTMServiceManagement.c index 9027f43..d19fd86 100644 --- a/Foundation/GTMServiceManagement.c +++ b/Foundation/GTMServiceManagement.c @@ -37,6 +37,7 @@ #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 +#include #include #include #include @@ -53,6 +54,18 @@ typedef struct { CFErrorRef *error; } GTMCFToLDictContext; +static bool IsOsYosemiteOrGreater() { + SInt32 version_major; + SInt32 version_minor; + require_noerr(Gestalt(gestaltSystemVersionMajor, &version_major), + failedGestalt); + require_noerr(Gestalt(gestaltSystemVersionMinor, &version_minor), + failedGestalt); + return version_major > 10 || (version_major == 10 && version_minor >= 10); + failedGestalt: + return false; +} + static CFErrorRef GTMCFLaunchCreateUnlocalizedError(CFIndex code, CFStringRef format, ...) CF_FORMAT_FUNCTION(2, 3); @@ -649,6 +662,14 @@ Boolean GTMSMJobRemove(CFStringRef jobLabel, CFErrorRef *error) { switch (resp_type) { case LAUNCH_DATA_ERRNO: { int e = launch_data_get_errno(resp); + + // In OSX 10.10+, launch_msg(LAUNCH_KEY_REMOVEJOB, ...) returns the + // error EINPROGRESS if the job was running at the time it was removed. + // This should be considered a success as it was on earlier OS versions. + if (e == EINPROGRESS && IsOsYosemiteOrGreater()) { + break; + } + if (e) { local_error = GTMCFLaunchCreateUnlocalizedError(e, CFSTR("")); } -- cgit v1.2.3