Xinqi Bao's Git
projects
/
slstatus.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
remove newlines from warn() in swap_*(), those functions already print a newline...
[slstatus.git]
/
slstatus.c
diff --git
a/slstatus.c
b/slstatus.c
index
73e0f2c
..
e6e726e
100644
(file)
--- a/
slstatus.c
+++ b/
slstatus.c
@@
-405,8
+405,9
@@
ram_used(void)
static char *
run_command(const char *cmd)
{
static char *
run_command(const char *cmd)
{
+ char *nlptr;
FILE *fp;
FILE *fp;
- char buf[1024] =
"n/a"
;
+ char buf[1024] =
UNKNOWN_STR
;
fp = popen(cmd, "r");
if (fp == NULL) {
fp = popen(cmd, "r");
if (fp == NULL) {
@@
-415,9
+416,12
@@
run_command(const char *cmd)
}
fgets(buf, sizeof(buf), fp);
pclose(fp);
}
fgets(buf, sizeof(buf), fp);
pclose(fp);
-
buf[strlen(buf)] = '\0';
buf[strlen(buf)] = '\0';
+ if ((nlptr = strstr(buf, "\n")) != NULL) {
+ nlptr[0] = '\0';
+ }
+
return smprintf("%s", buf);
}
return smprintf("%s", buf);
}
@@
-439,7
+443,7
@@
swap_free(void)
buf[bytes_read] = '\0';
fclose(fp);
if (bytes_read == 0 || bytes_read == sizeof(buf)) {
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);
}
return smprintf(UNKNOWN_STR);
}
@@
-473,7
+477,7
@@
swap_perc(void)
buf[bytes_read] = '\0';
fclose(fp);
if (bytes_read == 0 || bytes_read == sizeof(buf)) {
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);
}
return smprintf(UNKNOWN_STR);
}
@@
-510,7
+514,7
@@
swap_total(void)
buf[bytes_read] = '\0';
fclose(fp);
if (bytes_read == 0 || bytes_read == sizeof(buf)) {
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);
}
return smprintf(UNKNOWN_STR);
}
@@
-541,7
+545,7
@@
swap_used(void)
buf[bytes_read] = '\0';
fclose(fp);
if (bytes_read == 0 || bytes_read == sizeof(buf)) {
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);
}
return smprintf(UNKNOWN_STR);
}