Added error handling to read calls for blocks

This commit is contained in:
Linden Krouse 2016-03-26 12:55:04 -04:00
parent ec105d0f59
commit 7261b8cf8e
2 changed files with 24 additions and 9 deletions

View file

@ -22,11 +22,12 @@ static void ya_exec_redir_once(ya_block_t *blk) {
execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
_exit(EXIT_SUCCESS);
}
else {
wait(NULL);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk);
}
ssize_t read_ret = read(opipe[0], blk->buf, BUFSIZE);
if (read_ret < 0) {
fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
} else if (read_ret > 0) {
ya_draw_pango_text(blk);
}
}
@ -47,7 +48,10 @@ static void ya_exec_redir_period(ya_block_t *blk) {
blk->pid = pid;
//close(opipe[1]);
wait(NULL);
if (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ssize_t read_ret = read(opipe[0], blk->buf, BUFSIZE);
if (read_ret < 0) {
fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
} else if (read_ret > 0) {
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
@ -69,9 +73,19 @@ static void ya_exec_redir_persist(ya_block_t *blk) {
}
blk->pid = pid;
close(opipe[1]);
while (read(opipe[0], blk->buf, BUFSIZE) != 0) {
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
ssize_t read_ret;
while (1) {
read_ret = read(opipe[0], blk->buf, BUFSIZE);
if(read_ret == 0) {
break;
} else if (read_ret < 0) {
fprintf(stderr, "Error with block %s: %s\n", blk->name, strerror(errno));
continue;
} else {
ya_draw_pango_text(blk);
memset(blk->buf, '\0', BUFSIZE);
}
}
}

View file

@ -10,6 +10,7 @@
#define YABAR_H
#include <stdio.h>
#include <errno.h>
#define __USE_XOPEN2K //for setenv implicit function decleration warning
#include <stdlib.h>
#include <string.h>