<rdar://problem/15996848>

Made sure we pass along the file action paths for stdin/stdout/stderr to the XPC service.
[Reviewed by Greg Clayton]

llvm-svn: 201103
This commit is contained in:
Han Ming Ong 2014-02-10 19:23:28 +00:00
parent 8896981056
commit a6cad47207
3 changed files with 49 additions and 4 deletions

View File

@ -1499,6 +1499,21 @@ LaunchProcessXPC (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t
// Posix spawn stuff.
xpc_dictionary_set_int64(message, LauncherXPCServiceCPUTypeKey, launch_info.GetArchitecture().GetMachOCPUType());
xpc_dictionary_set_int64(message, LauncherXPCServicePosixspawnFlagsKey, Host::GetPosixspawnFlags(launch_info));
const ProcessLaunchInfo::FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
if (file_action && file_action->GetPath())
{
xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey, file_action->GetPath());
}
file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
if (file_action && file_action->GetPath())
{
xpc_dictionary_set_string(message, LauncherXPCServiceStdOutPathKeyKey, file_action->GetPath());
}
file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
if (file_action && file_action->GetPath())
{
xpc_dictionary_set_string(message, LauncherXPCServiceStdErrPathKeyKey, file_action->GetPath());
}
xpc_object_t reply = xpc_connection_send_message_with_reply_sync(conn, message);
xpc_type_t returnType = xpc_get_type(reply);

View File

@ -9,6 +9,9 @@
#define LauncherXPCServiceEnvPrefxKey "env"
#define LauncherXPCServiceCPUTypeKey "cpuType"
#define LauncherXPCServicePosixspawnFlagsKey "posixspawnFlags"
#define LauncherXPCServiceStdInPathKeyKey "stdInPath"
#define LauncherXPCServiceStdOutPathKeyKey "stdOutPath"
#define LauncherXPCServiceStdErrPathKeyKey "stdErrPath"
#define LauncherXPCServiceChildPIDKey "childPID"
#define LauncherXPCServiceErrorTypeKey "errorType"
#define LauncherXPCServiceCodeTypeKey "errorCode"

View File

@ -52,17 +52,44 @@ int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawna
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.
// Setup any file actions.
errorCode = posix_spawn_file_actions_init(file_actions);
if (errorCode)
return errorCode;
errorCode = posix_spawn_file_actions_addclose(file_actions, STDIN_FILENO);
const char *path = xpc_dictionary_get_string(message, LauncherXPCServiceStdInPathKeyKey);
if (path)
{
errorCode = posix_spawn_file_actions_addopen(file_actions, STDIN_FILENO, path, O_NOCTTY | O_RDONLY, 0);
}
else
{
errorCode = posix_spawn_file_actions_addclose(file_actions, STDIN_FILENO);
}
if (errorCode)
return errorCode;
errorCode = posix_spawn_file_actions_addclose(file_actions, STDOUT_FILENO);
path = xpc_dictionary_get_string(message, LauncherXPCServiceStdOutPathKeyKey);
if (path)
{
errorCode = posix_spawn_file_actions_addopen(file_actions, STDOUT_FILENO, path, O_NOCTTY | O_CREAT | O_WRONLY, 0640);
}
else
{
errorCode = posix_spawn_file_actions_addclose(file_actions, STDOUT_FILENO);
}
if (errorCode)
return errorCode;
errorCode = posix_spawn_file_actions_addclose(file_actions, STDERR_FILENO);
path = xpc_dictionary_get_string(message, LauncherXPCServiceStdErrPathKeyKey);
if (path)
{
errorCode = posix_spawn_file_actions_addopen(file_actions, STDERR_FILENO, path, O_NOCTTY | O_CREAT | O_RDWR, 0640);
}
else
{
errorCode = posix_spawn_file_actions_addclose(file_actions, STDERR_FILENO);
}
return errorCode;
}