X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=pipex_posix.c;h=f53d74f7a8eacace0b4af8670a5074dc1088a331;hp=737f9ce66b9d99c106f3b1509eb409c3b3f707d8;hb=60900035e6d0309705f2326ee50edc52386305e9;hpb=683b5dc504dc5d930b617cfba09011e41e51dd16 diff --git a/pipex_posix.c b/pipex_posix.c index 737f9ce..f53d74f 100644 --- a/pipex_posix.c +++ b/pipex_posix.c @@ -3,6 +3,7 @@ // includes #include +#include #include #include #include @@ -90,7 +91,7 @@ void pipex_open(pipex_t *pipex, my_fatal("pipex_open(): pipe(): %s\n",strerror(errno)); } - // create the child process + // create the child process pipex->pid = fork(); @@ -120,11 +121,14 @@ void pipex_open(pipex_t *pipex, // attach standard error to standard output // commenting this out gives error messages on the console - /* my_dup2(STDOUT_FILENO,STDERR_FILENO); */ + my_dup2(STDOUT_FILENO,STDERR_FILENO); if(chdir(working_dir)){ - my_fatal("pipex_open(): cannot change directory: %s\n", - strerror(errno)); + printf("%s pipex_open(): %s: %s\n", + PIPEX_MAGIC, + working_dir, + strerror(errno)); + goto wait_for_eof; } // launch the new executable file @@ -132,8 +136,14 @@ void pipex_open(pipex_t *pipex, execvp(argv[0],&argv[0]); // execvp() only returns when an error has occured - - my_fatal("engine_open(): execvp(): %s: %s\n",argv[0],strerror(errno)); + + printf("%s pipex_open(): execvp(): %s: %s\n", + PIPEX_MAGIC, + argv[0], + strerror(errno)); + wait_for_eof: + while(fgets(string,StringSize,stdin)); + exit(EXIT_SUCCESS); } else { // pid > 0 @@ -263,7 +273,9 @@ bool pipex_readln(pipex_t *pipex, char *string){ pipex->state|=PIPEX_EOF; return FALSE; } - + if(strncmp(PIPEX_MAGIC,string,strlen(PIPEX_MAGIC))==0){ + my_fatal("%s\n",string+strlen(PIPEX_MAGIC)+1); + } return TRUE; }