Fixed bug in getcmd

This commit is contained in:
Ashish Kumar Yadav 2021-01-20 13:07:11 +05:30
parent 3e97aa9be7
commit 9329d0dfe6

View file

@ -19,8 +19,8 @@ typedef struct {
char *const pathc; char *const pathc;
const int interval; const int interval;
const int signal; const int signal;
char cmdoutcur[CMDLENGTH]; char cmdoutcur[CMDLENGTH + 1];
char cmdoutprv[CMDLENGTH]; char cmdoutprv[CMDLENGTH + 1];
} Block; } Block;
#include "blocks.h" #include "blocks.h"
@ -111,12 +111,20 @@ getcmd(Block *block, int sigval)
perror("getcmd - child - execv"); perror("getcmd - child - execv");
_exit(127); _exit(127);
default: default:
{
size_t trd = 0;
ssize_t rd;
close(fd[1]); close(fd[1]);
if (read(fd[0], block->cmdoutcur, CMDLENGTH) == -1) { do
rd = read(fd[0], block->cmdoutcur + trd, CMDLENGTH - trd);
while (rd > 0 && (trd += rd) < CMDLENGTH);
if (rd == -1) {
perror("getcmd - read"); perror("getcmd - read");
exit(1); exit(1);
} }
close(fd[0]); close(fd[0]);
}
} }
} }