00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <kernel/OS.h>
00018 #include <stdlib.h>
00019 #include <unistd.h>
00020 #include <stdio.h>
00021
00022 struct pipefd {
00023 int in;
00024 int out;
00025 int err;
00026 };
00027
00028 int main(int argc, char *argv[]) {
00029
00030
00031
00032
00033
00034
00035
00036 char *progname = argv[2];
00037 char *directory = argv[1];
00038 struct pipefd *pfd;
00039 thread_id sender;
00040 void *buffer;
00041 char ** newargs;
00042 int i = 0;
00043
00044 newargs = (char**)malloc(sizeof(char*) * (argc - 1));
00045
00046 buffer = (void*)malloc(sizeof(struct pipefd));
00047
00048 receive_data(&sender, buffer, sizeof(struct pipefd));
00049 pfd = (struct pipefd*)buffer;
00050
00051 if (pfd->in > STDERR_FILENO) {
00052 if (dup2(pfd->in, STDIN_FILENO) != STDIN_FILENO) return (-1);
00053 close (pfd->in);
00054 }
00055 if (pfd->out > STDERR_FILENO) {
00056 if (dup2(pfd->out, STDOUT_FILENO) != STDOUT_FILENO) return (-1);
00057 close (pfd->out);
00058 }
00059 if (pfd->err > STDERR_FILENO) {
00060 if (dup2(pfd->err, STDERR_FILENO) != STDERR_FILENO) return (-1);
00061 close (pfd->err);
00062 }
00063
00064 for (i=3;i<=argc;i++){
00065 newargs[i-3] = argv[i];
00066 }
00067
00068
00069 send_data(sender,1,NULL,0);
00070
00071 if (directory != NULL)
00072 chdir(directory);
00073 execve (progname, newargs, environ);
00074
00075 return (-1);
00076 }