mirror of
https://github.com/vale981/yabar
synced 2025-03-05 17:41:40 -05:00
Added error handling to read calls for blocks
This commit is contained in:
parent
ec105d0f59
commit
7261b8cf8e
2 changed files with 24 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue