diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-02-10 18:15:40 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-02-10 18:15:40 +0100 |
commit | 9e972f87c8b05fafc5574e4daf7591711a99b012 (patch) | |
tree | 10e32012aa6187be74a9645870162b8163e910f1 | |
parent | c32462ce9f65d3fc09766e48bc5bea967d2a2de4 (diff) |
fixed bug where if the command was invalid, it wouldn't kill the call to sh
-rw-r--r-- | dwmstatus/custom.diff | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/dwmstatus/custom.diff b/dwmstatus/custom.diff index 6b82e5f..14db8a7 100644 --- a/dwmstatus/custom.diff +++ b/dwmstatus/custom.diff @@ -1,5 +1,5 @@ diff --git a/dwmstatus.c b/dwmstatus.c -index d2a4b03..307d290 100644 +index d2a4b03..4f09dde 100644 --- a/dwmstatus.c +++ b/dwmstatus.c @@ -17,8 +17,6 @@ @@ -29,59 +29,42 @@ index d2a4b03..307d290 100644 } if (remcap < 0 || descap < 0) -@@ -175,47 +173,86 @@ gettemperature(char *base, char *sensor) +@@ -175,47 +173,69 @@ gettemperature(char *base, char *sensor) return smprintf("%02.0f°C", atof(co) / 1000); } +char * -+getpartition(char *partition) { -+ char *co = smprintf("df -lh | grep %s | tr -s ' ' | cut -d ' ' -f 4 | tr -d '\n'", partition); -+ FILE *fd = popen(co, "r"); ++getresult(char *command) { ++ FILE *fd = popen(command, "r"); ++ char ret[100]; + if (fd == NULL) -+ return smprintf("invalid"); ++ strcpy(ret, "invalid"); + -+ char ret[8]; -+ if (fgets(ret, 8, fd) == NULL) -+ return smprintf("invalid"); ++ if (fgets(ret, 100, fd) == NULL) ++ strcpy(ret, "invalid"); + + if (pclose(fd) == -1) -+ return smprintf("invalid"); ++ strcpy(ret, "invalid"); + + return smprintf("%s", ret); +} + +char * -+gettemp() { -+ char *co = smprintf("sensors amdgpu-pci-0400 | grep edge | cut -c 16-22"); -+ FILE *fd = popen(co, "r"); -+ if (fd == NULL) -+ return smprintf("invalid"); -+ -+ char ret[8]; -+ if (fgets(ret, 8, fd) == NULL) -+ return smprintf("invalid"); -+ -+ if (pclose(fd) == -1) -+ return smprintf("invalid"); ++getpartition(char *partition) { ++ char *co = smprintf("df -lh | grep %s | tr -s ' ' | cut -d ' ' -f 4 | tr -d '\n'", partition); ++ return getresult(co); ++} + -+ return smprintf("%s", ret); ++char * ++gettemp() { ++ char *co = smprintf("sensors amdgpu-pci-0400 | grep edge | cut -c 16-22 | tr -d '\n'"); ++ return getresult(co); +} + +char * +gettrack() { -+ char *co = smprintf("mpc -h core-a.lan | head -n 1 | tr -d '\n'" ); -+ FILE *fd = popen(co, "r"); -+ if (fd == NULL) -+ return smprintf("invalid"); -+ -+ char ret[100]; -+ if (fgets(ret, 100, fd) == NULL) -+ return smprintf("invalid"); -+ -+ if (pclose(fd) == -1) -+ return smprintf("invalid"); -+ -+ return smprintf("%s", ret); ++ char *co = smprintf("mpc -h core-a.lan | head -n 1 | tr -d '\n'"); ++ return getresult(co); +} + int |