2002-03-27 00:58:31 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) Andrew Tridgell 2002
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2002-03-26 15:46:43 +01:00
|
|
|
#include "ccache.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
execute a compiler backend, capturing all output to the given paths
|
|
|
|
the full path to the compiler to run is in argv[0]
|
|
|
|
*/
|
2002-03-27 01:39:06 +01:00
|
|
|
int execute(char **argv,
|
|
|
|
const char *path_stdout,
|
|
|
|
const char *path_stderr)
|
2002-03-26 15:46:43 +01:00
|
|
|
{
|
|
|
|
pid_t pid;
|
2002-03-27 01:39:06 +01:00
|
|
|
int status;
|
2002-03-26 15:46:43 +01:00
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
if (pid == -1) fatal("Failed to fork");
|
|
|
|
|
|
|
|
if (pid == 0) {
|
2002-03-27 01:39:06 +01:00
|
|
|
int fd;
|
|
|
|
|
2002-03-26 16:12:16 +01:00
|
|
|
unlink(path_stdout);
|
2002-03-26 15:46:43 +01:00
|
|
|
fd = open(path_stdout, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644);
|
|
|
|
if (fd == -1) {
|
|
|
|
exit(STATUS_NOCACHE);
|
|
|
|
}
|
|
|
|
dup2(fd, 1);
|
|
|
|
close(fd);
|
|
|
|
|
2002-03-26 16:12:16 +01:00
|
|
|
unlink(path_stderr);
|
2002-03-26 15:46:43 +01:00
|
|
|
fd = open(path_stderr, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644);
|
|
|
|
if (fd == -1) {
|
|
|
|
exit(STATUS_NOCACHE);
|
|
|
|
}
|
|
|
|
dup2(fd, 2);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
exit(execv(argv[0], argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (waitpid(pid, &status, 0) != pid) {
|
|
|
|
fatal("waitpid failed");
|
|
|
|
}
|
2002-03-27 01:39:06 +01:00
|
|
|
|
|
|
|
return WEXITSTATUS(status);
|
2002-03-26 15:46:43 +01:00
|
|
|
}
|