// // main.m // Used in both LauncherXPCService and LaunchRootXPCService targets // // Copyright (c) 2012 Apple Inc. All rights reserved. // #include #if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 #define BUILDING_ON_SNOW_LEOPARD 1 #endif #if !BUILDING_ON_SNOW_LEOPARD #define __XPC_PRIVATE_H__ #include #include #include #include #include #include "LauncherXPCService.h" // Declaration. Returns 0 if successful. int _validate_authorization(xpc_object_t message); // Returns 0 if successful. int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawnattr_t *attr, posix_spawn_file_actions_t *file_actions) { *attr = 0; int errorCode = posix_spawnattr_init(attr); if (errorCode) return errorCode; cpu_type_t cpuType = (cpu_type_t)xpc_dictionary_get_int64(message, LauncherXPCServiceCPUTypeKey); if (cpuType == -2) { cpuType= CPU_TYPE_ANY; } size_t realCount; errorCode = posix_spawnattr_setbinpref_np(attr, 1, &cpuType, &realCount); if (errorCode) return errorCode; sigset_t no_signals; sigset_t all_signals; sigemptyset (&no_signals); sigfillset (&all_signals); posix_spawnattr_setsigmask(attr, &no_signals); posix_spawnattr_setsigdefault(attr, &all_signals); short flags = xpc_dictionary_get_int64(message, LauncherXPCServicePosixspawnFlagsKey); errorCode = posix_spawnattr_setflags(attr, flags); if (errorCode) return errorCode; // Setup any file actions. Here we are emulating what debugserver would do normally in Host.mm since the XPC service meant only for debugserver. errorCode = posix_spawn_file_actions_init(file_actions); if (errorCode) return errorCode; errorCode = posix_spawn_file_actions_addclose(file_actions, STDIN_FILENO); if (errorCode) return errorCode; errorCode = posix_spawn_file_actions_addclose(file_actions, STDOUT_FILENO); if (errorCode) return errorCode; errorCode = posix_spawn_file_actions_addclose(file_actions, STDERR_FILENO); return errorCode; } bool extract_args(xpc_object_t message, const char *prefix, const char ***argsOut) { char buf[50]; // long enough for 'argXXX' memset(buf, 0, 50); sprintf(buf, "%sCount", prefix); int argsCount = (int)xpc_dictionary_get_int64(message, buf); if (argsCount == 0) { return true; } const char **argsp = NULL; argsp = (const char **)malloc((argsCount+1) * sizeof(argsp[0])); if (argsp == NULL) { return false; } for (int i=0; i