mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Handle empty command outputs properly
This commit is contained in:
parent
22916019dc
commit
68d3792030
11
main.c
11
main.c
@ -67,9 +67,9 @@ int getStatus(char* new, char* old) {
|
|||||||
|
|
||||||
for (int i = 0; i < LEN(blocks); i++) {
|
for (int i = 0; i < LEN(blocks); i++) {
|
||||||
#ifdef TRAILING_DELIMITER
|
#ifdef TRAILING_DELIMITER
|
||||||
if (strlen(outputs[i]) > (blocks[i].signal > 0))
|
if (strlen(outputs[i]))
|
||||||
#else
|
#else
|
||||||
if (strlen(new) && strlen(outputs[i]) > (blocks[i].signal > 0))
|
if (strlen(new) && strlen(outputs[i]))
|
||||||
#endif
|
#endif
|
||||||
strcat(new, DELIMITER);
|
strcat(new, DELIMITER);
|
||||||
strcat(new, outputs[i]);
|
strcat(new, outputs[i]);
|
||||||
@ -78,18 +78,21 @@ int getStatus(char* new, char* old) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateBlock(int i) {
|
void updateBlock(int i) {
|
||||||
|
char* output = outputs[i];
|
||||||
char buffer[LEN(outputs[0])];
|
char buffer[LEN(outputs[0])];
|
||||||
int bytesRead = read(pipes[i][0], buffer, LEN(buffer));
|
int bytesRead = read(pipes[i][0], buffer, LEN(buffer));
|
||||||
buffer[bytesRead - 1] = '\0';
|
buffer[bytesRead - 1] = '\0';
|
||||||
|
|
||||||
// Clear the pipe
|
|
||||||
if (bytesRead == LEN(buffer)) {
|
if (bytesRead == LEN(buffer)) {
|
||||||
|
// Clear the pipe
|
||||||
char ch;
|
char ch;
|
||||||
while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n')
|
while (read(pipes[i][0], &ch, 1) == 1 && ch != '\n')
|
||||||
;
|
;
|
||||||
|
} else if (bytesRead == 2) {
|
||||||
|
output[0] = '\0';
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* output = outputs[i];
|
|
||||||
if (blocks[i].signal > 0) {
|
if (blocks[i].signal > 0) {
|
||||||
output[0] = blocks[i].signal;
|
output[0] = blocks[i].signal;
|
||||||
output++;
|
output++;
|
||||||
|
Loading…
Reference in New Issue
Block a user