Skip to content

Commit

Permalink
is throwing errors #16
Browse files Browse the repository at this point in the history
  • Loading branch information
arun11299 committed Sep 30, 2018
1 parent 05c76a5 commit a90174c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
28 changes: 15 additions & 13 deletions subprocess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,29 +310,31 @@ namespace util
// Requires Buffer to be of type class Buffer
static inline int read_all(int fd, Buffer& buf)
{
size_t orig_size = buf.size();
int increment = orig_size;
auto buffer = buf.data();
int total_bytes_read = 0;
int fill_sz = buf.size();

while (1) {
int rd_bytes = read_atmost_n(fd, buffer, buf.size());
if (rd_bytes == increment) {
// Resize the buffer to accomodate more
orig_size = orig_size * 1.5;
increment = orig_size - buf.size();
buf.resize(orig_size);
const int rd_bytes = read_atmost_n(fd, buffer, fill_sz);

if (rd_bytes == -1) { // Read finished
if (total_bytes_read == 0) return -1;
break;

} else if (rd_bytes == fill_sz) { // Buffer full
const auto orig_sz = buf.size();
const auto new_sz = orig_sz * 2;
buf.resize(new_sz);
fill_sz = new_sz - orig_sz;

//update the buffer pointer
buffer = buf.data();
buffer += rd_bytes;
total_bytes_read += rd_bytes;

} else if (rd_bytes != -1) {
} else { // Partial data ? Continue reading
total_bytes_read += rd_bytes;
break;

} else {
if (total_bytes_read == 0) return -1;
fill_sz -= rd_bytes;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/cat_fredirect.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
through stdin to stdout
through stdin to stdoutthrough stdin to stdoutthrough stdin to stdoutthrough stdin to stdout
Binary file removed test/test_cat
Binary file not shown.
Binary file removed test/test_env
Binary file not shown.
Binary file removed test/test_err_redirection
Binary file not shown.
Binary file removed test/test_ret_code
Binary file not shown.
Binary file removed test/test_subprocess
Binary file not shown.
2 changes: 2 additions & 0 deletions test/write_err.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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
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 a90174c

Please sign in to comment.