possibly slightly faster win32 process spawn from http://lists.samba.org/archive/ccache/2006q3/000242.html
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10993 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5e50d29bb3
commit
d115e52bc0
1 changed files with 51 additions and 0 deletions
|
|
@ -55,6 +55,8 @@ int execute(char **argv,
|
||||||
const char *path_stderr)
|
const char *path_stderr)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#if 0
|
||||||
PROCESS_INFORMATION pinfo;
|
PROCESS_INFORMATION pinfo;
|
||||||
STARTUPINFO sinfo;
|
STARTUPINFO sinfo;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
@ -107,6 +109,55 @@ int execute(char **argv,
|
||||||
CloseHandle(pinfo.hThread);
|
CloseHandle(pinfo.hThread);
|
||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
|
#else /* possibly slightly faster */
|
||||||
|
/* Should be portable */
|
||||||
|
int status = -2;
|
||||||
|
int fd, std_od = -1, std_ed = -1;
|
||||||
|
|
||||||
|
/* TODO: needs moving after possible exit() below, but before stdout is redirected */
|
||||||
|
if (ccache_verbose) {
|
||||||
|
display_execute_args(argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink(path_stdout);
|
||||||
|
std_od = _dup(1);
|
||||||
|
fd = _open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||||
|
if (fd == -1) {
|
||||||
|
status = STATUS_NOCACHE;
|
||||||
|
cc_log("stdout error: failed to open %s\n", path_stdout);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
_dup2(fd, 1);
|
||||||
|
_close(fd);
|
||||||
|
|
||||||
|
unlink(path_stderr);
|
||||||
|
fd = _open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
|
||||||
|
std_ed = _dup(2);
|
||||||
|
if (fd == -1) {
|
||||||
|
status = STATUS_NOCACHE;
|
||||||
|
cc_log("stderr error: failed to open %s\n", path_stderr);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
_dup2(fd, 2);
|
||||||
|
_close(fd);
|
||||||
|
|
||||||
|
/* Spawn process (_exec* familly doesn't return) */
|
||||||
|
status = _spawnv(_P_WAIT, argv[0], (const char **)argv);
|
||||||
|
|
||||||
|
out:
|
||||||
|
cc_log("%s:\n stdout -> %s\n stderr -> %s\n process status=%i\n",
|
||||||
|
argv[0], path_stdout, path_stderr, status);
|
||||||
|
if (status == -1) cc_log("Error %i: %s\n", errno, strerror(errno));
|
||||||
|
|
||||||
|
/* Restore descriptors */
|
||||||
|
if (std_od != -1) _dup2(std_od, 1);
|
||||||
|
if (std_ed != -1) _dup2(std_ed, 2);
|
||||||
|
_flushall();
|
||||||
|
|
||||||
|
return (status>0);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue