diff --git a/basis/io/backend/unix/unix-tests.factor b/basis/io/backend/unix/unix-tests.factor index 5417b9b178..2e94d7a2df 100644 --- a/basis/io/backend/unix/unix-tests.factor +++ b/basis/io/backend/unix/unix-tests.factor @@ -1,7 +1,7 @@ USING: io.files io.files.temp io.directories io.sockets io kernel threads namespaces tools.test continuations strings byte-arrays sequences prettyprint system io.encodings.binary io.encodings.ascii -io.streams.duplex destructors make ; +io.streams.duplex destructors make io.launcher ; IN: io.backend.unix.tests ! Unix domain stream sockets @@ -138,3 +138,13 @@ datagram-client delete-file input-stream get send ] with-file-reader ] must-fail + +! closing stdin caused some problems +[ ] [ + [ + vm , + "-i=" image append , + "-run=none" , + "-e=USING: destructors namespaces io calendar threads ; input-stream get dispose 1 seconds sleep" , + ] { } make try-process +] unit-test diff --git a/vm/os-unix.c b/vm/os-unix.c index 952d2683cf..97c29d8c6e 100755 --- a/vm/os-unix.c +++ b/vm/os-unix.c @@ -216,18 +216,21 @@ void safe_write(int fd, void *data, size_t size) fatal_error("error writing fd",errno); } -void safe_read(int fd, void *data, size_t size) +bool safe_read(int fd, void *data, size_t size) { ssize_t bytes = read(fd,data,size); if(bytes < 0) { if(errno == EINTR) - safe_read(fd,data,size); + return safe_read(fd,data,size); else + { fatal_error("error reading fd",errno); + return false; + } } - else if(bytes != size) - fatal_error("unexpected eof on fd",bytes); + else + return (bytes == size); } void *stdin_loop(void *arg) @@ -237,7 +240,9 @@ void *stdin_loop(void *arg) while(loop_running) { - safe_read(control_read,buf,1); + if(!safe_read(control_read,buf,1)) + break; + if(buf[0] != 'X') fatal_error("stdin_loop: bad data on control fd",buf[0]); @@ -258,16 +263,15 @@ void *stdin_loop(void *arg) { safe_write(size_write,&bytes,sizeof(bytes)); - if(write(stdin_write,buf,bytes) != bytes) + if(!check_write(stdin_write,buf,bytes)) loop_running = false; break; } } } - safe_close(stdin_write); - safe_close(control_write); + safe_close(control_read); return NULL; }