Skip to content

Commit

Permalink
Reading from a pipe is messed up #14
Browse files Browse the repository at this point in the history
  • Loading branch information
arun11299 committed Apr 16, 2018
1 parent b5e3da1 commit 05c76a5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions subprocess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ namespace util
int eintr_cnter = 0;

while (1) {
int read_bytes = read(fd, buf, read_upto);
int read_bytes = read(fd, buf + rbytes, read_upto - rbytes);
if (read_bytes == -1) {
if (errno == EINTR) {
if (eintr_cnter >= 50) return -1;
Expand Down Expand Up @@ -322,11 +322,15 @@ namespace util
orig_size = orig_size * 1.5;
increment = orig_size - buf.size();
buf.resize(orig_size);
//update the buffer pointer
buffer = buf.data();
buffer += rd_bytes;
total_bytes_read += rd_bytes;

} else if (rd_bytes != -1) {
total_bytes_read += rd_bytes;
break;

} else {
if (total_bytes_read == 0) return -1;
break;
Expand Down Expand Up @@ -1423,12 +1427,12 @@ namespace detail {
} else if (stream_->output()) {
// Read till EOF
// ATTN: This could be blocking, if the process
// at the other end screws up, we get screwed up as well
// at the other end screws up, we get screwed as well
obuf.add_cap(out_buf_cap_);

int rbytes = util::read_all(
fileno(stream_->output()),
obuf.buf);
fileno(stream_->output()),
obuf.buf);

if (rbytes == -1) {
throw OSError("read to obuf failed", errno);
Expand Down
Binary file modified test/test_err_redirection
Binary file not shown.
Binary file modified test/test_subprocess
Binary file not shown.
2 changes: 1 addition & 1 deletion test/write_err.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
>&2 echo "writing error to stderr"
>&2 echo "This is going to be a big chunk of error text consisting of garbage words that would never make sense....so here it goes....shouldnt I be doing my work instead ???? ...anyways....lets get to it......dsmvnskmnv;lsdnv;la,mdfv;, lasdnvs, dv;lknvlka;dv laldmflasmdlgvma lm glfdmg lasfgl;mflgms,vdmlmsdfl'bmsldfkmblsdfm blksdfmblk fsdl,b sdlfnbksan kjskanfkjbhv snf p'owMF;OANDOPGIHWEPO;JFOIEHGUYHT JNTG JWEBGIJN FV SDKMNV KJNKJ nokfnrgok weoirgoinfs ijbzx,mv;lksdcnvpisfuhgu wnergorgok nvglk;bn;mkf bkngfkbm fdlb;gfnb ;kdfgn b,mfdl's,g'l;am nsgaosnblm;adrg;lnklf nglkfmnvklb njfknblsmdnkfngsjdfbgsjdbghjb iblnrfgiof n gjsndv vewflkjvekrjgnlkmv mjbeijdfnwek vkijnnfg'koqrnbon nq'eopkfm[qef[lfkdnb ;smknv jk fnkmv ntipjvn kbvn iprtu ghj9p84w5toihnvlkmnlmk nvoijh90rjqo3mrok34 nfkm nnkof nerokmnrgo[j0igjwlkngvmfgnvml oirejgoiewjrfgoiwejrgko[ mwbkm grioejqg[ktrwngk;wnmb;mn;wfkb oirjgiontrgmnwe;fklvnfiobjneiorgn;mbn ijorgenowg;lwbenkownfboiwnrtgiovwnrtblntbontriobnwkrn; onboirw noignjwmKFCV;MKNSDVIUNRIPTN5I KNVK;JN ION EOQWNQ;LDKN V;FMNVKFN[B WPORJGOP[ WLERGNA;SLDKNV;MF NPOINRG;JWN;KNRPEFGI9485JBEKMSD NK;NKL; NFOSAJFKOSNKMN;CV, KAD;FKM;SOGMVLKSMD;,R F;OKA;FL APSLFM ADL;SKOK OKNEW KDJFOKSDJ Alpwpowejgoplwefkmglk p[reg porej gokwem vkl wmo ao[jk [klqmpkoem gpofem lksjn zflkvbn;kf hgioniog krngkmadnv;mfsdn bkleqrjl;wgnpoekw jqbfk mv;lm,redop[ jor[f klqr3ko[j vioadm ;lksdcmn ovj['or'aewnjkopj 'wk;w;k fwrite_err.sh sadkjlbnlfkblfkn blndsf kjwern gfpjknerkgn fknv k;qkgn kfv mscvlkmsn ldkfv nkamdkmv efkgv n;kemf mvwfbkm nfgkmbk bklwnmgklwmtrklgnfkl;b nwkjn glkwmfn lkmnrknwrkpg nkf nlmk nwljkengjklnwflgbnflkjbngkljwfgbn jnk wngpkwrtgnpo n"
2 changes: 2 additions & 0 deletions test/write_err.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
writing error to stderr
This is going to be a big chunk of error text consisting of garbage words that would never make sense....so here it goes....shouldnt I be doing my work instead ???? ...anyways....lets get to it......dsmvnskmnv;lsdnv;la,mdfv;, lasdnvs, dv;lknvlka;dv laldmflasmdlgvma lm glfdmg lasfgl;mflgms,vdmlmsdfl'bmsldfkmblsdfm blksdfmblk fsdl,b sdlfnbksan kjskanfkjbhv snf p'owMF;OANDOPGIHWEPO;JFOIEHGUYHT JNTG JWEBGIJN FV SDKMNV KJNKJ nokfnrgok weoirgoinfs ijbzx,mv;lksdcnvpisfuhgu wnergorgok nvglk;bn;mkf bkngfkbm fdlb;gfnb ;kdfgn b,mfdl's,g'l;am nsgaosnblm;adrg;lnklf nglkfmnvklb njfknblsmdnkfngsjdfbgsjdbghjb iblnrfgiof n gjsndv vewflkjvekrjgnlkmv mjbeijdfnwek vkijnnfg'koqrnbon nq'eopkfm[qef[lfkdnb ;smknv jk fnkmv ntipjvn kbvn iprtu ghj9p84w5toihnvlkmnlmk nvoijh90rjqo3mrok34 nfkm nnkof nerokmnrgo[j0igjwlkngvmfgnvml oirejgoiewjrfgoiwejrgko[ mwbkm grioejqg[ktrwngk;wnmb;mn;wfkb oirjgiontrgmnwe;fklvnfiobjneiorgn;mbn ijorgenowg;lwbenkownfboiwnrtgiovwnrtblntbontriobnwkrn; onboirw noignjwmKFCV;MKNSDVIUNRIPTN5I KNVK;JN ION EOQWNQ;LDKN V;FMNVKFN[B WPORJGOP[ WLERGNA;SLDKNV;MF NPOINRG;JWN;KNRPEFGI9485JBEKMSD NK;NKL; NFOSAJFKOSNKMN;CV, KAD;FKM;SOGMVLKSMD;,R F;OKA;FL APSLFM ADL;SKOK OKNEW KDJFOKSDJ Alpwpowejgoplwefkmglk p[reg porej gokwem vkl wmo ao[jk [klqmpkoem gpofem lksjn zflkvbn;kf hgioniog krngkmadnv;mfsdn bkleqrjl;wgnpoekw jqbfk mv;lm,redop[ jor[f klqr3ko[j vioadm ;lksdcmn ovj['or'aewnjkopj 'wk;w;k fwrite_err.sh sadkjlbnlfkblfkn blndsf kjwern gfpjknerkgn fknv k;qkgn kfv mscvlkmsn ldkfv nkamdkmv efkgv n;kemf mvwfbkm nfgkmbk bklwnmgklwmtrklgnfkl;b nwkjn glkwmfn lkmnrknwrkpg nkf nlmk nwljkengjklnwflgbnflkjbngkljwfgbn jnk wngpkwrtgnpo n
This is going to be a big chunk of error text consisting of garbage words that would never make sense....so here it goes....shouldnt I be doing my work instead ???? ...anyways....lets get to it......dsmvnskmnv;lsdnv;la,mdfv;, lasdnvs, dv;lknvlka;dv laldmflasmdlgvma lm glfdmg lasfgl;mflgms,vdmlmsdfl'bmsldfkmblsdfm blksdfmblk fsdl,b sdlfnbksan kjskanfkjbhv snf p'owMF;OANDOPGIHWEPO;JFOIEHGUYHT JNTG JWEBGIJN FV SDKMNV KJNKJ nokfnrgok weoirgoinfs ijbzx,mv;lksdcnvpisfuhgu wnergorgok nvglk;bn;mkf bkngfkbm fdlb;gfnb ;kdfgn b,mfdl's,g'l;am nsgaosnblm;adrg;lnklf nglkfmnvklb njfknblsmdnkfngsjdfbgsjdbghjb iblnrfgiof n gjsndv vewflkjvekrjgnlkmv mjbeijdfnwek vkijnnfg'koqrnbon nq'eopkfm[qef[lfkdnb ;smknv jk fnkmv ntipjvn kbvn iprtu ghj9p84w5toihnvlkmnlmk nvoijh90rjqo3mrok34 nfkm nnkof nerokmnrgo[j0igjwlkngvmfgnvml oirejgoiewjrfgoiwejrgko[ mwbkm grioejqg[ktrwngk;wnmb;mn;wfkb oirjgiontrgmnwe;fklvnfiobjneiorgn;mbn ijorgenowg;lwbenkownfboiwnrtgiovwnrtblntbontriobnwkrn; onboirw noignjwmKFCV;MKNSDVIUNRIPTN5I KNVK;JN ION EOQWNQ;LDKN V;FMNVKFN[B WPORJGOP[ WLERGNA;SLDKNV;MF NPOINRG;JWN;KNRPEFGI9485JBEKMSD NK;NKL; NFOSAJFKOSNKMN;CV, KAD;FKM;SOGMVLKSMD;,R F;OKA;FL APSLFM ADL;SKOK OKNEW KDJFOKSDJ Alpwpowejgoplwefkmglk p[reg porej gokwem vkl wmo ao[jk [klqmpkoem gpofem lksjn zflkvbn;kf hgioniog krngkmadnv;mfsdn bkleqrjl;wgnpoekw jqbfk mv;lm,redop[ jor[f klqr3ko[j vioadm ;lksdcmn ovj['or'aewnjkopj 'wk;w;k fwrite_err.sh sadkjlbnlfkblfkn blndsf kjwern gfpjknerkgn fknv k;qkgn kfv mscvlkmsn ldkfv nkamdkmv efkgv n;kemf mvwfbkm nfgkmbk bklwnmgklwmtrklgnfkl;b nwkjn glkwmfn lkmnrknwrkpg nkf nlmk nwljkengjklnwflgbnflkjbngkljwfgbn jnk wngpkwrtgnpo n

0 comments on commit 05c76a5

Please sign in to comment.