X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/5a218e990ca05e6bb087f4fecaaa4807fbe69528..6cab2d57199edd8cc9e292ded04558fe9279962b:/slstatus.c?ds=inline diff --git a/slstatus.c b/slstatus.c index 2d5d173..e6e726e 100644 --- a/slstatus.c +++ b/slstatus.c @@ -30,7 +30,6 @@ #include "extern/arg.h" #include "extern/strlcat.h" -#include "extern/strlcpy.h" #include "extern/concat.h" struct arg { @@ -406,19 +405,22 @@ ram_used(void) static char * run_command(const char *cmd) { + char *nlptr; FILE *fp; - char buf[1024] = "n/a"; + char buf[1024] = UNKNOWN_STR; fp = popen(cmd, "r"); if (fp == NULL) { warn("Failed to get command output for %s", cmd); return smprintf(UNKNOWN_STR); } - fgets(buf, sizeof(buf)-1, fp); + fgets(buf, sizeof(buf), fp); pclose(fp); - buf[strlen(buf)] = '\0'; - strtok(buf, "\n"); + + if ((nlptr = strstr(buf, "\n")) != NULL) { + nlptr[0] = '\0'; + } return smprintf("%s", buf); } @@ -441,7 +443,7 @@ swap_free(void) buf[bytes_read] = '\0'; fclose(fp); if (bytes_read == 0 || bytes_read == sizeof(buf)) { - warn("Failed to read /proc/meminfo\n"); + warn("Failed to read from /proc/meminfo"); return smprintf(UNKNOWN_STR); } @@ -475,7 +477,7 @@ swap_perc(void) buf[bytes_read] = '\0'; fclose(fp); if (bytes_read == 0 || bytes_read == sizeof(buf)) { - warn("Failed to read /proc/meminfo\n"); + warn("Failed to read from /proc/meminfo"); return smprintf(UNKNOWN_STR); } @@ -512,7 +514,7 @@ swap_total(void) buf[bytes_read] = '\0'; fclose(fp); if (bytes_read == 0 || bytes_read == sizeof(buf)) { - warn("Failed to read /proc/meminfo\n"); + warn("Failed to read from /proc/meminfo"); return smprintf(UNKNOWN_STR); } @@ -543,7 +545,7 @@ swap_used(void) buf[bytes_read] = '\0'; fclose(fp); if (bytes_read == 0 || bytes_read == sizeof(buf)) { - warn("Failed to read /proc/meminfo\n"); + warn("Failed to read from /proc/meminfo"); return smprintf(UNKNOWN_STR); }