aboutsummaryrefslogtreecommitdiff
path: root/dwmblocks.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwmblocks.c')
-rw-r--r--dwmblocks.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/dwmblocks.c b/dwmblocks.c
index befd252..c8f77b7 100644
--- a/dwmblocks.c
+++ b/dwmblocks.c
@@ -58,25 +58,26 @@ static int returnStatus = 0;
//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
{
- strcpy(output, block->icon);
+ //make sure status is same until output is ready
+ char tempstatus[CMDLENGTH] = {0};
+ strcpy(tempstatus, block->icon);
FILE *cmdf = popen(block->command, "r");
if (!cmdf)
return;
int i = strlen(block->icon);
- fgets(output+i, CMDLENGTH-i-delimLen, cmdf);
- i = strlen(output);
- if (i == 0) {
- //return if block and command output are both empty
- pclose(cmdf);
- return;
- }
- //only chop off newline if one is present at the end
- i = output[i-1] == '\n' ? i-1 : i;
- if (delim[0] != '\0') {
- strncpy(output+i, delim, delimLen);
+ fgets(tempstatus+i, CMDLENGTH-i-delimLen, cmdf);
+ i = strlen(tempstatus);
+ //if block and command output are both not empty
+ if (i != 0) {
+ //only chop off newline if one is present at the end
+ i = tempstatus[i-1] == '\n' ? i-1 : i;
+ if (delim[0] != '\0') {
+ strncpy(tempstatus+i, delim, delimLen);
+ }
+ else
+ tempstatus[i++] = '\0';
}
- else
- output[i++] = '\0';
+ strcpy(output, tempstatus);
pclose(cmdf);
}