mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
Reformat to be Unix format. Check the program
with pfind() to see if executable.
This commit is contained in:
parent
e1b17f11c1
commit
b968757017
1 changed files with 135 additions and 145 deletions
|
@ -8,7 +8,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
/* from pfind.c */
|
||||
char *pfind( char *name );
|
||||
extern char *pfind(const char *name);
|
||||
|
||||
pid_t
|
||||
exec0(const char *path, char *const argv[], char *const envp[],
|
||||
|
@ -18,25 +18,20 @@ exec0(const char *path, char *const argv[], char *const envp[],
|
|||
pid_t childpid;
|
||||
char *full_path;
|
||||
|
||||
//
|
||||
// Handle this error case, we need the full path for execve() below.
|
||||
//
|
||||
if (path[0] != '/' && path[0] != '.') {
|
||||
/*
|
||||
* We use pfind() to check that the program exists and is an executable.
|
||||
* If not pass the error up.
|
||||
*/
|
||||
full_path = pfind(path);
|
||||
//full_path = pathfind (getenv ("PATH"), path, "rx");
|
||||
if (full_path == NULL) {
|
||||
fprintf(stderr, "Unable to find full path for \"%s\"\n", path);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
full_path = strdup(path);
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure we can create our pipes before forking.
|
||||
//
|
||||
if( channels != NULL )
|
||||
{
|
||||
/*
|
||||
* Make sure we can create our pipes before forking.
|
||||
*/
|
||||
if (channels != NULL) {
|
||||
if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
|
||||
fprintf(stderr, "%s(%d): returning due to error.\n",
|
||||
__FUNCTION__, __LINE__);
|
||||
|
@ -57,8 +52,7 @@ exec0(const char *path, char *const argv[], char *const envp[],
|
|||
|
||||
chdir(dirpath);
|
||||
|
||||
if( channels != NULL )
|
||||
{
|
||||
if (channels != NULL) {
|
||||
/* Close the write end of pipe0 */
|
||||
if (close(pipe0[1]) == -1)
|
||||
perror("close(pipe0[1])");
|
||||
|
@ -86,12 +80,9 @@ exec0(const char *path, char *const argv[], char *const envp[],
|
|||
close(fd++);
|
||||
}
|
||||
|
||||
if( envp[0] == NULL )
|
||||
{
|
||||
if (envp[0] == NULL) {
|
||||
execv(full_path, argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
execve(full_path, argv, envp);
|
||||
}
|
||||
|
||||
|
@ -101,8 +92,7 @@ exec0(const char *path, char *const argv[], char *const envp[],
|
|||
|
||||
char b;
|
||||
|
||||
if( channels != NULL )
|
||||
{
|
||||
if (channels != NULL) {
|
||||
/* close the read end of pipe1 */
|
||||
if (close(pipe0[0]) == -1)
|
||||
perror("close(pipe0[0])");
|
||||
|
|
Loading…
Add table
Reference in a new issue