mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
@@ -46,12 +46,23 @@ namespace io
|
||||
OAK_CHECK(posix_spawn_file_actions_addclose(&fileActions, err[1]));
|
||||
OAK_CHECK(posix_spawnattr_init(&flags));
|
||||
OAK_CHECK(posix_spawnattr_setflags(&flags, POSIX_SPAWN_SETSIGDEF|closeOnExecFlag));
|
||||
OAK_CHECK(posix_spawn(&pid, argv[0], &fileActions, &flags, argv, env));
|
||||
|
||||
int rc = posix_spawn(&pid, argv[0], &fileActions, &flags, argv, env);
|
||||
if(rc != 0)
|
||||
perror(text::format("posix_spawn(\"%s\")", cmd.c_str()).c_str());
|
||||
|
||||
OAK_CHECK(posix_spawnattr_destroy(&flags));
|
||||
OAK_CHECK(posix_spawn_file_actions_destroy(&fileActions));
|
||||
OAK_CHECK(close(out[1]));
|
||||
OAK_CHECK(close(err[1]));
|
||||
|
||||
if(rc != 0)
|
||||
{
|
||||
close(out[0]);
|
||||
close(err[0]);
|
||||
return NULL_STR;
|
||||
}
|
||||
|
||||
std::string output, error;
|
||||
|
||||
char buf[255];
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <oak/compat.h>
|
||||
#include <io/environment.h>
|
||||
|
||||
#define OAK_CHECK(expr) do { if((expr) != 0) { perror(#expr); return -1; } } while(false)
|
||||
|
||||
namespace network
|
||||
{
|
||||
pid_t launch_tbz (std::string const& dest, int& input, int& output, std::string& error)
|
||||
@@ -21,28 +23,32 @@ namespace network
|
||||
|
||||
short closeOnExecFlag = (oak::os_major() == 10 && oak::os_minor() == 7) ? 0 : POSIX_SPAWN_CLOEXEC_DEFAULT;
|
||||
|
||||
bool ok = true;
|
||||
ok = ok && pipe(&in[0]) == 0;
|
||||
ok = ok && pipe(&out[0]) == 0;
|
||||
ok = ok && fcntl(in[1], F_SETFD, FD_CLOEXEC) == 0;
|
||||
ok = ok && fcntl(out[0], F_SETFD, FD_CLOEXEC) == 0;
|
||||
ok = ok && posix_spawn_file_actions_init(&fileActions) == 0;
|
||||
ok = ok && posix_spawn_file_actions_adddup2(&fileActions, in[0], 0) == 0;
|
||||
ok = ok && posix_spawn_file_actions_adddup2(&fileActions, out[1], 1) == 0;
|
||||
ok = ok && posix_spawn_file_actions_adddup2(&fileActions, out[1], 2) == 0;
|
||||
ok = ok && posix_spawn_file_actions_addclose(&fileActions, in[0]) == 0;
|
||||
ok = ok && posix_spawn_file_actions_addclose(&fileActions, out[1]) == 0;
|
||||
ok = ok && posix_spawnattr_init(&flags) == 0;
|
||||
ok = ok && posix_spawnattr_setflags(&flags, POSIX_SPAWN_SETSIGDEF|closeOnExecFlag) == 0;
|
||||
ok = ok && posix_spawn(&pid, "/usr/bin/tar", &fileActions, &flags, (char* const*)argv, env) == 0;
|
||||
ok = ok && posix_spawnattr_destroy(&flags) == 0;
|
||||
ok = ok && posix_spawn_file_actions_destroy(&fileActions) == 0;
|
||||
ok = ok && close(in[0]) == 0;
|
||||
ok = ok && close(out[1]) == 0;
|
||||
OAK_CHECK(pipe(&in[0]) );
|
||||
OAK_CHECK(pipe(&out[0]));
|
||||
OAK_CHECK(fcntl(in[1], F_SETFD, FD_CLOEXEC));
|
||||
OAK_CHECK(fcntl(out[0], F_SETFD, FD_CLOEXEC));
|
||||
OAK_CHECK(posix_spawn_file_actions_init(&fileActions));
|
||||
OAK_CHECK(posix_spawn_file_actions_adddup2(&fileActions, in[0], 0));
|
||||
OAK_CHECK(posix_spawn_file_actions_adddup2(&fileActions, out[1], 1));
|
||||
OAK_CHECK(posix_spawn_file_actions_adddup2(&fileActions, out[1], 2));
|
||||
OAK_CHECK(posix_spawn_file_actions_addclose(&fileActions, in[0]));
|
||||
OAK_CHECK(posix_spawn_file_actions_addclose(&fileActions, out[1]));
|
||||
OAK_CHECK(posix_spawnattr_init(&flags));
|
||||
OAK_CHECK(posix_spawnattr_setflags(&flags, POSIX_SPAWN_SETSIGDEF|closeOnExecFlag));
|
||||
|
||||
if(!ok)
|
||||
int rc = posix_spawn(&pid, "/usr/bin/tar", &fileActions, &flags, (char* const*)argv, env);
|
||||
if(rc != 0)
|
||||
perror(text::format("posix_spawn(\"/usr/bin/tar\")").c_str());
|
||||
|
||||
OAK_CHECK(posix_spawnattr_destroy(&flags));
|
||||
OAK_CHECK(posix_spawn_file_actions_destroy(&fileActions));
|
||||
OAK_CHECK(close(in[0]));
|
||||
OAK_CHECK(close(out[1]));
|
||||
|
||||
if(rc != 0)
|
||||
{
|
||||
perror("launch_tbz");
|
||||
close(in[1]);
|
||||
close(out[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user