# HG changeset patch # User Binki # Date 2009-02-23 18:19:00 # Node ID 5b500e68d09101f0dd3d72a9a8026559e68508b5 # Parent 529ca20aaaa51e859fa18f0930dc0be2e051cded execio: typo in new API, added exec() diff --git a/src/common/execio.c b/src/common/execio.c --- a/src/common/execio.c +++ b/src/common/execio.c @@ -26,7 +26,7 @@ #include #include -int execio_open(const char *progname, struct execio **rem) +int execio_open(struct execio **rem, const char *progname, char *const argv[]) { /* pipe used to write to child */ int pipe_write[2]; @@ -39,6 +39,7 @@ int execio_open(const char *progname, st int childstatus; int counter; + int counter2; /* create two pipes to facilitate communication with child */ if(pipe(pipe_write)) @@ -108,17 +109,23 @@ int execio_open(const char *progname, st counter = pipe_read[0]; if(counter < pipe_read[1]) counter = pipe_read[1]; + counter2 = 0; while(counter > 2) { - close(counter); + if(!close(counter)) + counter2 ++; /* record how many descriptors we still had open :-) */ counter --; } + /* stderr is the only stream we haven't confiscated atm - just for fun - I will confiscate it later, though, to support parsing error messages */ + fprintf(stderr, "closed %d fds before execing \"%s\"\n", counter2, progname); + /* - now exec + now exec: execvp uses interpreter to find the file to exec */ + execvp(progname, argv); - return 1; /* this line should never be reached because we exec*/ + return 1; /* this line should never be reached because we exec -- unless if the exec returns something bad. Then we'd have to tell execio over the pipe about that somehow... */ } } diff --git a/src/common/execio.h b/src/common/execio.h --- a/src/common/execio.h +++ b/src/common/execio.h @@ -42,7 +42,7 @@ struct execio }; /* nonzsero return on error */ -int execio_open(struct execio **rem, const char *progname, char *cont argv[]); +int execio_open(struct execio **rem, const char *progname, char *const argv[]); /* blocks,