aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2015-01-27 18:57:31 +0000
committerGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2015-01-27 18:57:31 +0000
commitec189725d81a238ccf990bbf2bc015013abac913 (patch)
treec0056f950f0c5897ffc6c9a0a4180a04e8f41ad0 /Foundation
parentbcd422d399ef41f1c7cbf237b8e9100be5e0dcc8 (diff)
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+.
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMServiceManagement.c21
1 files changed, 21 insertions, 0 deletions
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 <CoreServices/CoreServices.h>
#include <paths.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -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(""));
}